diff --git a/app/controllers/mpa_controller.rb b/app/controllers/mpa_controller.rb index 494b99e..a08921d 100644 --- a/app/controllers/mpa_controller.rb +++ b/app/controllers/mpa_controller.rb @@ -8,38 +8,32 @@ def pept2data 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 = @equate_il ? peptides.map { |p| p.gsub('I', 'L') } : peptides - - @peptides = Sequence - .includes(Sequence.lca_t_relation_name(@equate_il) => :lineage) - .where(sequence: equalized_pepts) - .where.not(Sequence.lca_t_relation_name(@equate_il) => nil) - if missed - @peptides += equalized_pepts - .to_set.subtract(@peptides.map(&:sequence)) - .map { |p| Sequence.missed_cleavage(p, @equate_il) } - .compact + File.open("/mnt/data/suffix-array/unipept_query.txt", "w+") do |f| + peptides.each { |element| f.puts(element) } end - eq_seq_to_fa = {} - eq_seq_to_info = {} + command = IO.popen("/mnt/data/Thesis_rust_implementations/target/release/suffixarray -d /mnt/data/suffix-array/protein_database.tsv -t /mnt/data/suffix-array/taxons.tsv -s /mnt/data/suffix-array/unipept_query.txt -m taxon-id > /mnt/data/suffix-array/unipept_result.txt --load-index /mnt/data/suffix-array/uniprot_indexed_sparse3_sa.bin") + Process.wait(command.pid) - @peptides.each do |sequence| - eq_seq_to_fa[sequence.sequence] = sequence.calculate_fa(@equate_il) - eq_seq_to_info[sequence.sequence] = sequence + processed_peptides = File.readlines('/mnt/data/suffix-array/unipept_result.txt') + + @response = Hash.new + processed_peptides.each do |line| + splitted = line.split(";") + # Skip taxa that are not found + unless splitted[1] == "/" + @response[splitted[0]] = splitted[1] + end end - @original_pep_results = {} - @original_pep_fas = {} + taxa = Taxon.where(id => @response.values).includes(:lineage) - peptides.each do |original_seq| - equalized_seq = @equate_il ? original_seq.gsub('I', 'L') : original_seq - 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 + @lineages = Hash.new + taxa.each do |taxon| + @lineages[taxon.id] = taxon.lineage end + + @response end def pept2filtered diff --git a/app/views/mpa/pept2data.json.jbuilder b/app/views/mpa/pept2data.json.jbuilder index 3855eb9..164c4ec 100644 --- a/app/views/mpa/pept2data.json.jbuilder +++ b/app/views/mpa/pept2data.json.jbuilder @@ -1,10 +1,9 @@ -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.peptides @response do |peptide, lca| + json.sequence peptide + json.lca lca + json.lineage(@lineages[lca]) json.fa do - json.counts @original_pep_fas[orig_seq]['num'] - json.data @original_pep_fas[orig_seq]['data'] + json.counts {} + json.data {} end end