-
Notifications
You must be signed in to change notification settings - Fork 0
/
LMToolkit.py
159 lines (139 loc) · 4.14 KB
/
LMToolkit.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 14 17:08:19 2021
@author: sb069
"""
import subprocess
import errno
import os
def main():
global outpathgupfinal
global qinputgup
global q1
global Alignq
global Assembleq
global basecallconfig
global basecall
global folderoutgup
global outfilename
global plasmid
global outpathgup
global refpath
with open("config.txt","r") as basecallpath:
basecall=basecallpath.read()
print("This is your basecaller path " + basecall)
with open("guppyconfig.txt","r") as configpath:
basecallconfig=configpath.read()
print("This is your config file path " + basecallconfig)
qinputgup=input("What is the name of the input fast5 folder (drag and drop it here): ")
folderoutgup=input("What would you like to the name the output folder?: ")
q1=input("Are you expecting plasmids? [y/N]: ")
Alignq=input("Would you like to run an alignment [y/N]: ")
Assembleq=input("Would you like to run an assembly [y/N]: ")
print("The output of guppy will be found here: MinionOut/"+folderoutgup)
outpathgup="MinionOut/"+folderoutgup
outpathgupfinal=outpathgup
if Alignq == "y":
refpath=input("What is the path to your reference file? (drag and drop it here): ")
basecalling()
else:
basecalling()
def basecalling():
global outpathgupfinal
global qinputgup
global q1
global Alignq
global Assembleq
global basecallconfig
global basecall
global folderoutgup
global outfilename
global plasmid
global outpathgup
global outpath1
global outpath
try:
os.system("mkdir " + outpathgup)
except OSError as e:
if e.errno != errno.EEXIST:
raise
string1='sudo ' + basecall + ' -i ' + qinputgup + ' -s ' + outpathgupfinal + ' -c ' + basecallconfig + ' -x ' '"cuda:0"'
print(string1)
os.system(string1)
outpath="Assembly_Out/"+folderoutgup
outpath1="'"+outpath+"'"
#Merger Start
folderin=outpathgupfinal
folderin.strip()
#folderin=folderin[:-1]
#folderin=folderin[1:]
print(folderin) #check 1 for strip
outfilename=folderoutgup
outfilename=outfilename +'.fastq'
print("the merged file will be located in " + folderin + " named as " + outfilename)
#os.chdir(folderin) #Check 2 for strip
string3 = str('cd ' + folderin + ";" + "cat *.fastq > " + outfilename)
print(string3)
subprocess.run(string3, shell=True)
if Assembleq == "y" and Alignq == "y" :
flye()
elif Assembleq == "N" and Alignq== "y":
Align()
elif Assembleq == "N" and Alignq == "N":
pass
elif Assembleq == "y" and Alignq == "N":
flye()
else:
(flye)
#Flye Start
def flye():
global outfilename
global q1
global plasmid
global outpathgupfinal
global qinputgup
global q1
global Alignq
global Assembleq
global basecallconfig
global basecall
global folderoutgup
global outfilename
global plasmid
global outpathgup
global inassemble
global outpath1
global outpath
qinput=outfilename
if q1=='y':
plasmid= '--plasmid '
elif q1=='N':
plasmid=" "
else:
plasmid='--plasmid'
try:
os.system("mkdir -p " +outpath )
except OSError as e:
if e.errno != errno.EEXIST:
raise
inassemble=outpathgupfinal+"/"+outfilename
print("The assembled output will be found here: " + outpath)
string2='flye ' '-o ' + outpath1 + ' --threads 14 ' '-i 3 ' ' --nano-raw ' + inassemble + " " + plasmid
print(string2)
os.system(string2)
if Alignq=="N":
print("This program has now finished!")
else:
Align()
def Align():
global outpathgupfinal
global basecall
global outpath1
global refpath
alignpath=basecall.replace("basecaller","aligner")
stringalign= 'sudo ' + alignpath + "-i " + outpathgupfinal + " -s " + outpath1 + " -a " + refpath + " --bam"
print(stringalign)
os.system(stringalign)
print("This program has now finished!")
main()