Handle all tools from the input tsv files when plotting

parent d17f9a99
...@@ -21,42 +21,57 @@ import sys ...@@ -21,42 +21,57 @@ import sys
path = '/work/gad/shared/analyse/STR/results2020-01-09' path = '/work/gad/shared/analyse/STR/results2020-01-09'
def display_console_graph(title, data): def display_console_graph(title, tools, data):
print(title) print(title)
for x, y in data: for tool, tool_data in zip(tools, data):
print(tool)
for x, y in tool_data:
print(f'{x}\t{"*" * y}') print(f'{x}\t{"*" * y}')
def display_html_graph(title, data): def display_html_graph(title, tools, data):
import plotly.graph_objects as go import plotly.graph_objects as go
import plotly.subplots as sp
fig = go.Figure( figure = sp.make_subplots(
data=[go.Bar( rows=len(tools),
x=[x for (x, y) in data], cols=1,
y=[y for (x, y) in data] subplot_titles=tools
)],
layout_title_text=title
) )
print(fig.to_html()) for tool_id in range(len(tools)):
figure.add_trace(
go.Bar(
x=[x for (x, y) in data[tool_id]],
y=[y for (x, y) in data[tool_id]]
),
row=tool_id + 1,
col=1
)
figure.update_layout(title_text=title, showlegend=False)
print(figure.to_html())
def graph_locus(locus): def graph_locus(locus):
title = f'Effectif pour chaque nombre de répétitions au locus {locus}' title = f'Effectif pour chaque nombre de répétitions au locus {locus}'
data = []
with open(f'{path}{os.sep}{locus}.tsv') as result_file: with open(f'{path}{os.sep}{locus}.tsv') as result_file:
tsvreader = csv.reader(result_file, delimiter='\t') tsvreader = csv.reader(result_file, delimiter='\t')
try: try:
next(tsvreader) tools = next(tsvreader)[1:]
counter = collections.Counter() counters = [collections.Counter({0: 0}) for tool in tools]
counter[0] = 0
for row in tsvreader: for row in tsvreader:
if row[1] not in ['.', 'nofile']: for tool_id in range(len(tools)):
for count in row[1].split(','): if row[tool_id + 1] not in ['.', 'nofile']:
counter[int(count)] += 1 for count in row[tool_id + 1].split(','):
counters[tool_id][int(count)] += 1
except StopIteration: except StopIteration:
print('Input file is empty', file=sys.stderr) print('Input file is empty', file=sys.stderr)
sys.exit(1) sys.exit(1)
data = sorted(counter.items()) for tool_id in range(len(tools)):
#display_console_graph(title, data) data.append(sorted(counters[tool_id].items()))
display_html_graph(title, data) #display_console_graph(title, tools, data)
display_html_graph(title, tools, data)
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment