Skip to content
Snippets Groups Projects
Commit ce090c6b authored by Hottlet Valentin's avatar Hottlet Valentin
Browse files

Add alignment generation functionality and integrate with pipeline

parent ef9df26e
No related branches found
No related tags found
1 merge request!8Tests docker
...@@ -86,6 +86,7 @@ COPY ./pampa /var/www/cgi-bin/pampa/pampa ...@@ -86,6 +86,7 @@ COPY ./pampa /var/www/cgi-bin/pampa/pampa
RUN cp /var/www/cgi-bin/pampa/pampa/config.json /var/www/html/pampa/data_pampa/config.json RUN cp /var/www/cgi-bin/pampa/pampa/config.json /var/www/html/pampa/data_pampa/config.json
COPY ./main_taxonomy_filtering.py /var/www/cgi-bin/pampa/pampa/ COPY ./main_taxonomy_filtering.py /var/www/cgi-bin/pampa/pampa/
COPY ./table_maker.py /var/www/cgi-bin/pampa/pampa COPY ./table_maker.py /var/www/cgi-bin/pampa/pampa
COPY ./alignment_maker.py /var/www/cgi-bin/pampa/pampa
# Ajustage des droits # Ajustage des droits
RUN chmod +x /var/www/cgi-bin/pampa/* RUN chmod +x /var/www/cgi-bin/pampa/*
......
import argparse
import json
import csv
from src import markers
from src import peptide_table as pt
from src import config
from src import utils
from functools import cmp_to_key, partial
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-r", dest="out_data")
parser.add_argument("-o", dest="output")
args = parser.parse_args()
alignment_page(args.out_data, args.output)
def alignment_page(result, output_path):
markers, _ = pt.parse_peptide_tables([result],None, None, False)
group = group_markers_species(markers)
final_group = alignment(group)
generate_page(final_group, output_path)
def group_markers_species(markers):
group = {}
for marker in markers:
code = marker.code()
if code in group:
group[code].append(marker)
else:
group[code] = [marker]
all_data = {}
for code in group:
list_of_markers = group[code]
tmp_seq = []
tmp_species = []
data = {}
for marker in list_of_markers:
seq = marker.sequence()
specie = marker.taxon_name()
if seq not in tmp_seq and specie not in tmp_species:
tmp_seq.append(seq)
tmp_species.append(specie)
data[seq] = [marker.mass(), specie]
elif seq in tmp_seq and specie not in tmp_species:
tmp_species.append(specie)
data[seq].append(specie)
all_data[code] = data
return all_data
def alignment(group_of_markers):
for marker in group_of_markers:
sequences = list(group_of_markers[marker].keys())
ref = sequences[0]
if len(sequences) > 1:
diff = []
for i in range(1, len(sequences)):
diff_pos = align(ref, sequences[i])
diff.append(diff_pos)
group_of_markers[marker]['diff'] = diff
return group_of_markers
def align(seq1, seq2):
diff_pos = []
for i in range(len(seq1)):
if seq1[i] != seq2[i]:
diff_pos.append(i)
return diff_pos
def generate_page(data, output_path):
html = """
<html>
<head>
<style>
body { font-family: monospace; padding: 20px; }
.diff { background-color: #ffcccc; }
.number {
display: inline-block;
font-size: 0.8em;
color: #444444;
margin-left: 5px;
}
.number2 {
display: inline-block;
font-size: 0.8em;
color: #444444;
margin-right: 5px;
}
h2 { margin-top: 40px; }
</style>
</head>
<body>
"""
for marker_name, marker_data in data.items():
sequences = {k: v[0] for k, v in marker_data.items() if k != "diff"}
species = {k: v[1:] for k, v in marker_data.items() if k != "diff"}
if "diff" in marker_data:
diff_positions = [pos[0] for pos in marker_data["diff"]]
else:
diff_positions = []
html += f"<h2>Marker: {marker_name}</h2>\n"
count = 1
legend = ""
for name, seq in sequences.items():
highlighted_seq = ""
for i, aa in enumerate(name):
if i in diff_positions:
highlighted_seq += f"<span class='diff'>{aa}</span>"
else:
highlighted_seq += aa
html += f"<div class='sequence-line'>{highlighted_seq}<span class='number'>{count}</span></div>\n"
legend += f"<div class='legend'><span class='number2'>{count}</span>Species: {', '.join(species[name])}</div>\n"
count += 1
html += "<br>"
html += legend
html += "</body></html>"
with open(output_path, "w") as f:
f.write(html)
if __name__ == '__main__':
main()
\ No newline at end of file
...@@ -9,6 +9,9 @@ from src import config ...@@ -9,6 +9,9 @@ from src import config
from src import utils from src import utils
from functools import cmp_to_key, partial from functools import cmp_to_key, partial
import alignment_maker
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-g", dest="or_data") parser.add_argument("-g", dest="or_data")
......
...@@ -64,10 +64,13 @@ def write_main_page(run_id, taxo_used, or_data, method, job_name=None): ...@@ -64,10 +64,13 @@ def write_main_page(run_id, taxo_used, or_data, method, job_name=None):
html += '''</div></div><div id="main"><div id="center">''' html += '''</div></div><div id="main"><div id="center">'''
table_dir = common.RESULT_DIR + run_id + "/table.php" table_dir = common.RESULT_DIR + run_id + "/table.php"
align_dir = common.RESULT_DIR + run_id + "/alignment.php"
command = f"/usr/bin/python {common.PAMPA_DIR}table_maker.py -g {or_data} -r {taxo_used} -o {table_dir} -m {method}" command = f"/usr/bin/python {common.PAMPA_DIR}table_maker.py -g {or_data} -r {taxo_used} -o {table_dir} -m {method}"
os.chdir(format(os.getcwd()) + "/pampa/") os.chdir(format(os.getcwd()) + "/pampa/")
os.system(command) os.system(command)
command = f"/usr/bin/python {common.PAMPA_DIR}alignment_maker.py -r {taxo_used} -o {align_dir}"
os.system(command)
if os.path.exists(table_dir): if os.path.exists(table_dir):
html += f'<h2>Results for job {run_id}{f" ({job_name})" if job_name else ""}</h2>' html += f'<h2>Results for job {run_id}{f" ({job_name})" if job_name else ""}</h2>'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment