-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalign_all.py
More file actions
46 lines (42 loc) · 1.84 KB
/
align_all.py
File metadata and controls
46 lines (42 loc) · 1.84 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
#!/usr/bin/env python
# Import packages
import argparse
import subprocess
import os
# Arguments
parser = argparse.ArgumentParser(description=
"****************************************************************************\n"
"STAR alignment with default parameters for all files in specified directory,"
" compressed FASTA files with R1(/R2).fq.gz extensions are expected\n"
"****************************************************************************")
parser.add_argument("cores", type = int, help="Number of cores used (Default = 2)", default=2)
parser.add_argument("genomeDir", help="Reference genome directory")
parser.add_argument("-v", "--verbose", action="store_true", help="Prints what is going on")
parser.add_argument("-w", "--workdir", action = "store", help = "Input directory",
default = os.getcwd())
parser.add_argument("-o", "--outdir", action = "store", help = "Output directory",
default = os.getcwd())
args = parser.parse_args()
# Main program
iniDir = os.getcwd()
dirFiles = os.listdir(iniDir)
R1files = [f for f in dirFiles if "R1.fq.gz" in f]
for file in R1files:
read1 = file
read2 = file.replace("R1.fq.gz", "R2.fq.gz")
outPreffix = file.replace("R1.fq.gz", "")
if args.verbose:
print("{} alignment started...".format(outPreffix))
subprocess.call("STAR --runMode alignReads "
"--runThreadN {} "
"--genomeDir {} "
"--readFilesCommand zcat "
"--readFilesIn {} {} "
"--outFileNamePrefix {} "
"--outSAMtype BAM SortedByCoordinate"
"".format(args.cores, args.genomeDir, read1, read2,
outPreffix), shell = True)
if args.verbose:
print("... alignment done!")
if args.verbose:
print("All alignments done!!! :D")