Skip to content

Commit

Permalink
Merge pull request #19 from unipept/fix/equate_il_aa_replacement
Browse files Browse the repository at this point in the history
Keep track of original I's when equating I and L
  • Loading branch information
pverscha authored Jun 13, 2023
2 parents 56ebe48 + 997867f commit 341f974
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 21 additions & 3 deletions app/controllers/mpa_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ def pept2data
peptides = params[:peptides] || []
missed = params[:missed] || false
@equate_il = params[:equate_il].nil? ? true : params[:equate_il]

# If equate_il is set, we have to replace all I's by and L in the input peptides.
equalized_pepts = peptides.map { |p| p.gsub('I', 'L') } if @equate_il

@peptides = Sequence
.includes(Sequence.lca_t_relation_name(@equate_il) => :lineage)
.where(sequence: peptides)
.where(sequence: equalized_pepts)
.where.not(Sequence.lca_t_relation_name(@equate_il) => nil)
if missed
@peptides += peptides
Expand All @@ -18,9 +22,23 @@ def pept2data
.compact
end

@results_fa = {}
eq_seq_to_fa = {}
eq_seq_to_info = {}

@peptides.each do |sequence|
@results_fa[sequence.sequence] = sequence.calculate_fa(@equate_il)
eq_seq_to_fa[sequence.sequence] = sequence.calculate_fa(@equate_il)
eq_seq_to_info[sequence.sequence] = sequence
end

@original_pep_results = {}
@original_pep_fas = {}

peptides.each do |original_seq|
equalized_seq = original_seq.gsub('I', 'L')
if eq_seq_to_info.key? equalized_seq
@original_pep_results[original_seq] = eq_seq_to_info[equalized_seq]
@original_pep_fas[original_seq] = eq_seq_to_fa[equalized_seq]
end
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/views/mpa/pept2data.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
json.peptides @peptides do |peptide|
json.sequence peptide.sequence
json.peptides @original_pep_results do |orig_seq, peptide|
json.sequence orig_seq
json.lca @equate_il ? peptide.lca_il : peptide.lca
l = peptide.send(Sequence.lca_t_relation_name(@equate_il)).lineage
json.lineage(Lineage.ranks.map { |rank| l.send(rank) })
json.fa do
json.counts @results_fa[peptide.sequence]['num']
json.data @results_fa[peptide.sequence]['data']
json.counts @original_pep_fas[orig_seq]['num']
json.data @original_pep_fas[orig_seq]['data']
end
end

0 comments on commit 341f974

Please sign in to comment.