-
Notifications
You must be signed in to change notification settings - Fork 0
/
hoonah.py
177 lines (131 loc) · 5.16 KB
/
hoonah.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
168
169
170
171
172
173
174
175
176
177
import pandas as pd
import os
import time
import subprocess
import sys
import re
class bcolors:
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
OKWARNING = '\033[93m'
#################################
squeue = 'squeue '
sbatch = 'sbatch '
################################
dat_file = sys.argv[1]
WD = sys.argv[2]
scripts = sys.argv[3]
user = sys.argv[4]
dat = pd.read_csv(dat_file, header=None)
species_list = []
for index, row in dat.iterrows():
species_list.append(row[0])
for i in (list(dict.fromkeys(species_list))):
SpeciesCheck = str(subprocess.check_output('ls ' + WD + '/raw/', shell=True))
if i not in SpeciesCheck:
species = i
print(f"{bcolors.OKBLUE}")
print(f"{bcolors.OKGREEN}Download SRR files, QC and trim")
print(f"{bcolors.OKBLUE}")
for index, row in dat.iterrows():
try:
if row[0] == species:
SRR = row[1]
sex = row[2]
layout = row[3]
command = sbatch + scripts + '/download_trim_qc.sh ' + species + ' ' + SRR + ' ' + sex + ' ' + layout + ' ' + WD
subprocess.Popen([command], shell=True)
time.sleep(5)
check = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep download | wc -l', shell=True))
while check > 1:
time.sleep(10)
check = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep download | wc -l', shell=True))
except:
pass
check2 = str(subprocess.check_output(squeue + ' --user=' + user, shell=True))
while 'download' in check2:
time.sleep(10)
check2 = str(subprocess.check_output(squeue + ' --user=' + user, shell=True))
print(f"{bcolors.OKBLUE}")
print(f"{bcolors.OKGREEN}Runing Trinity, BUSCO and Blast")
print(f"{bcolors.OKBLUE}")
df_paired = pd.DataFrame()
df_single = pd.DataFrame()
for index, row in dat.iterrows():
if row[0] == species:
if row[3] == 'PAIRED':
df_paired = df_paired.append(row[0:4], ignore_index=True)
if row[3] == 'SINGLE':
df_single = df_single.append(row[0:4], ignore_index=True)
##############################################################################################################################
# Trinity paired
check3 = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep trinity | wc -l', shell=True))
while check3 > 2:
time.sleep(10)
check3 = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep trinity | wc -l', shell=True))
if df_paired.empty == False:
command = sbatch + scripts + '/trinity_busco_blast.sh ' + species + ' PAIRED ' + WD
subprocess.Popen([command], shell=True)
##############################################################################################################################
# Trinity single
check4 = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep trinity | wc -l', shell=True))
while check4 > 2:
time.sleep(10)
check4 = int(subprocess.check_output(squeue + ' --user=' + user + ' | grep trinity | wc -l', shell=True))
if df_single.empty == False:
command = sbatch + scripts + '/trinity_busco_blast.sh ' + species + ' SINGLE ' + WD
subprocess.Popen([command], shell=True)
##############################################################################################################################
# Pause pipeline for both transcriptomes to be assembled and compared if both paired and single end layout libraries are used
time.sleep(30)
print(f"{bcolors.OKWARNING}Paused for completion of transcriptome assembly(s)")
print(f"{bcolors.OKBLUE}")
trinity_check = 'yes'
while trinity_check == 'yes':
command = squeue + '--user=' + user + ' -h | awk \'{print $1}\''
check5 = str(subprocess.check_output(command, shell=True))
result = re.sub('[^0-9]',' ', check5)
for i in result.split():
try:
file = '/projects/sykesj/StdOut/R-%x.' + i + '-Trinity.out'
with open(file, 'r') as f:
if species not in f.read():
trinity_check = 'no'
except:
pass
time.sleep(1800)
##########################################################
print(f"{bcolors.OKBLUE}")
print(f"{bcolors.OKGREEN}Maping SRA libraries to de novo transcriptome")
print(f"{bcolors.OKBLUE}")
for index, row in dat.iterrows():
try:
if row[0] == species:
SRR = row[1]
sex = row[2]
layout = row[3]
command = sbatch + scripts + '/map.sh ' + species + ' ' + SRR + ' ' + sex + ' ' + layout + ' ' + DUEL_LAYOUT + ' ' + WD
subprocess.Popen([command], shell=True)
except:
pass
time.sleep(5)
check6 = str(subprocess.check_output(squeue + ' --user=' + user, shell=True))
while 'map' in check6:
time.sleep(10)
check6 = str(subprocess.check_output(squeue + ' --user=' + user, shell=True))
print(f"{bcolors.OKBLUE}")
print(f"{bcolors.OKGREEN}Filtering contaminant sequences")
print(f"{bcolors.OKBLUE}")
for index, row in dat.iterrows():
try:
if row[0] == species:
SRR = row[1]
sex = row[2]
layout = row[3]
command = sbatch + scripts + '/blob.sh ' + species + ' ' + SRR + ' ' + layout + ' ' + WD
subprocess.Popen([command], shell=True)
except:
pass
print(f"{bcolors.OKBLUE}")
print(f"{bcolors.OKGREEN}Pipeline complete for " + species)
print(f"{bcolors.OKBLUE}")