-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbamdepth2coverageplot.py
More file actions
executable file
·27 lines (21 loc) · 1010 Bytes
/
bamdepth2coverageplot.py
File metadata and controls
executable file
·27 lines (21 loc) · 1010 Bytes
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
#!/usr/bin/env python
import argparse, pandas as pd, matplotlib.pyplot as plt
# command line parsing info
parser = argparse.ArgumentParser(description='Create coverage plot')
parser.add_argument('-b', '--bamdepth', type=argparse.FileType('r'), required=True, help='samtools depth output file')
parser.add_argument('-s', '--sample', type=str, required=True, help='sample name')
parser.add_argument('-f', '--filetype', type=str, default='png', help='output filetype (default: png)')
args = parser.parse_args()
def covergage_plot():
with args.bamdepth as file:
depth = pd.read_csv(args.bamdepth, header=None, names=['Contig', 'Position', 'Depth'], sep="\t")
sample = args.sample
filetype = args.filetype
outname = '.'.join([sample, filetype])
# TODO loop through possible contigs
plt.bar(x='Position', height='Depth', width=1, data=depth, color='black')
plt.xlabel('Genomic Position')
plt.ylabel('Read Depth')
plt.title(sample)
plt.savefig(outname, format=filetype)
covergage_plot()