-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapstats.py
52 lines (43 loc) · 1.42 KB
/
mapstats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/env/python
import sys
import os
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid")
fhand = sys.argv[1]
out_suf = sys.argv[2]
name1 = '{}-counts.png'.format(out_suf)
name2 ='{}-percent.png'.format(out_suf)
path_name1 = os.path.join(os.path.dirname(fhand), name1)
path_name2 = os.path.join(os.path.dirname(fhand), name2)
# read flagstat out table and convert colums into numeric
a = pd.read_csv(fhand, sep=',')
a = a.dropna()
a['count_reads_mapped'] = a['count_reads_mapped'].astype(int)
a['percent_reads_mapped'] = a['percent_reads_mapped'].astype(int)
# number of reads mapped
# size a4 paper
plt.figure(figsize=(15,8))
az = sns.barplot(x="file_name", y="count_reads_mapped", data=a)
labels = [str(item.get_text()) for item in az.get_xticklabels()]
az.set_xticklabels(labels, rotation=90)
az.set_ylabel('count reads mapped')
az.set_xlabel('sample name')
plt.tight_layout()
plt.savefig(path_name1)
plt.gcf().clear()
# percent of reads from the total reads which map against the reference
# size a4 paper
plt.figure(figsize=(15,8))
az = sns.barplot(x="file_name", y="percent_reads_mapped", data=a)
labels = [str(item.get_text()) for item in az.get_xticklabels()]
az.set_xticklabels(labels, rotation=90)
az.set_ylabel('percent reads mapped')
az.set_xlabel('sample name')
plt.ylim(0, 100)
plt.tight_layout()
plt.savefig(path_name2)
plt.gcf().clear()