-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathYAPFastaCleanup.py
155 lines (115 loc) · 4.21 KB
/
YAPFastaCleanup.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
########################################################################################
## This file is a part of YAP package of scripts. https://github.com/shpakoo/YAP
## Distributed under the MIT license: http://www.opensource.org/licenses/mit-license.php
## Copyright (c) 2011-2013 Sebastian Szpakowski
########################################################################################
#################################################
## A pipeline for cleaning up contaminants
#################################################
import sys
from optparse import *
from StepsLibrary import *
from StepsLibrary_EXP import *
from collections import defaultdict
_author="Sebastian Szpakowski"
_date="2011/01/01"
_version="Version 1"
#################################################
## Classes
##
#################################################
## Functions
##
#################################################
## Arguments
##
parser = OptionParser()
parser.add_option("-d", "--directory", dest="dn_fasta", default="",
help="directory that will be scanned to fasta files", metavar="path/to/dir")
parser.add_option("-f", "--fasta", dest="fn_fasta", default="",
help="fasta file", metavar="path/to/file")
parser.add_option("-r", "--reference", dest="reference", default="human",
help="reference genome of the host (to filter out contaminants)", metavar="human")
parser.add_option("-P", "--PROJECT", dest="project", default="",
help="project code", metavar="#")
parser.add_option("-E", "--EMAIL", dest="email", default="",
help="e-mail address", metavar="@")
group = OptionGroup(parser, "Technical", "\"behind-the-scene\" options")
group.add_option("-T", "--threads",
dest="maxThreads",type="int", default=4,
help="maximum number of threads to spawn. [default: %default]")
group.add_option("-N", "--nodes",
dest="maxNodes",type="int", default=125,
help="maximum number of grid-nodes to use. [default: %default]")
group.add_option("-F", "--filesOpen",
dest="maxFiles",type="int", default=5,
help="maximum number of files opened at a given time. [default: %default]")
group.add_option("-C", "--NODESIZE", dest="nodesize", default=30,
help="maximum number of grid node's CPUs to use", metavar="#")
parser.add_option_group(group)
(options, args) = parser.parse_args()
#################################################
## Begin
##
if options.fn_fasta=="" and options.dn_fasta== "" or options.project=="":
parser.print_help()
sys.exit(1)
CLEAN= list()
ASSEMBLIES = list()
COVERAGES = list()
READS = list()
if options.reference =="mouse":
ref= "/usr/local/projects/KFLAB/sszpakow/annotation/GENOMES/MM9/mm9"
else:
ref = "/usr/local/projects/KFLAB/sszpakow/annotation/GENOMES/HG19/hg19"
files = list()
if options.fn_fasta != "":
files.extend(options.fn_fasta.split(","))
if options.dn_fasta != "":
for ext in ("fa", "fasta", "fna"):
tmp = glob.glob("%s/*.%s" % (options.dn_fasta, ext) )
if len(tmp)>0:
files.extend(tmp)
init(options.project, options.email)
for file in files:
type = file.strip().split(".")[-1]
INS= {type: ["%s" % (file)]}
S1 = FileImport(INS)
if type=="fastq":
Q = getQ(file)
ARGS = {
"-Q": Q
}
S2 = fastq2fasta({}, ARGS, [S1])
else:
S2 = S1
S3 = FastaSplit({"types": "fasta", "chunk": "100000"}, [S2])
ARGS = {
"-x" : ref,
"-k" : "1",
"--nondeterministic": "",
"--local" : "",
"--no-unal": "",
"--no-hd": "",
"--no-sq": "",
"-N": "1",
"-p": "4"
}
S4a = Bowtie2(dict(), ARGS, [S3])
ARGS = {
"type": "sam",
"newtype": "filter",
"awk" : " NF>2 {print $1}",
"uniq" : "",
"sort" : "",
"postprocess" : " tr -d \"@\" | sort | uniq "
}
S4 = AwkCommand({}, ARGS, [S4a] )
S5 = ContaminantRemoval(dict(), {"-t": "fasta" }, [S4])
p = "".join(file.strip().split("/")[-1].split(".")[0:-1])
S6 = FileMerger("fasta", [S5], prefix = p)
CLEAN.append(S6)
OutputStep("CLEAN", "fasta", CLEAN)
##################################################
### Finish
##################################################?