-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadlen.py
More file actions
35 lines (28 loc) · 1 KB
/
Readlen.py
File metadata and controls
35 lines (28 loc) · 1 KB
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
import argparse
import matplotlib.pyplot as plt
def get_args():
parser = argparse.ArgumentParser(
description="Plots a histogram of read lengths from both read 1 and read 2 from trimommatic output"
)
parser.add_argument("-f", "--file", help="input trimommatic filename", required=True)
return parser.parse_args()
args = get_args()
Read1_lens = []
Read2_lens = []
with open(args.file, "r") as fh:
for line in fh:
line = line.strip()
line = line.split(" ")
read_num = line[1]
length = int(line[2])
if length != 0:
if read_num.startswith("1"):
Read1_lens.append(length)
elif read_num.startswith("2"):
Read2_lens.append(length)
plt.hist([Read1_lens, Read2_lens], bins = 20, log = True, color = ["Blue", "Orange"], label = ["Read 1", "Read 2"])
plt.legend(loc = "upper left")
plt.title("Read Length Distributions")
plt.xlabel("Read Length")
plt.ylabel("Frequency (log scale)")
plt.savefig("6_hist.png")