static/js/select.js
/**
 * Summarize a field of multiple contigs.
 * @function summFieldInfo
 * @param {Array} arr - data array to describe
 * @param {string} type - field type
 * @param {string} [metric='mean'] - metric for numeric field (sum or mean)
 * @param {string} [deci=3] - digits after decimal point
 * @param {string} [rarr] - reference data array
 * @param {string} [warr] - weight data array
 * @returns {[string, string]} descriptive text and comment
 * @todo The weights are currently not in use.
 */
Summarize a field of multiple contigs.
Summarize a field of multiple contigs .
function summFieldInfo(arr, type, metric, deci, rarr, warr) {
  metric = metric || 'mean';
  deci = deci || 3;
  const noref = rarr === undefined;
  const nowei = warr === undefined;
  const issum = metric === 'sum';
  let text = '', comment = '';
  switch (type) {
    case 'num':
      let val, n, _;
      if (noref) {
        if (issum) [val, n] = arrSumN(arr);
        else [val, n] = arrMeanN(arr);
      } else {
        if (issum) [val, _, n] = arrProdSumN(arr, rarr);
        else [val, _, n] = arrProdMeanN(arr, rarr);
      }
      text = val.toFixed(deci).replace(/\.?0+$/, '');
      comment = `${noref ? '' : 'weighted '}${metric} of ${n} values`;
      break;
    case 'cat':
      let top;  
      let freq; 
      let frac; 
      if (noref) {
        [top, freq] = objMax(listCats(arr));
        frac = freq / arr.length;
      } else {
        const [freqs, rsum] = listCatsW(arr, rarr);
        [top, freq] = objMax(freqs);
        frac = freq / rsum;
      }
      if (frac === 1) {
        text = top;
        comment = `uniform category`;
      } else {
        const perc = (frac * 100).toFixed(2).replace(/\.?0+$/, '');
        if (frac > 0.5) {
          text = `${top} (${perc}%)`;
          comment = `${noref ? '' : 'weighted '}majority category`;
        }
        else {
          text = 'ambiguous';
          comment = `no category is ${noref ? '' : 'weighted '}majority; ` +
            `most frequent: ${top} (${perc}%)`;
        }
      }
      break;
    case 'fea':
      text = summFeatures(arr);
      break;
  }
  return [text, capital(comment)];
}
function summFieldInfo ( arr , type , metric , deci , rarr , warr ) { metric = metric || 'mean' ; deci = deci || 3 ; const noref = rarr === undefined ; const nowei = warr === undefined ; const issum = metric === 'sum' ; let text = '' , comment = '' ; switch ( type ) { case 'num' : let val , n , _ ; if ( noref ) { if ( issum ) [ val , n ] = arrSumN ( arr ) ; else [ val , n ] = arrMeanN ( arr ) ; } else { if ( issum ) [ val , _ , n ] = arrProdSumN ( arr , rarr ) ; else [ val , _ , n ] = arrProdMeanN ( arr , rarr ) ; } text = val . toFixed ( deci ) . replace ( / \.?0+$ / , '' ) ; comment = ` ${ noref ? '' : 'weighted ' } ${ metric } ${ n } ` ; break ; case 'cat' : let top ; let freq ; let frac ; if ( noref ) { [ top , freq ] = objMax ( listCats ( arr ) ) ; frac = freq / arr . length ; } else { const [ freqs , rsum ] = listCatsW ( arr , rarr ) ; [ top , freq ] = objMax ( freqs ) ; frac = freq / rsum ; } if ( frac === 1 ) { text = top ; comment = ` ` ; } else { const perc = ( frac * 100 ) . toFixed ( 2 ) . replace ( / \.?0+$ / , '' ) ; if ( frac > 0.5 ) { text = ` ${ top } ${ perc } ` ; comment = ` ${ noref ? '' : 'weighted ' } ` ; } else { text = 'ambiguous' ; comment = ` ${ noref ? '' : 'weighted ' } ` + ` ${ top } ${ perc } ` ; } } break ; case 'fea' : text = summFeatures ( arr ) ; break ; } return [ text , capital ( comment ) ] ; }
Summarize a field of multiple contigs.
Summarize a field of multiple contigs .
// round number // most frequent category // (weighted) number of contigs in this category // (weighted) fraction of contigs in this category // convert fraction to percentage // find top category by majority rule // ambiguity - no category is majority