-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_by_marker.py
More file actions
80 lines (60 loc) · 1.82 KB
/
split_by_marker.py
File metadata and controls
80 lines (60 loc) · 1.82 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This script splits libraries obtained from sequencing with different markers. I.e. one library - one marker.
# You will have to provide read ids where another marker start. Read ids should be provided in text file: one line - one read id.
# For now you should provide only one stop read id, i.e. when the program sees this id, it stops and writes content into provided
# output file.
from Bio.Seq import Seq
from Bio import SeqIO
from Bio.Alphabet import generic_dna
import sys
def split_by_marker1(infile, outfile, id) :
handle = open(infile, "rU")
records = []
for record in SeqIO.parse(handle, "fastq") :
if record.id == id :
break
records.append(record)
handle.close()
# Writing output
handle = open(outfile, "w")
SeqIO.write(records, handle, "fastq")
def split_by_marker2(infile, outfile, id) :
handle = open(infile, "rU")
records = []
flag = False
for record in SeqIO.parse(handle, "fastq") :
if record.id == id :
#break
flag = True
if flag == True :
records.append(record)
handle.close()
# Writing output
handle = open(outfile, "w")
SeqIO.write(records, handle, "fastq")
def rev2fwd(infile, outfile) :
handle = open(infile, "rU")
records = []
revcomp = False
for record in SeqIO.parse(handle, "fastq") :
if record.id == "SRR072221.58746" :
break
if record.id == "SRR072221.29034" :
revcomp = True
if revcomp == True :
new_record = record.reverse_complement()
new_record.id = record.id
new_record.description = record.description
records.append(new_record)
else :
records.append(record)
handle.close()
# Writing output
handle = open(outfile, "w")
SeqIO.write(records, handle, "fastq")
def main() :
outfile = sys.argv[-2]
infile = sys.argv[-3]
read_id = sys.argv[-1]
split_by_marker2(infile, outfile, read_id)
if __name__ == '__main__':
main()