Create script to draw html graph to visualize STR results

parent 4e810be0
Gene;High normal range
AFF2;39
AR;35
ATN1;34
ATXN1;38
ATXN10;20
ATXN2;24
ATXN3;36
ATXN7;35
ATXN8OS;34
C9ORF72;19
CACNA1A;7
CNBP;26
CSTB;3
DIP2B;NA
DMPK;37
FMR1;45
FXN;32
HTT;34
JPH3;27
NOP56;8
PHOX2B;20
PPP2R2B;45
TBP;42
TCF4;NA
BEAN/TK2;NA
DAB1;NA
SAMD12;NA
\ No newline at end of file
#! /bin/sh
SCRIPT="$(dirname "$(readlink -f "$0")")/triplets_plotly.py"
cd '/work/gad/shared/analyse/STR/results2020-01-09' || exit 1
for locus_tsv in *.tsv; do
locus="$(basename "$locus_tsv" ".tsv")"
echo "Processing $locus" >&2
"$SCRIPT" "$locus" > "$locus.html"
done
#! /usr/bin/env python3
### ASDP PIPELINE ###
## triplets_plotly.py
## Version : 0.0.1
## Licence : FIXME
## Description : script to get automatically graphics from expansion pipeline results from getResults.py with Plotly
## Usage :
## Output : FIXME
## Requirements : FIXME
## Author : anne-sophie.denomme-pichon@u-bourgogne.fr
## Creation Date : 20200202
## last revision date : 20200202
## Known bugs : None
import collections
import csv
import os
import sys
path = '/work/gad/shared/analyse/STR/results2020-01-09'
def display_console_graph(title, data):
print(title)
for x, y in data:
print(f'{x}\t{"*" * y}')
def display_html_graph(title, data):
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(
x=[x for (x, y) in data],
y=[y for (x, y) in data]
)],
layout_title_text=title
)
print(fig.to_html())
def graph_locus(locus):
title = f'Effectif pour chaque nombre de répétitions au locus {locus}'
with open(f'{path}{os.sep}{locus}.tsv') as result_file:
tsvreader = csv.reader(result_file, delimiter='\t')
try:
next(tsvreader)
counter = collections.Counter()
counter[0] = 0
for row in tsvreader:
if row[1] not in ['.', 'nofile']:
for count in row[1].split(','):
counter[int(count)] += 1
except StopIteration:
print('Input file is empty', file=sys.stderr)
sys.exit(1)
data = sorted(counter.items())
#display_console_graph(title, data)
display_html_graph(title, data)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'Usage: {sys.argv[0].split(os.sep)[-1]} <LOCUS>', file=sys.stderr)
sys.exit(1)
graph_locus(sys.argv[1])
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