Skip to content

Commit

Permalink
Fix bug in how we determine problematic peptides after running path-f…
Browse files Browse the repository at this point in the history
…inding algorithm
  • Loading branch information
susannasiebert committed Aug 14, 2020
1 parent b4a4af4 commit 64d707b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/pvacvector/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,31 @@ def find_optimal_path(Paths, distance_matrix, seq_dict, seq_keys, base_output_di
results_file = os.path.join(base_output_dir, args.sample_name + '_results.fa')
with open(results_file, 'w') as f:
name = list()
if Paths.has_edge(state[0], state[1]):
min_score = Paths[state[0]][state[1]]['weight']
else:
return (None, "No valid junction between peptides {} and {}".format(state[0], state[1]))
problematic_ends = []
problematic_starts = []
problematic_junctions = []
cumulative_weight = 0
all_scores = list()

for i in range(0, (len(state) - 1)):
name.append(state[i])
if Paths.has_edge(state[i], state[i + 1]):
edge = Paths[state[i]][state[i + 1]]
min_score = min(min_score, edge['weight'])
try:
min_score = min(min_score, edge['weight'])
except:
min_score = edge['weight']
cumulative_weight += edge['weight']
all_scores.append(str(edge['weight']))
spacer = edge['spacer']
if spacer != 'None':
name.append(spacer)
else:
return (None, "No valid junction between peptides {} and {}".format(state[i], state[i+1]))
problematic_ends.append(state[i])
problematic_starts.append(state[i+1])
problematic_junctions.append("{} - {}".format(state[i], state[i+1]))
if len(problematic_junctions) > 0:
return (None, "No valid junction between peptides: {}".format(", ".join(problematic_junctions)), problematic_starts, problematic_ends)
name.append(state[-1])
median_score = str(cumulative_weight/len(all_scores))
peptide_id_list = ','.join(name)
Expand All @@ -336,7 +342,7 @@ def find_optimal_path(Paths, distance_matrix, seq_dict, seq_keys, base_output_di
output.append(id)
output.append("\n")
f.write(''.join(output))
return (results_file, None)
return (results_file, None, None, None)

def shorten_problematic_peptides(input_file, problematic_start, problematic_end, output_dir):
print("Shortening problematic peptides")
Expand Down Expand Up @@ -434,11 +440,10 @@ def main(args_input=sys.argv[1:]):
print("No valid path found. {}".format(error))
continue
distance_matrix = create_distance_matrix(Paths)
(results_file, error) = find_optimal_path(Paths, distance_matrix, seq_dict, seq_keys, base_output_dir, args)
(results_file, error, problematic_start, problematic_end) = find_optimal_path(Paths, distance_matrix, seq_dict, seq_keys, base_output_dir, args)
if results_file is not None:
break
else:
(problematic_start, problematic_end) = identify_problematic_peptides(Paths, seq_dict)
print("No valid path found. {}".format(error))
tries += 1

Expand Down

0 comments on commit 64d707b

Please sign in to comment.