static/js/control.js
/**
 * Select contigs by criteria.
 * @function selectByCriteria
 * @param {Object} mo - master object
 * @returns {boolean} whether selection is successful
 */
Select contigs by criteria.
@function selectByCriteria
@param {Object} mo - master object
@returns {boolean} whether selection is successful
Select contigs by criteria . @function selectByCriteria @param { Object } mo - master object @returns { boolean } whether selection is successful
function selectByCriteria(mo) {
  var data = mo.data;
  var mask = mo.mask;
  var f = document.getElementById('field-list').value;
  if (f === '') {
    toastMsg('No search criterium was specified.', mo.stat);
    return false;
  }
  f = parseInt(f);
  var type = data.types[f];
  var indices = [];
  var hasMask = (Object.keys(mask).length > 0);
  if (type === 'number') {
    var min = document.getElementById('min-txt').value;
    var max = document.getElementById('max-txt').value;
    if (min === '' && max === '') {
      toastMsg('Must specify minimum and/or maximum thresholds.', mo.stat);
      return false;
    }
    if (min === '') min = null;
    else if (isNaN(min)) {
      toastMsg('Invalid minimum threshold was specified.', mo.stat);
      return false;
    } else min = Number(min);
    if (max === '') max = null;
    else if (isNaN(max)) {
      toastMsg('Invalid maximum threshold was specified.', mo.stat);
      return false;
    } else max = Number(max);
    var minIn = (document.getElementById('min-btn').innerHTML === '[');
    var maxIn = (document.getElementById('max-btn').innerHTML === '[');
    for (var i = 0; i < data.df.length; i++) {
      if (hasMask && i in mask) continue;
      var val = data.df[i][f];
      if ((val !== null) &&
        (min === null || (minIn ? (val >= min) : (val > min))) &&
        (max === null || (maxIn ? (val <= max) : (val < max)))) {
          indices.push(i);
      }
    }
  }
  else {
    var text = document.getElementById(type.substr(0, 3) + '-sel-txt')
      .value;
    if (text === '') {
      toastMsg('Must specify a keyword.', mo.stat);
      return false;
    }
    var mcase = document.getElementById('case-btn').classList
      .contains('pressed');
    if (!mcase) text = text.toUpperCase();
    var mwhole = document.getElementById('whole-btn').classList
      .contains('pressed');
    for (var i = 0; i < data.df.length; i++) {
      if (hasMask && i in mask) continue;
      var val = data.df[i][f];
      if (val === null) continue;
      if (type !== 'feature') {
        if (type === 'category') val = val[0];
        if (!mcase) val = val.toUpperCase();
        if (mwhole ? (val === text) : (val.indexOf(text) > -1))
          indices.push(i);
      }
      else {
        for (var key in val) {
          if (mwhole ? (key === text) : (key.indexOf(text) > -1)) {
            indices.push(i);
            break;
          }
        }
      }
    }
  }
  treatSelection(indices, mo.stat.selmode, mo.stat.masking, mo);
  return true;
}
function selectByCriteria ( mo ) { var data = mo . data ; var mask = mo . mask ; var f = document . getElementById ( 'field-list' ) . value ; if ( f === '' ) { toastMsg ( 'No search criterium was specified.' , mo . stat ) ; return false ; } f = parseInt ( f ) ; var type = data . types [ f ] ; var indices = [ ] ; var hasMask = ( Object . keys ( mask ) . length > 0 ) ; if ( type === 'number' ) { var min = document . getElementById ( 'min-txt' ) . value ; var max = document . getElementById ( 'max-txt' ) . value ; if ( min === '' && max === '' ) { toastMsg ( 'Must specify minimum and/or maximum thresholds.' , mo . stat ) ; return false ; } if ( min === '' ) min = null ; else if ( isNaN ( min ) ) { toastMsg ( 'Invalid minimum threshold was specified.' , mo . stat ) ; return false ; } else min = Number ( min ) ; if ( max === '' ) max = null ; else if ( isNaN ( max ) ) { toastMsg ( 'Invalid maximum threshold was specified.' , mo . stat ) ; return false ; } else max = Number ( max ) ; var minIn = ( document . getElementById ( 'min-btn' ) . innerHTML === '[' ) ; var maxIn = ( document . getElementById ( 'max-btn' ) . innerHTML === '[' ) ; for ( var i = 0 ; i < data . df . length ; i ++ ) { if ( hasMask && i in mask ) continue ; var val = data . df [ i ] [ f ] ; if ( ( val !== null ) && ( min === null || ( minIn ? ( val >= min ) : ( val > min ) ) ) && ( max === null || ( maxIn ? ( val <= max ) : ( val < max ) ) ) ) { indices . push ( i ) ; } } } else { var text = document . getElementById ( type . substr ( 0 , 3 ) + '-sel-txt' ) . value ; if ( text === '' ) { toastMsg ( 'Must specify a keyword.' , mo . stat ) ; return false ; } var mcase = document . getElementById ( 'case-btn' ) . classList . contains ( 'pressed' ) ; if ( ! mcase ) text = text . toUpperCase ( ) ; var mwhole = document . getElementById ( 'whole-btn' ) . classList . contains ( 'pressed' ) ; for ( var i = 0 ; i < data . df . length ; i ++ ) { if ( hasMask && i in mask ) continue ; var val = data . df [ i ] [ f ] ; if ( val === null ) continue ; if ( type !== 'feature' ) { if ( type === 'category' ) val = val [ 0 ] ; if ( ! mcase ) val = val . toUpperCase ( ) ; if ( mwhole ? ( val === text ) : ( val . indexOf ( text ) > - 1 ) ) indices . push ( i ) ; } else { for ( var key in val ) { if ( mwhole ? ( key === text ) : ( key . indexOf ( text ) > - 1 ) ) { indices . push ( i ) ; break ; } } } } } treatSelection ( indices , mo . stat . selmode , mo . stat . masking , mo ) ; return true ; }
Select contigs by criteria.
Select contigs by criteria .
// filter contigs by currently specified criteria // search by threshold // validate minimum and maximum thresholds // whether to include lower and upper bounds // compare values to threshold(s) // search by keyword // category or description // feature