-
Notifications
You must be signed in to change notification settings - Fork 1
/
split-strand-rna.py
executable file
·55 lines (48 loc) · 1.44 KB
/
split-strand-rna.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
53
54
55
#!/usr/bin/env python
####### Strand splitting script
###### Daria Gavriouchkina
###### Sauka-Spengler lab
import pysam
import sys
sam=pysam.Samfile("-", "r")
name=sys.argv[1]
sense= pysam.Samfile(name+'_+.sam', "wh", header=sam.header)
antisense= pysam.Samfile(name+'_-.sam', "wh", header=sam.header)
prob_ct=0
n,n_um,n_ps,n_pr,n_ss,n_sr=0,0,0,0,0,0
for fwd in sam.fetch():
n+=1
if n%100000==0:
print "{0} reads ... paired: {1}/{2}, unpaired: {3}/{4}".format(n,n_ps,n_pr,n_ss,n_sr,n_um)
if fwd.is_unmapped:
n_um+=1
continue
if fwd.is_proper_pair:
rev=sam.next()
if fwd.is_read1 and rev.is_read2:
if not fwd.is_reverse and rev.is_reverse:
n_ps+=1
#print "sens +"
sense.write(fwd)
sense.write(rev)
elif fwd.is_reverse and not rev.is_reverse:
n_pr+=1
#print "sens -"
antisense.write(fwd)
antisense.write(rev)
else:
#print "We have a problem!!!"
prob_ct+=1
else:
if fwd.is_reverse:
n_sr+=1
antisense.write(fwd)
else:
n_ss+=1
sense.write(fwd)
print "unmapped: {0}".format(n_um)
print "paired sens: {0}".format(n_ps)
print "paired antisens: {0}".format(n_pr)
print "single sens: {0}".format(n_ss)
print "single antisens: {0}".format(n_sr)
print "problems=", prob_ct