-
Notifications
You must be signed in to change notification settings - Fork 0
/
libTrim.py
167 lines (146 loc) · 6.64 KB
/
libTrim.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
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
import libConfig, libPrint
import pathlib
"""
--- README of 03-trim ---
Title:
Batch Processing for Trimmomatic
Original command:
java -jar <bin>/trimmomatic-0.35.jar PE \\
-phred33 -threads <threads> \\
input_forward.fq.gz input_reverse.fq.gz \\
output_forward_paired.fq.gz output_forward_unpaired.fq.gz \\
output_reverse_paired.fq.gz output_reverse_unpaired.fq.gz \\
<ILLUMINACLIP> <LEADING> \\
<TRAILING> <SLIDINGWINDOW> <MINLEN>
java -jar <bin>/trimmomatic-0.35.jar SE \\
-phred33 -threads <threads> \\
input.fq.gz output.fq.gz \\
<ILLUMINACLIP> <LEADING> \\
<TRAILING> <SLIDINGWINDOW> <MINLEN>
--- README ---
"""
class trimmer:
def __init__(self):
# ---- Initialization ----
self.queryStr = str()
def trimming(self):
# ---- Parameter ----
BinTrim = libConfig.config()
BinTrim.queryStr = "binTrimmomatic"
BinTrim.folderStr = "config/"
BinTrim.modeStr = "UPDATE"
BinTrim.load()
ExpRep = libConfig.config()
ExpRep.queryStr = self.queryStr
ExpRep.folderStr = "config/"
ExpRep.modeStr = "UPDATE"
ExpRep.load()
# ---- Initialization ----
commandStr = BinTrim.storeDict["command"]
conditionList = ExpRep.storeDict.get("conditionsList",[])
groupList = ExpRep.storeDict.get("group",[])
replicationList = ExpRep.storeDict.get("replication",[])
directionList = ExpRep.storeDict.get("direction",[])
branchStr = ExpRep.storeDict.get("branch","")
pairStr = ExpRep.storeDict.get("pairPostfix","")
unpairStr = ExpRep.storeDict.get("unpairPostfix","")
modeStr = ExpRep.storeDict.get("mode","")
inputFileNameStr = ExpRep.storeDict.get("[trim]inputFileName","")
outputFileNameStr = ExpRep.storeDict.get("[trim]outputFileName","")
fileTypeStr = ExpRep.storeDict.get("[trim]fileType","")
checkFolderList = ExpRep.storeDict.get("checkFolder",[])
if not ExpRep.storeDict.get("testing",True):
testingBool = False
else:
testingBool = True
# ---- Action ----
for folderStr in checkFolderList:
pathlib.Path(folderStr).mkdir(parents=True,exist_ok=True)
if type(conditionList) == type(list()) and conditionList != []:
for conditionDict in conditionList:
conditionStr = conditionDict['trim']
Print = libPrint.timer()
Print.logFilenameStr = "03-trim-{branch}-{cond}".format(
branch=branchStr,
cond=conditionStr
)
Print.folderStr = "log/"
Print.testingBool = testingBool
Print.startLog()
TrimPara = libConfig.config()
TrimPara.queryStr = conditionStr
TrimPara.folderStr = "config/"
TrimPara.modeStr = "UPDATE"
TrimPara.load()
headerStr = TrimPara.storeDict.get('header',"")
for groupStr in groupList:
for replicationStr in replicationList:
if modeStr == "pairEnd":
inputFileList = list()
outputFileList = list()
for directionStr in directionList:
inputStr = inputFileNameStr.format(
group=groupStr,
replication=replicationStr,
direction=directionStr,
fileType=fileTypeStr
)
inputFileList.append(inputStr)
outputPairStr = outputFileNameStr.format(
condition=headerStr,
direction=directionStr,
group=groupStr,
replication=replicationStr,
pairType=pairStr,
fileType=fileTypeStr,
)
outputFileList.append(outputPairStr)
outputUnPairStr = outputFileNameStr.format(
condition=headerStr,
direction=directionStr,
group=groupStr,
replication=replicationStr,
pairType=unpairStr,
fileType=fileTypeStr,
)
outputFileList.append(outputUnPairStr)
fileList = inputFileList + outputFileList
fileStr = " ".join(fileList)
commandDict = dict()
commandDict.update(TrimPara.storeDict)
commandDict.update({
'files' : fileStr,
'mode' : "PE",
})
CommandStr = commandStr.format(**commandDict)
Print.phraseStr = CommandStr
Print.runCommand()
elif modeStr == "singleEnd":
inputStr = inputFileNameStr.format(
group=groupStr,
replication=replicationStr,
fileType=fileTypeStr
)
outputStr = outputFileNameStr.format(
condition=headerStr,
group=groupStr,
replication=replicationStr,
fileType=fileTypeStr,
)
fileStr = "{} {}".format(inputStr,outputStr)
commandDict = dict()
commandDict.update(TrimPara.storeDict)
commandDict.update({
'files' : fileStr,
'mode' : "SE",
})
CommandStr = commandStr.format(**commandDict)
Print.phraseStr = CommandStr
Print.runCommand()
Print.stopLog()
if __name__ == "__main__":
print("__name__ == "+__name__)
Trim = trimmer()
Trim.queryStr = "testing"
Trim.trimming()