Skip to content

Commit

Permalink
Doco for #91
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed May 6, 2024
1 parent e52ea4d commit 2545a49
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 77 deletions.
145 changes: 76 additions & 69 deletions rosalind.wpr
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ debug.show-args-dialog = {loc('../cluster/fcs_params.py'): False,
loc('count-kmer-occurrences.py'): False,
loc('newick.py'): False,
loc('nwck.py'): False,
loc('unknown:<untitled> #1'): False}
loc('unknown:<untitled> #15'): False}
guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'windows': [{'name': 'dtaAtJloNhSft7SabFzspl0xqEmVIDbK',
'size-state': '',
Expand All @@ -770,7 +770,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
{'tree-state': {'file-sort-method': 'by name',
'list-files-first': False,
'tree-states': {'deep': {'expanded-nodes': [],
'selected-nodes': [],
'selected-nodes': [(69,)],
'top-node': (65,)}},
'tree-style': 'deep'}}),
('source-assistant',
Expand Down Expand Up @@ -1755,11 +1755,11 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'top-node': [('function def',
loc('ukkonen.py'),
'build')]},
loc('unknown:<untitled> #2'): {'expanded-nodes': [],
'selected-nodes': [],
'top-node': [('function def',
loc('unknown:<untitled> #3'),
'to_adjacency_matrix')]}},
loc('unknown:<untitled> #16'): {'expanded-nodes': [],
'selected-nodes': [],
'top-node': [('function def',
loc('unknown:<untitled> #17'),
'to_adjacency_matrix')]}},
'browse_mode': 'Current Module',
'follow-selection': False,
'sort_mode': 'Alphabetically',
Expand Down Expand Up @@ -1861,10 +1861,10 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'folded-linenos': [],
'history': {},
'launch-id': None,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0,
'sel-line': 2,
'sel-line-start': 159,
'selection_end': 159,
'selection_start': 159,
'zoom': 0}),
('messages',
'wide',
Expand All @@ -1876,52 +1876,17 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
{'last-percent': 0.8,
'toolbox-percent': 1.0,
'toolbox-tree-sel': ''})],
'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('spectrum.py'),
{'attrib-starts': [('SequencePeptide|0|',
1032)],
'code-line': " return ''.join(inverse_masses[i] for i in create_peptide(Scores,Choices,masses))\r\n",
'first-line': 1055,
'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('BA10D.py'),
{'attrib-starts': [],
'code-line': " Input,Expected = read_strings(f'data/OutcomeLikelihood.txt',init=0)\r\n",
'first-line': 40,
'folded-linenos': [],
'sel-line': 1071,
'sel-line-start': 41047,
'selection_end': 41131,
'selection_start': 41131,
'sel-line': 53,
'sel-line-start': 2163,
'selection_end': 2262,
'selection_start': 2171,
'zoom': 0},
1714968173.471065],
[loc('BA11E.py'),
{'attrib-starts': [],
'code-line': '\r\n',
'first-line': 23,
'folded-linenos': [],
'sel-line': 27,
'sel-line-start': 1080,
'selection_end': 1080,
'selection_start': 1080,
'zoom': 0},
1714968267.0628998],
[loc('spectrum.py'),
{'attrib-starts': [('SequencePeptide|0|',
1032)],
'code-line': " return ''.join(inverse_masses[i] for i in create_peptide(Scores,Choices,masses))\r\n",
'first-line': 1055,
'folded-linenos': [],
'sel-line': 1071,
'sel-line-start': 41047,
'selection_end': 41131,
'selection_start': 41131,
'zoom': 0},
1714968267.7633479],
[loc('BA10D.py'),
{'attrib-starts': [],
'code-line': " Input,Expected = read_strings(f'data/OutcomeLikelihood.txt',init=0)\r\n",
'first-line': 40,
'folded-linenos': [],
'sel-line': 53,
'sel-line-start': 2163,
'selection_end': 2262,
'selection_start': 2171,
'zoom': 0},
1714968268.531469],
1714968268.531469],
[loc('BA11E.py'),
{'attrib-starts': [],
'code-line': ' print (SequencePeptide(Spectral))\r\n',
Expand Down Expand Up @@ -2122,7 +2087,46 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'selection_end': 39700,
'selection_start': 39685,
'zoom': 0},
1715024841.7465267]],
1715024841.7465267],
[loc('BA11E.py'),
{'attrib-starts': [],
'code-line': ' print (SequencePeptide(Spectral))\r\n',
'first-line': 33,
'folded-linenos': [],
'sel-line': 42,
'sel-line-start': 1860,
'selection_end': 1890,
'selection_start': 1875,
'zoom': 0},
1715029329.0039022],
[loc('spectrum.py'),
{'attrib-starts': [('SequencePeptide|0|',
1032),
('SequencePeptide|0|.compute_scores|0|',
1040)],
'code-line': '\r\n',
'first-line': 1045,
'folded-linenos': [],
'sel-line': 1063,
'sel-line-start': 41294,
'selection_end': 41294,
'selection_start': 41294,
'zoom': 0},
1715029621.6188264],
[loc('spectrum.py'),
{'attrib-starts': [('SequencePeptide|0|',
1032),
('SequencePeptide|0|.compute_scores|0|',
1040)],
'code-line': '\r\n',
'first-line': 1326,
'folded-linenos': [],
'sel-line': 1063,
'sel-line-start': 41294,
'selection_end': 41294,
'selection_start': 41294,
'zoom': 0},
1715029773.103349]],
20),
'current-loc': None,
'editor-state-list': [],
Expand All @@ -2136,7 +2140,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'tab_location': 'top',
'traversal_pos': ((1,
0),
1715023971.700375),
1715029610.269612),
'user_data': {}},
'saved_notebook_display': None,
'split_percents': {},
Expand Down Expand Up @@ -2773,13 +2777,13 @@ guimgr.visual-state = {loc('../../../Anaconda3/lib/site-packages/Bio/File.py'):
'selection_start': 8810,
'zoom': 0},
loc('BA11E.py'): {'attrib-starts': [],
'code-line': ' Result = SequencePeptide(Spectral)\r\n',
'code-line': ' print (SequencePeptide(Spectral))\r\n',
'first-line': 33,
'folded-linenos': [],
'sel-line': 47,
'sel-line-start': 2071,
'selection_end': 2103,
'selection_start': 2088,
'sel-line': 42,
'sel-line-start': 1860,
'selection_end': 1890,
'selection_start': 1875,
'zoom': 0},
loc('BA11F.py'): {'attrib-starts': [],
'code-line': '# Copyright (C) 2020 Greenweaves Software Limited\r\n',
Expand Down Expand Up @@ -4346,14 +4350,17 @@ guimgr.visual-state = {loc('../../../Anaconda3/lib/site-packages/Bio/File.py'):
'selection_end': 23,
'selection_start': 23,
'zoom': 0},
loc('spectrum.py'): {'attrib-starts': [],
'code-line': 'def SequencePeptide(spectral, protein_masses = integer_masses):\r\n',
'first-line': 1063,
loc('spectrum.py'): {'attrib-starts': [('SequencePeptide|0|',
1032),
('SequencePeptide|0|.compute_scores|0|',
1040)],
'code-line': '\r\n',
'first-line': 1326,
'folded-linenos': [],
'sel-line': 1032,
'sel-line-start': 39681,
'selection_end': 39700,
'selection_start': 39685,
'sel-line': 1063,
'sel-line-start': 41294,
'selection_end': 41294,
'selection_start': 41294,
'zoom': 0},
loc('sptb.py'): {'attrib-starts': [],
'code-line': ' elapsed = time.time()-start\r\n',
Expand Down
22 changes: 14 additions & 8 deletions spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def extract(seq,candidates):
prefixes = extract( [min(candidates.keys())],candidates)
suffixes = extract([min([r for r in candidates.keys() if not r in prefixes])],candidates)
# Our algorithm is a bit greedy, so there may be some overlap between prefixes and suffices
# Thius must be fixed!
# This must be fixed!

while len(prefixes)>len(suffixes):
for r in suffixes:
Expand Down Expand Up @@ -1048,31 +1048,37 @@ def compute_scores(Spectrum,masses):
Scores Best score for each node
Choices The amino acids that have been chosen to maximize Scores
'''
Scores = np.full_like(Spectrum,-np.inf,dtype=np.float64)
Scores = np.full_like(Spectrum,-np.inf,dtype=np.float64) # Set all scores to - infinity,
# Later we want best scores, so
# defualt values will be ignored
n = len(Scores)
Scores[0] = 0
Choices = np.full_like(Spectrum,-1)
for i in range(1,n):
CandidatePredecessors = [i-k for k in masses if i>=k] # All ways to get here with one amino acid
CandidateScores = [Scores[j] for j in CandidatePredecessors] # Scores of all possible predecessors
if len(CandidatePredecessors)>0:
if len(CandidatePredecessors) > 0: # Choose the highest scoring predecessor
best_candidate = np.argmax(CandidateScores)
Scores[i] = Spectrum[i] + CandidateScores[best_candidate]
Choices[i] = best_candidate

return Scores,Choices

def create_peptide(Scores,Choices,masses):
'''
Construct the peptide by backtracking through the choices
Construct the peptide by backtracking through the DAG
and adding the amino acid that was chosen to the peptide.
'''
imax = np.argmax(Scores)
max_score = Scores[imax]
n = len(Scores) - 1
peptide = []
peptide = [] # We will construct peptide in reverse order
# so will need to reverse later
while n > 0:
i = Choices[n]
peptide.append(masses[i])
n -= masses[i]
i = Choices[n] # This is the peptide that was chosen
peptide.append(masses[i]) # accumulate it in peptide
n -= masses[i] # since mass was used to dicide how much to step forward
# in compute_scores(), we step back by same amount
return peptide[::-1]

inverse_masses = invert(protein_masses)
Expand Down

0 comments on commit 2545a49

Please sign in to comment.