forked from georgek/bio-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastq-subsample.py
executable file
·37 lines (32 loc) · 1.07 KB
/
fastq-subsample.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
#!/usr/bin/env python
import sys
import argparse
# ----- command line parsing -----
parser = argparse.ArgumentParser(
description="Subsample a read file to lower coverage and/or read length.")
parser.add_argument("fastq_file", type=str, help="FASTQ file.")
parser.add_argument("divide_coverage", type=int, help="Amount of divide coverage by.")
parser.add_argument("read_length", type=int, help="Length to reduce reads to.")
args = parser.parse_args()
# ----- end command line parsing -----
lines = 0
reads = 0
name = ""
read = ""
qual = ""
input_file = open(args.fastq_file)
for line in input_file:
if lines == 0:
name = line[1:-1]
elif lines == 1:
read = line[:-1]
if args.read_length < len(read):
read = read[:args.read_length]
elif lines == 3:
qual = line[:-1]
if args.read_length < len(qual):
qual = qual[:args.read_length]
if reads == 0:
sys.stdout.write("@{:s}\n{:s}\n+\n{:s}\n".format(name, read, qual))
reads = (reads + 1) % args.divide_coverage
lines = (lines + 1) % 4