def compute_leaderboard(n, spectrum, table):
    leaderboard = ['']
    leader_peptide = ''
    leader_score = score(leader_peptide, spectrum, table)
    parent_mass = spectrum[-1]
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(lambda x: new_leaderboard.extend([peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if score(peptide, spectrum, table) > leader_score:
                    leader_peptide = peptide
                    leader_score = score(peptide, spectrum, table)
            elif weight(peptide, table) > parent_mass:
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

        def trim(leaderboard, spectrum, N):
            temp = []
            for peptide in leaderboard:
                temp.append((peptide, score(peptide, spectrum, table)))
            temp.sort(key=lambda x: x[1])
            return [x[0] for x in temp[-N:]]

        leaderboard = trim(leaderboard, spectrum, n)
    return leader_peptide
Пример #2
0
def compute_leaderboard(n, spectrum, table):
    leaderboard = ['']
    leader_peptide = ''
    leader_score = score(leader_peptide, spectrum, table)
    parent_mass = spectrum[-1]
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(
            lambda x: new_leaderboard.extend(
                [peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if score(peptide, spectrum, table) > leader_score:
                    leader_peptide = peptide
                    leader_score = score(peptide, spectrum, table)
            elif weight(peptide, table) > parent_mass:
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

        def trim(leaderboard, spectrum, N):
            temp = []
            for peptide in leaderboard:
                temp.append((peptide, score(peptide, spectrum, table)))
            temp.sort(key=lambda x: x[1])
            return [x[0] for x in temp[-N:]]

        leaderboard = trim(leaderboard, spectrum, n)
    return leader_peptide
def compute_leaderboard(n, spectrum, table):
    leaderboard = ['']
    leader_peptides = ['']
    leader_score = score(leader_peptides[0], spectrum, table)
    parent_mass = spectrum[-1]
    peptides_83 = []
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(
            lambda x: new_leaderboard.extend(
                [peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if score(peptide, spectrum, table) == 83:
                    peptides_83.append(peptide)
                if score(peptide, spectrum, table) > leader_score:
                    leader_peptides = [peptide]
                    leader_score = score(peptide, spectrum, table)
                elif score(peptide, spectrum, table) == leader_score:
                    leader_peptides.append(peptide)
            elif weight(peptide, table) > parent_mass:
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

        def trim(leaderboard, spectrum, N):
            if (len(leaderboard) < N):
                return leaderboard
            temp = []
            for peptide in leaderboard:
                temp.append((peptide, score(peptide, spectrum, table)))
            temp.sort(key=lambda x: x[1], reverse=True)
            edge_score = temp[N - 1][1]
            assert temp[0][1] >= temp[-1][1]
            result = [x[0] for x in temp if x[1] >= edge_score]
            print 'Trimmed length %s against given N=%s' % (len(result), N)
            return result

        leaderboard = trim(leaderboard, spectrum, n)
    print leader_score
    return leader_peptides
def compute_leaderboard(n, spectrum, table):
    leaderboard = ['']
    leader_peptides = ['']
    leader_score = score(leader_peptides[0], spectrum, table)
    parent_mass = spectrum[-1]
    peptides_83 = []
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(lambda x: new_leaderboard.extend([peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if score(peptide, spectrum, table) == 83:
                    peptides_83.append(peptide)
                if score(peptide, spectrum, table) > leader_score:
                    leader_peptides = [peptide]
                    leader_score = score(peptide, spectrum, table)
                elif score(peptide, spectrum, table) == leader_score:
                    leader_peptides.append(peptide)
            elif weight(peptide, table) > parent_mass:
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

        def trim(leaderboard, spectrum, N):
            if (len(leaderboard) < N):
                return leaderboard
            temp = []
            for peptide in leaderboard:
                temp.append((peptide, score(peptide, spectrum, table)))
            temp.sort(key=lambda x: x[1], reverse=True)
            edge_score = temp[N - 1][1]
            assert temp[0][1] >= temp[-1][1]
            result = [x[0] for x in temp if x[1] >= edge_score]
            print 'Trimmed length %s against given N=%s' % (len(result), N)
            return result

        leaderboard = trim(leaderboard, spectrum, n)
    print leader_score
    return leader_peptides
def cyclo_sequence(spectrum, table):
    leaderboard = ['']
    leader_peptides = ['']
    parent_mass = spectrum[-1]
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(lambda x: new_leaderboard.extend([peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if generate_cyclo_spectrum(peptide, table) == spectrum:
                    leader_peptides.append(peptide)
                stuff_to_remove.append(peptide)
            elif not is_spectrum_consistent(generate_linear_spectrum(peptide, table), perfect_spectrum):
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

    return leader_peptides