-
Notifications
You must be signed in to change notification settings - Fork 0
/
Molsero.py
executable file
·61 lines (51 loc) · 1.6 KB
/
Molsero.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
56
57
58
59
60
61
#!/usr/bin/env python3
import argparse
from SeqUtils import Fsa
import io
#import gzip
import subprocess as sp
import os
devnull=open(os.devnull,"w")
parser = argparse.ArgumentParser(description='')
parser.add_argument("contigs",type=argparse.FileType())
parser.add_argument("-v","--verbose",action="store_true",default=False,help="Print errors to StdErr")
parser.add_argument("-p","--primers",type=argparse.FileType(), required=True)
args=parser.parse_args()
primerfile=args.primers.name
primers=Fsa("".join(args.primers.readlines()))
contigfile=args.contigs.name
idxh=sp.Popen(("bwa","index",contigfile),stderr=devnull)
idxh.wait()
samOutput=sp.Popen(("bwa","mem","-B","5","-p","-T","15","-k","13",contigfile,primerfile),stdout=sp.PIPE,stderr=devnull).communicate()[0]
samOutput=samOutput.decode().split("\n")
matches=dict()
for line in samOutput:
if len(line)==0:
continue
if line.startswith("@"):
if args.verbose:
print(line)
continue
field=line.split("\t")
if(not int(field[1]) & 4):
matches[field[0]]=field
bands=set()
for k in sorted(matches.keys()):
if args.verbose:
print("\t".join(matches[k]))
else:
if k.endswith("-F"):
bands.add(k.rstrip("-F"))
print("{}\t{}".format(k.rstrip("-F"),abs(int(matches[k][8]))))
if bands== set(('lmo0737','prs')):
print('IIa')
elif bands== set(('ORF2819','prs')):
print('IIb')
elif bands== set(('lmo1118','lmo0737','prs')):
print('IIc')
elif bands== set(('ORF2110','ORF2819','prs')):
print('IVb')
elif bands== set(('prs')):
print('L')
else:
print("Eureka!!")