-
Notifications
You must be signed in to change notification settings - Fork 0
/
kraken2paired.py
58 lines (36 loc) · 1.46 KB
/
kraken2paired.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 python3
#Theo Allnutt 2021.
#Usage:
#kraken2paired.py "reads/*.fastq" kraken_results/ 0 24 kraken2_paftol2/
#Where 'reads/' is a directory containing paired fastq read files for all samples to be analysed
#0 is the kraken2 confidence value. In this case we want all read hits, so use zero
#24 is the number of threads
#kraken2_paftol2/ is the kraken2 report output directory
import sys
import re
import glob
import subprocess
import os
digits = re.compile(r'(\d+)')
def tokenize(filename):
return tuple(int(token) if match else token
for token, match in
((fragment, digits.search(fragment))
for fragment in digits.split(filename)))
folder = sys.argv[1]
folder = os.path.expanduser(folder)
filelist=glob.glob(folder)
filelist.sort(key=tokenize)
print(filelist)
outfolder=sys.argv[2]
subprocess.Popen("mkdir -p %s" %outfolder,shell=True).wait()
#subprocess.Popen("module load kraken2",shell=True).wait()
conf= sys.argv[3]
threads=sys.argv[4]
db= sys.argv[5]
for i in range(0,len(filelist)-1,2):
print('Processing:',filelist[i],filelist[i+1])
filename=filelist[i].split("/")[-1].split("_")[0]
outname=outfolder+filename
subprocess.Popen("kraken2 --db %s %s %s --threads %s --confidence %s --report %s.report --use-names --paired" %(db,filelist[i],filelist[i+1],threads,conf,outname),shell=True).wait()
#--unclassified-out %s#.nohit.fastq --classified-out %s#.hit.fastq --use-mpa-style -output %s.out