Generic function for sorting peptides and psms. Assumes a higher
    number is better for what is passed at sort_index position in protein.
779645
def sort_amounts(proteins, sort_index):
    """"""
    amounts = {}
    for protein in proteins:
        amount_x_for_protein = protein[sort_index]
        try:
            amounts[amount_x_for_protein].append(protein)
        except KeyError:
            amounts[amount_x_for_protein] = [protein]
    return [v for k, v in sorted(amounts.items(), reverse=True)]
1329079
def filter_unique_peptides(peptides, score, ns):
    
    scores = {'q': 'q_value',
              'pep': 'pep',
              'p': 'p_value',
              'svm': 'svm_score'}
    highest = {}
    for el in peptides:
        featscore = float(el.xpath('xmlns:%s' % scores[score],
                                   namespaces=ns)[0].text)
        seq = reader.get_peptide_seq(el, ns)

        if seq not in highest:
            highest[seq] = {
                'pep_el': formatting.stringify_strip_namespace_declaration(
                    el, ns), 'score': featscore}
        if score == 'svm':  # greater than score is accepted
            if featscore > highest[seq]['score']:
                highest[seq] = {
                    'pep_el':
                    formatting.stringify_strip_namespace_declaration(el, ns),
                    'score': featscore}
        else:  # lower than score is accepted
            if featscore < highest[seq]['score']:
                highest[seq] = {
                    'pep_el':
                    formatting.stringify_strip_namespace_declaration(el, ns),
                    'score': featscore}
        formatting.clear_el(el)

    for pep in list(highest.values()):
        yield pep['pep_el']
1374085
def sort_protein_groups(pgroups, evidence):
    """"""
    sortfnxs = get_sortfnxs(evidence)
    pgroups_out = {}
    for master, pgroup in pgroups.items():
        sorted_pg = sort_protein_group(pgroup, sortfnxs, 0)
        pgroups_out[master] = sorted_pg
    return pgroups_out
624562
def sortby(listoflists,sortcols):
    
    newlist = abut(colex(listoflists,sortcols),listoflists)
    newlist.sort()
    try:
        numcols = len(sortcols)
    except TypeError:
        numcols = 1
    crit = '[' + str(numcols) + ':]'
    newlist = colex(newlist,crit)
    return newlist
628855
function getLegendEntries(series, labelFormatter, sorted) {
        var lf = labelFormatter,
            legendEntries = series.map(function(s, i) {
                return {
                    label: (lf ? lf(s.label, s) : s.label) || 'Plot ' + (i + 1),
                    color: s.color,
                    options: {
                        lines: s.lines,
                        points: s.points,
                        bars: s.bars
                    }
                };
            });

        // Sort the legend using either the default or a custom comparator
        if (sorted) {
            if ($.isFunction(sorted)) {
                legendEntries.sort(sorted);
            } else if (sorted === 'reverse') {
                legendEntries.reverse();
            } else {
                var ascending = (sorted !== 'descending');
                legendEntries.sort(function(a, b) {
                    return a.label === b.label
                        ? 0
                        : ((a.label < b.label) !== ascending ? 1 : -1 // Logical XOR
                        );
                });
            }
        }

        return legendEntries;
    }
901570
def _sorter(n1,n2):
    ''''''

    i = cmp(n1.namespaceURI, n2.namespaceURI)
    if i: return i
    return cmp(n1.localName, n2.localName)
580754
function massageSort(sort) {
  if (!Array.isArray(sort)) {
    throw new Error('invalid sort json - should be an array');
  }
  return sort.map(function (sorting) {
    if (typeof sorting === 'string') {
      var obj = {};
      obj[sorting] = 'asc';
      return obj;
    } else {
      return sorting;
    }
  });
}
770085
def merge_peptides(fns, ns):
    """"""
    peptides_to_map = reader.generate_peptides_multiple_fractions(fns, ns)
    psmmap = create_merge_psm_map(peptides_to_map, ns)
    peptides = reader.generate_peptides_multiple_fractions(fns, ns)
    for peptide in peptides:
        seq = reader.get_peptide_seq(peptide, ns)
        psm_ids = reader.get_psm_ids_from_peptide(peptide, ns)
        # remove current psm ids, repopulate with stored ones
        psm_ids.clear()
        for new_psm_id in psmmap[seq]:
            etree.SubElement(psm_ids, 'psm_id').text = new_psm_id
        yield formatting.string_and_clear(peptide, ns)
1295367
def findOrDie(s):
    
    aa = find(s)
    if aa:
        return aa
    else:
        print('Unknown amino acid or codon: %s' % s, file=sys.stderr)
        print('Valid arguments are: %s.' % list(CODONS.keys()),
              file=sys.stderr)
        sys.exit(1)
123484
public static void sort(int n, int[] Xip, int Xip_offset, int[] Xlen, int Xlen_offset,
			double[] LU, int[] Tp, int[] Tj, double[] Tx, int[] W)
	{
		/*int[]*/double[] Xi ;
		double[] Xx ;
		int p, i, j, nz, tp, xlen, pend ;
		int[] len = new int[1] ;
		int[] Xi_offset = new int[1] ;
		int[] Xx_offset = new int[1] ;

		ASSERT (klu_valid_LU (n, FALSE, Xip, Xip_offset, Xlen, Xlen_offset, LU)) ;

		/* count the number of entries in each row of L or U */
		for (i = 0 ; i < n ; i++)
		{
			W [i] = 0 ;
		}
		for (j = 0 ; j < n ; j++)
		{
			Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
			for (p = 0 ; p < len[0] ; p++)
			{
				W [(int) Xi [Xi_offset[0] + p]]++ ;
			}
		}

		/* construct the row pointers for T */
		nz = 0 ;
		for (i = 0 ; i < n ; i++)
		{
			Tp [i] = nz ;
			nz += W [i] ;
		}
		Tp [n] = nz ;
		for (i = 0 ; i < n ; i++)
		{
			W [i] = Tp [i] ;
		}

		/* transpose the matrix into Tp, Ti, Tx */
		for (j = 0 ; j < n ; j++)
		{
			Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
			for (p = 0 ; p < len[0] ; p++)
			{
				tp = W [(int) Xi [Xi_offset[0] + p]]++ ;
				Tj [tp] = j ;
				Tx [tp] = Xx [Xx_offset[0] + p] ;
			}
		}

		/* transpose the matrix back into Xip, Xlen, Xi, Xx */
		for (j = 0 ; j < n ; j++)
		{
			W [j] = 0 ;
		}
		for (i = 0 ; i < n ; i++)
		{
			pend = Tp [i+1] ;
			for (p = Tp [i] ; p < pend ; p++)
			{
				j = Tj [p] ;
				Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
				xlen = W [j]++ ;
				Xi [Xi_offset[0] + xlen] = i ;
				Xx [Xx_offset[0] + xlen] = Tx [p] ;
			}
		}

		ASSERT (klu_valid_LU (n, FALSE, Xip, Xip_offset, Xlen, Xlen_offset, LU)) ;
	}
58685
def get_proteins_for_peptide(self, psm_id):
        """"""
        protsql = self.get_sql_select(['protein_acc'], 'protein_psm')
        protsql = '{0} WHERE psm_id=?'.format(protsql)
        cursor = self.get_cursor()
        proteins = cursor.execute(protsql, psm_id).fetchall()
        return [x[0] for x in proteins]
759627
def get_proteins_from_psm(line):
    """"""
    proteins = line[mzidtsvdata.HEADER_PROTEIN].split(';')
    outproteins = []
    for protein in proteins:
        prepost_protein = re.sub('\(pre=.*post=.*\)', '', protein).strip()
        outproteins.append(prepost_protein)
    return outproteins
877028
def sort_segment_points(Aps, Bps):
    
    mid = []
    j = 0
    mid.append(Aps[0])
    for i in range(len(Aps)-1):
        dist = distance_tt_point(Aps[i], Aps[i+1])
        for m in range(j, len(Bps)):
            distm = distance_tt_point(Aps[i], Bps[m])
            if dist > distm:
                direction = dot(normalize(line(Aps[i].gen2arr(), Aps[i+1].gen2arr())), normalize(Bps[m].gen2arr()))
                if direction > 0:
                    j = m + 1
                    mid.append(Bps[m])
                    break

        mid.append(Aps[i+1])
    for m in range(j, len(Bps)):
        mid.append(Bps[m])
    return mid
227997
def as_sorted_list(options):
        
        if len(options) > 0:
            options = sorted(options, key=lambda o: o.number)
        return options
664633
def get_unique_gene_psms(self, genetable, fields, firstjoin):
        """"""
        lastgene = None
        gpsms_out, gp_ids = [], []
        for gpsm in self.get_proteins_psms(genetable, fields, firstjoin):
            if gpsm[0] != lastgene:
                for outpsm in gpsms_out:
                    yield outpsm
                lastgene = gpsm[0]
                gpsms_out, gp_ids = [], []
            gp_id = gpsm[0] + gpsm[1] + gpsm[3]
            if gp_id not in gp_ids:
                gp_ids.append(gp_id)
                gpsms_out.append(gpsm)
        for outpsm in gpsms_out:
            yield outpsm
95667
function argSort(vectors, ascending) {
  if (vectors.length !== ascending.length) {
    throw new Error('length of "ascending" must match the number of ' +
      'sort columns');
  }
  if (vectors.length === 0) {
    return null;
  }
  var nRow = vectors[0].size();
  var result = allocArray(nRow);
  for (var i = 0; i < nRow; i++) {
    result[i] = i;
  }

  // Create composite compare function
  var compareFuncs = ascending.map(function(asc) {
    return asc ? compare : compareReverse;
  });
  var compositeCompare = function(a, b) {
    var result = 0;
    for (var i = 0; i < compareFuncs.length; i++) {
      var aValue = vectors[i].values[a];
      var bValue = vectors[i].values[b];
      result = compareFuncs[i](aValue, bValue);
      if (result !== 0) {
        return result;
      }
    }
    // Order based on row index as last resort to ensure stable sorting
    return compare(a, b);
  };

  result.sort(compositeCompare);
  return result;
}
137665
def sortBy(self, *args):
        ''''''
        criteria = ['seeds', 'size']
        for k in args:
            if k in criteria:
                self.results = sorted(
                    self.results, key=attrgetter(k), reverse=True)
        return self