AMINO_DICT = {'A': 71, 'C': 103, 'E': 129, 'D': 115, 'G': 57, 'F': 147, 'I': 113, 'H': 137, 'K': 128, 'M': 131, 'L': 113, 'N': 114, 'Q': 128, 'P': 97, 'S': 87, 'R': 156, 'T': 101, 'W': 186, 'V': 99, 'Y': 163, 'X': 4, 'Z': 5} def peptide_identification(spec_vec, proteome): ''' Given: A space-delimited spectral vector Spectrum' and an amino acid string Proteome. Return: A substring of Proteome with maximum score against Spectrum'. ''' result = {'score': - sys.maxint, 'sub_str': ""} for str_index in range(len(proteome)): new_score = 0 new_sub_str = proteome[str_index] vec_index = AMINO_DICT[proteome[str_index]] while vec_index < len(spec_vec) and str_index < len(proteome): new_score += spec_vec[vec_index] if vec_index == len(spec_vec) - 1: if new_score > result["score"]: result["score"] = new_score result["sub_str"] = new_sub_str str_index += 1 if str_index < len(proteome): new_sub_str += proteome[str_index] vec_index += AMINO_DICT[proteome[str_index]] return result ################################################################################################ #spec_vec = [0, 0, 0, 0, 4, -2, -3, -1, -7, 6, 5, 3, 2, 1, 9, 3, -8, 0, 3, 1, 2, 1, 8] #proteome = "XZZXZXXXZXZZXZXXZ" # #print peptide_identification(spec_vec, proteome) ################################################################################################ spec_vectors = [[0, -1, 5, -4, 5, 3, -1, -4, 5, -1, 0, 0, 4, -1, 0, 1, 4, 4, 4], [-4, 2, -2, -4, 4, -5, -1, 4, -1, 2, 5, -3, -1, 3, 2, -3]] proteome = "XXXZXZXXZXZXXXZXXZX" threshold = 5 def psm_search(spec_vectors, proteome, threshold): ''' Given: A set of space-delimited spectral vectors SpectralVectors, an amino acid string Proteome, and an integer threshold. Return: The set PSMthreshold(Proteome, SpectralVectors) of Peptide- Spectrum Matches. PSMSet ← an empty set for each vector Spectrum' in SpectralVectors Peptide ← PeptideIdentification(Spectrum', Proteome) if Score(Peptide, Spectrum) ≥ threshold add the PSM (Peptide, Spectrum') to PSMSet return PSMSet ''' pms_set = set() for spec_vec in spec_vectors: peptide = peptide_identification(spec_vec, proteome) if peptide["score"] >= threshold: pms_set.add(peptide["sub_str"]) return pms_set print psm_search(spec_vectors, proteome, threshold)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question