annotate cpo_galaxy_prediction.py @ 2:29302ffdf137 draft

planemo upload
author jjjjia
date Mon, 20 Aug 2018 14:19:56 -0400
parents fea89c4d5227
children e6027598a35c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
1 #!/home/jjjjia/.conda/envs/py36/bin/python
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
2
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
3 #$ -S /home/jjjjia/.conda/envs/py36/bin/python
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
4 #$ -V # Pass environment variables to the job
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
5 #$ -N CPO_pipeline # Replace with a more specific job name
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
6 #$ -wd /home/jjjjia/testCases # Use the current working dir
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
7 #$ -pe smp 8 # Parallel Environment (how many cores)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
8 #$ -l h_vmem=11G # Memory (RAM) allocation *per core*
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
9 #$ -e ./logs/$JOB_ID.err
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
10 #$ -o ./logs/$JOB_ID.log
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
11 #$ -m ea
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
12 #$ -M bja20@sfu.ca
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
13
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
14 #~/scripts/pipeline.py -i BC11-Kpn005_S2 -f /data/jjjjia/R1/BC11-Kpn005_S2_L001_R1_001.fastq.gz -r /data/jjjjia/R2/BC11-Kpn005_S2_L001_R2_001.fastq.gz -o pipelineResultsQsub -e "Klebsiella pneumoniae"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
15
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
16 import subprocess
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
17 import pandas
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
18 import optparse
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
19 import os
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
20 import datetime
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
21 import sys
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
22 import time
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
23 import urllib.request
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
24 import gzip
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
25 import collections
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
26 import json
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
27 import numpy
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
28
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
29
2
29302ffdf137 planemo upload
jjjjia
parents: 1
diff changeset
30 debug = False #True #debug skips the shell scripts and also dump out a ton of debugging messages
1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
31
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
32 if not debug:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
33 #parses some parameters
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
34 parser = optparse.OptionParser("Usage: %prog [options] arg1 arg2 ...")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
35 #required
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
36 parser.add_option("-i", "--id", dest="id", type="string", help="identifier of the isolate")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
37 parser.add_option("-a", "--assembly", dest="assemblyPath", type="string", help="absolute file path to contigs fasta")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
38 parser.add_option("-c", "--card-db", dest="cardDB", default = "/home/jjjjia/databases/card202.json", type="string", help="absolute path to card reference database")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
39 parser.add_option("-o", "--output", dest="output", default='./', type="string", help="absolute path to output folder")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
40 parser.add_option("-e", "--expected", dest="expectedSpecies", default="NA/NA/NA", type="string", help="expected species of the isolate")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
41
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
42 #optionals
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
43 parser.add_option("-k", "--script-path", dest="scriptDir", default="/home/jjjjia/scripts", type="string", help="absolute file path to this script folder")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
44 parser.add_option("-b", "--update-abricate-path", dest="updateAbPath", default = "", type="string", help="absolute file path to fasta sequence used for abricate database")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
45 parser.add_option("-m", "--update-abricate-dbname", dest="updateAbName", default = "default", type="string", help="name of abricate database to update")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
46 parser.add_option("-u", "--update-mlst", dest="updateMLST", default = "False", type="string", help="True = update MLST")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
47 #used for parsing
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
48 parser.add_option("-s", "--mlst-scheme", dest="mlst", default= "/home/jjjjia/databases/scheme_species_map.tab", type="string", help="absolute file path to mlst scheme")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
49
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
50
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
51 #parallelization, useless, these are hard coded to 8cores/64G RAM
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
52 #parser.add_option("-t", "--threads", dest="threads", default=8, type="int", help="number of cpu to use")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
53 #parser.add_option("-p", "--memory", dest="memory", default=64, type="int", help="memory to use in GB")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
54
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
55 (options,args) = parser.parse_args()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
56 #if len(args) != 8:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
57 #parser.error("incorrect number of arguments, all 7 is required")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
58 curDir = os.getcwd()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
59 outputDir = options.output
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
60 expectedSpecies = options.expectedSpecies
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
61 mlstScheme = options.mlst
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
62 tempDir = outputDir + "/shovillTemp"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
63 scriptDir = options.scriptDir
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
64 updateAbName = options.updateAbName
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
65 updateAbPath = options.updateAbPath
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
66 updateMLST = options.updateMLST
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
67 cardDB=options.cardDB
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
68 assemblyPath=options.assemblyPath
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
69 ID = options.id
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
70 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
71 manifestDir = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
72 curDir = os.getcwd()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
73 outputDir = "pipelineTest"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
74 expectedSpecies = "Escherichia coli"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
75 #threads = 8
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
76 #memory = 64
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
77 mlstScheme = outputDir + "/scheme_species_map.tab"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
78 tempDir= outputDir + "/shovillTemp"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
79 scriptDir = "~/scripts"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
80 updateAbName = "cpo"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
81 updateAbPath = "~/database/bccdcCPO.seq"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
82 updateMLST = True
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
83 assemblyPath = "./"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
84 cardDB = "./"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
85 ID = "BC11-Kpn005_S2"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
86
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
87 #region result objects
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
88 #define some objects to store values from results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
89 #//TODO this is not the proper way of get/set private object variables. every value has manually assigned defaults intead of specified in init(). Also, use property(def getVar, def setVar).
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
90 class starFinders(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
91 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
92 self.file = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
93 self.sequence = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
94 self.start = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
95 self.end = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
96 self.gene = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
97 self.shortGene = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
98 self.coverage = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
99 self.coverage_map = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
100 self.gaps = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
101 self.pCoverage = 100.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
102 self.pIdentity = 100.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
103 self.database = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
104 self.accession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
105 self.product = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
106 self.source = "chromosome"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
107 self.row = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
108
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
109 class PlasFlowResult(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
110 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
111 self.sequence = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
112 self.length = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
113 self.label = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
114 self.confidence = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
115 self.usefulRow = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
116 self.row = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
117
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
118 class MlstResult(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
119 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
120 self.file = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
121 self.speciesID = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
122 self.seqType = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
123 self.scheme = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
124 self.species = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
125 self.row=""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
126
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
127 class mobsuiteResult(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
128 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
129 self.file_id = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
130 self.cluster_id = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
131 self.contig_id = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
132 self.contig_num = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
133 self.contig_length = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
134 self.circularity_status = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
135 self.rep_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
136 self.rep_type_accession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
137 self.relaxase_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
138 self.relaxase_type_accession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
139 self.mash_nearest_neighbor = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
140 self.mash_neighbor_distance = 0.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
141 self.repetitive_dna_id = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
142 self.match_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
143 self.score = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
144 self.contig_match_start = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
145 self.contig_match_end = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
146 self.row = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
147
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
148 class mobsuitePlasmids(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
149 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
150 self.file_id = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
151 self.num_contigs = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
152 self.total_length = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
153 self.gc = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
154 self.rep_types = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
155 self.rep_typeAccession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
156 self.relaxase_type= ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
157 self.relaxase_type_accession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
158 self.mpf_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
159 self.mpf_type_accession= ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
160 self.orit_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
161 self.orit_accession = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
162 self.PredictedMobility = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
163 self.mash_nearest_neighbor = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
164 self.mash_neighbor_distance = 0.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
165 self.mash_neighbor_cluster= 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
166 self.row = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
167 class RGIResult(object):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
168 def __init__(self):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
169 self.ORF_ID = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
170 self.Contig = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
171 self.Start = -1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
172 self.Stop = -1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
173 self.Orientation = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
174 self.Cut_Off = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
175 self.Pass_Bitscore = 100000
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
176 self.Best_Hit_Bitscore = 0.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
177 self.Best_Hit_ARO = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
178 self.Best_Identities = 0.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
179 self.ARO = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
180 self.Model_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
181 self.SNPs_in_Best_Hit_ARO = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
182 self.Other_SNPs = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
183 self.Drug_Class = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
184 self.Resistance_Mechanism = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
185 self.AMR_Gene_Family = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
186 self.Predicted_DNA = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
187 self.Predicted_Protein = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
188 self.CARD_Protein_Sequence = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
189 self.Percentage_Length_of_Reference_Sequence = 0.00
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
190 self.ID = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
191 self.Model_ID = 0
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
192 self.source = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
193 self.row = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
194
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
195 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
196
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
197 #region useful functions
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
198 def read(path):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
199 return [line.rstrip('\n') for line in open(path)]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
200 def execute(command):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
201 process = subprocess.Popen(command, shell=False, cwd=curDir, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
202
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
203 # Poll process for new output until finished
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
204 while True:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
205 nextline = process.stdout.readline()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
206 if nextline == '' and process.poll() is not None:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
207 break
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
208 sys.stdout.write(nextline)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
209 sys.stdout.flush()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
210
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
211 output = process.communicate()[0]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
212 exitCode = process.returncode
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
213
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
214 if (exitCode == 0):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
215 return output
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
216 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
217 raise subprocess.CalledProcessError(exitCode, command)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
218 def httpGetFile(url, filepath=""):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
219 if (filepath == ""):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
220 return urllib.request.urlretrieve(url)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
221 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
222 urllib.request.urlretrieve(url, filepath)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
223 return True
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
224 def gunzip(inputpath="", outputpath=""):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
225 if (outputpath == ""):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
226 with gzip.open(inputpath, 'rb') as f:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
227 gzContent = f.read()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
228 return gzContent
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
229 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
230 with gzip.open(inputpath, 'rb') as f:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
231 gzContent = f.read()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
232 with open(outputpath, 'wb') as out:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
233 out.write(gzContent)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
234 return True
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
235 def ToJson(dictObject, outputPath):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
236 outDir = outputDir + '/summary/' + ID + ".json/"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
237 if not (os.path.exists(outDir)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
238 os.makedirs(outDir)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
239 with open(outDir + outputPath, 'w') as f:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
240 json.dump([ob.__dict__ for ob in dictObject.values()], f, ensure_ascii=False)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
241 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
242
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
243 #region functions to parse result files
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
244 def ParseMLSTResult(pathToMLSTResult):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
245 _mlstResult = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
246 scheme = pandas.read_csv(mlstScheme, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
247 scheme = scheme.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
248
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
249 taxon = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
250 #record the scheme as a dictionary
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
251 taxon["-"] = "No MLST Match"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
252 for i in range(len(scheme.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
253 key = scheme.iloc[i,0]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
254 if (str(scheme.iloc[i,2]) == "nan"):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
255 value = str(scheme.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
256 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
257 value = str(scheme.iloc[i,1]) + " " + str(scheme.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
258
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
259 if (key in taxon.keys()):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
260 taxon[key] = taxon.get(key) + ";" + value
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
261 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
262 taxon[key] = value
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
263 #read in the mlst result
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
264 mlst = pandas.read_csv(pathToMLSTResult, delimiter='\t', header=None)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
265 _mlstHit = MlstResult()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
266
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
267 _mlstHit.file = mlst.iloc[0,0]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
268 _mlstHit.speciesID = (mlst.iloc[0,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
269 _mlstHit.seqType = str(mlst.iloc[0,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
270 for i in range(3, len(mlst.columns)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
271 _mlstHit.scheme += mlst.iloc[0,i] + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
272 _mlstHit.species = taxon[_mlstHit.speciesID]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
273 _mlstHit.row = "\t".join(str(x) for x in mlst.ix[0].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
274 _mlstResult[_mlstHit.speciesID]=_mlstHit
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
275
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
276 return _mlstResult
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
277
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
278 def ParsePlasmidFinderResult(pathToPlasmidFinderResult):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
279 #pipelineTest/contigs/BC110-Kpn005.fa contig00019 45455 45758 IncFIC(FII)_1 8-308/499 ========/=..... 8/11 59.52 75.65 plasmidfinder AP001918 IncFIC(FII)_1__AP001918
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
280 #example resfinder:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
281 #pipelineTest/contigs/BC110-Kpn005.fa contig00038 256 1053 OXA-181 1-798/798 =============== 0/0 100.00 100.00 bccdc AEP16366.1 OXA-48 family carbapenem-hydrolyzing class D beta-lactamase OXA-181
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
282
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
283 _pFinder = {} #***********************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
284 plasmidFinder = pandas.read_csv(pathToPlasmidFinderResult, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
285 plasmidFinder = plasmidFinder.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
286
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
287
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
288 for i in range(len(plasmidFinder.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
289 pf = starFinders()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
290 pf.file = str(plasmidFinder.iloc[i,0])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
291 pf.sequence = str(plasmidFinder.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
292 pf.start = int(plasmidFinder.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
293 pf.end = int(plasmidFinder.iloc[i,3])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
294 pf.gene = str(plasmidFinder.iloc[i,4])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
295 pf.shortGene = pf.gene[:pf.gene.index("_")]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
296 pf.coverage = str(plasmidFinder.iloc[i,5])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
297 pf.coverage_map = str(plasmidFinder.iloc[i,6])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
298 pf.gaps = str(plasmidFinder.iloc[i,7])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
299 pf.pCoverage = float(plasmidFinder.iloc[i,8])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
300 pf.pIdentity = float(plasmidFinder.iloc[i,9])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
301 pf.database = str(plasmidFinder.iloc[i,10])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
302 pf.accession = str(plasmidFinder.iloc[i,11])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
303 pf.product = str(plasmidFinder.iloc[i,12])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
304 pf.source = "plasmid"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
305 pf.row = "\t".join(str(x) for x in plasmidFinder.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
306 _pFinder[pf.gene]=pf
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
307 #row = "\t".join(str(x) for x in plasmidFinder.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
308 #plasmidFinderContigs.append(str(plasmidFinder.iloc[i,1]))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
309 #origins.append(str(plasmidFinder.iloc[i,4][:plasmidFinder.iloc[i,4].index("_")]))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
310 return _pFinder
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
311
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
312 def ParseMobsuiteResult(pathToMobsuiteResult):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
313 _mobsuite = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
314 mResult = pandas.read_csv(pathToMobsuiteResult, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
315 mResult = mResult.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
316
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
317 for i in range(len(mResult.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
318 mr = mobsuiteResult()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
319 mr.file_id = str(mResult.iloc[i,0])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
320 mr.cluster_id = str(mResult.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
321 if (mr.cluster_id == "chromosome"):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
322 break
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
323 mr.contig_id = str(mResult.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
324 mr.contig_num = mr.contig_id[(mr.contig_id.find("contig")+6):mr.contig_id.find("_len=")]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
325 mr.contig_length = int(mResult.iloc[i,3])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
326 mr.circularity_status = str(mResult.iloc[i,4])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
327 mr.rep_type = str(mResult.iloc[i,5])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
328 mr.rep_type_accession = str(mResult.iloc[i,6])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
329 mr.relaxase_type = str(mResult.iloc[i,7])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
330 mr.relaxase_type_accession = str(mResult.iloc[i,8])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
331 mr.mash_nearest_neighbor = str(mResult.iloc[i,9])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
332 mr.mash_neighbor_distance = float(mResult.iloc[i,10])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
333 mr.repetitive_dna_id = str(mResult.iloc[i,11])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
334 mr.match_type = str(mResult.iloc[i,12])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
335 if (mr.match_type == ""):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
336 mr.score = -1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
337 mr.contig_match_start = -1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
338 mr.contig_match_end = -1
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
339 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
340 mr.score = int(mResult.iloc[i,13])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
341 mr.contig_match_start = int(mResult.iloc[i,14])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
342 mr.contig_match_end = int(mResult.iloc[i,15])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
343 mr.row = "\t".join(str(x) for x in mResult.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
344 _mobsuite[mr.contig_id]=(mr)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
345 return _mobsuite
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
346
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
347 def ParseMobsuitePlasmids(pathToMobsuiteResult):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
348 _mobsuite = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
349 mResults = pandas.read_csv(pathToMobsuiteResult, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
350 mResults = mResults.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
351
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
352 for i in range(len(mResults.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
353 mr = mobsuitePlasmids()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
354 mr.file_id = str(mResults.iloc[i,0])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
355 mr.num_contigs = int(mResults.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
356 mr.total_length = int(mResults.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
357 mr.gc = int(mResults.iloc[i,3])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
358 mr.rep_types = str(mResults.iloc[i,4])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
359 mr.rep_typeAccession = str(mResults.iloc[i,5])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
360 mr.relaxase_type = str(mResults.iloc[i,6])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
361 mr.relaxase_type_accession = str(mResults.iloc[i,7])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
362 mr.mpf_type = str(mResults.iloc[i,8])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
363 mr.mpf_type_accession = str(mResults.iloc[i,9])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
364 mr.orit_type = str(mResults.iloc[i,10])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
365 mr.orit_accession = str(mResults.iloc[i,11])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
366 mr.PredictedMobility = str(mResults.iloc[i,12])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
367 mr.mash_nearest_neighbor = str(mResults.iloc[i,13])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
368 mr.mash_neighbor_distance = float(mResults.iloc[i,14])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
369 mr.mash_neighbor_cluster = int(mResults.iloc[i,15])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
370 mr.row = "\t".join(str(x) for x in mResults.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
371 _mobsuite[mr.file_id] = mr
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
372 return _mobsuite
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
373
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
374 def ParseResFinderResult(pathToResFinderResults, plasmidContigs, likelyPlasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
375 _rFinder = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
376 resFinder = pandas.read_csv(pathToResFinderResults, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
377 resFinder = resFinder.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
378
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
379 for i in range(len(resFinder.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
380 rf = starFinders()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
381 rf.file = str(resFinder.iloc[i,0])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
382 rf.sequence = str(resFinder.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
383 rf.start = int(resFinder.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
384 rf.end = int(resFinder.iloc[i,3])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
385 rf.gene = str(resFinder.iloc[i,4])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
386 rf.shortGene = rf.gene
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
387 rf.coverage = str(resFinder.iloc[i,5])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
388 rf.coverage_map = str(resFinder.iloc[i,6])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
389 rf.gaps = str(resFinder.iloc[i,7])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
390 rf.pCoverage = float(resFinder.iloc[i,8])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
391 rf.pIdentity = float(resFinder.iloc[i,9])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
392 rf.database = str(resFinder.iloc[i,10])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
393 rf.accession = str(resFinder.iloc[i,11])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
394 rf.product = str(resFinder.iloc[i,12])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
395 rf.row = "\t".join(str(x) for x in resFinder.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
396 if (rf.sequence[6:] in plasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
397 rf.source = "plasmid"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
398 elif (rf.sequence[6:] in likelyPlasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
399 rf.source = "likely plasmid"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
400 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
401 rf.source = "likely chromosome"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
402 _rFinder[rf.gene]=rf
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
403 return _rFinder
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
404
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
405 def ParseRGIResult(pathToRGIResults, plasmidContigs, likelyPlasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
406 _rgiR = {}
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
407 RGI = pandas.read_csv(pathToRGIResults, delimiter='\t', header=0)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
408 RGI = RGI.replace(numpy.nan, '', regex=True)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
409
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
410 for i in range(len(RGI.index)):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
411 r = RGIResult()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
412 r.ORF_ID = str(RGI.iloc[i,0])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
413 r.Contig = str(RGI.iloc[i,1])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
414 r.Contig_Num = r.Contig[6:r.Contig.find("_")]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
415 r.Start = int(RGI.iloc[i,2])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
416 r.Stop = int(RGI.iloc[i,3])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
417 r.Orientation = str(RGI.iloc[i,4])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
418 r.Cut_Off = str(RGI.iloc[i,5])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
419 r.Pass_Bitscore = int(RGI.iloc[i,6])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
420 r.Best_Hit_Bitscore = float(RGI.iloc[i,7])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
421 r.Best_Hit_ARO = str(RGI.iloc[i,8])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
422 r.Best_Identities = float(RGI.iloc[i,9])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
423 r.ARO = int(RGI.iloc[i,10])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
424 r.Model_type = str(RGI.iloc[i,11])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
425 r.SNPs_in_Best_Hit_ARO = str(RGI.iloc[i,12])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
426 r.Other_SNPs = str(RGI.iloc[i,13])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
427 r.Drug_Class = str(RGI.iloc[i,14])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
428 r.Resistance_Mechanism = str(RGI.iloc[i,15])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
429 r.AMR_Gene_Family = str(RGI.iloc[i,16])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
430 r.Predicted_DNA = str(RGI.iloc[i,17])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
431 r.Predicted_Protein = str(RGI.iloc[i,18])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
432 r.CARD_Protein_Sequence = str(RGI.iloc[i,19])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
433 r.Percentage_Length_of_Reference_Sequence = float(RGI.iloc[i,20])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
434 r.ID = str(RGI.iloc[i,21])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
435 r.Model_ID = int(RGI.iloc[i,22])
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
436 r.row = "\t".join(str(x) for x in RGI.ix[i].tolist())
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
437 if (r.Contig_Num in plasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
438 r.source = "plasmid"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
439 elif (r.Contig_Num in likelyPlasmidContigs):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
440 r.source = "likely plasmid"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
441 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
442 r.source = "likely chromosome"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
443 _rgiR[r.Model_ID]=r
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
444 return _rgiR
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
445 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
446
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
447 def Main():
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
448 notes = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
449 #init the output list
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
450 output = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
451 jsonOutput = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
452
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
453 print(str(datetime.datetime.now()) + "\n\nID: " + ID + "\nAssembly: " + assemblyPath)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
454 output.append(str(datetime.datetime.now()) + "\n\nID: " + ID + "\nAssembly: " + assemblyPath)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
455
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
456 #region update databases if update=true
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
457 if not debug:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
458 #update databases if necessary
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
459 if not (updateAbPath == "" and updateAbName == "default"):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
460 print("updating abricate database: " + updateAbName + " @fasta path: " + updateAbPath)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
461 cmd = [scriptDir + "/pipeline_updateAbricateDB.sh", updateAbPath, updateAbName]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
462 update = execute(cmd)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
463 if (updateMLST.lower() == "true"):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
464 print("updating mlst database... ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
465 cmd = [scriptDir + "/pipeline_updateMLST.sh"]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
466 update = execute(cmd)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
467 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
468
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
469 print("step 3: parsing the mlst results")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
470
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
471 print("performing MLST")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
472 #region call the mlst script
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
473 if not debug:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
474 print("running pipeline_prediction.sh")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
475 #input parameters: 1=ID 2 = assemblyPath, 3= outputdir, 4=card.json
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
476 cmd = [scriptDir + "/pipeline_prediction.sh", ID, assemblyPath, outputDir, cardDB]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
477 result = execute(cmd)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
478 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
479
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
480 #region parse the mlst results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
481 print("step 3: parsing mlst, plasmid, and amr results")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
482
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
483 print("identifying MLST")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
484 pathToMLSTScheme = outputDir + "/predictions/" + ID + ".mlst"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
485 mlstHit = ParseMLSTResult(pathToMLSTScheme)#***********************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
486 ToJson(mlstHit, "mlst.json") #write it to a json output
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
487 mlstHit = list(mlstHit.values())[0]
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
488
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
489 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
490
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
491 #region parse mobsuite, resfinder and rgi results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
492 print("identifying plasmid contigs and amr genes")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
493
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
494 plasmidContigs = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
495 likelyPlasmidContigs = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
496 origins = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
497
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
498 #parse mobsuite results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
499 mSuite = ParseMobsuiteResult(outputDir + "/predictions/" + ID + ".recon/contig_report.txt")#*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
500 ToJson(mSuite, "mobsuite.json") #*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
501 mSuitePlasmids = ParseMobsuitePlasmids(outputDir + "/predictions/" + ID + ".recon/mobtyper_aggregate_report.txt")#*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
502 ToJson(mSuitePlasmids, "mobsuitePlasmids.json") #*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
503
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
504 for key in mSuite:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
505 if mSuite[key].contig_num not in plasmidContigs and mSuite[key].contig_num not in likelyPlasmidContigs:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
506 if not (mSuite[key].rep_type == ''):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
507 plasmidContigs.append(mSuite[key].contig_num)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
508 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
509 likelyPlasmidContigs.append(mSuite[key].contig_num)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
510 for key in mSuite:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
511 if mSuite[key].rep_type not in origins:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
512 origins.append(mSuite[key].rep_type)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
513
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
514 #parse resfinder AMR results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
515 rFinder = ParseResFinderResult(outputDir + "/predictions/" + ID + ".cp", plasmidContigs, likelyPlasmidContigs) #**********************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
516 ToJson(rFinder, "resfinder.json") #*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
517
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
518 rgiAMR = ParseRGIResult(outputDir + "/predictions/" + ID + ".rgi.txt", plasmidContigs, likelyPlasmidContigs)#***********************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
519 ToJson(rgiAMR, "rgi.json") #*************
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
520
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
521 carbapenamases = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
522 amrGenes = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
523 for keys in rFinder:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
524 carbapenamases.append(rFinder[keys].shortGene + "(" + rFinder[keys].source + ")")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
525 for keys in rgiAMR:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
526 if (rgiAMR[keys].Drug_Class.find("carbapenem") > -1):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
527 if (rgiAMR[keys].Best_Hit_ARO not in carbapenamases):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
528 carbapenamases.append(rgiAMR[keys].Best_Hit_ARO+ "(" + rgiAMR[keys].source + ")")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
529 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
530 if (rgiAMR[keys].Best_Hit_ARO not in amrGenes):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
531 amrGenes.append(rgiAMR[keys].Best_Hit_ARO+ "(" + rgiAMR[keys].source + ")")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
532 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
533
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
534 #region output parsed mlst information
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
535 print("formatting mlst outputs")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
536 output.append("\n\n\n~~~~~~~MLST summary~~~~~~~")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
537 output.append("MLST determined species: " + mlstHit.species)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
538 output.append("\nMLST Details: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
539 output.append(mlstHit.row)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
540
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
541 output.append("\nMLST information: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
542 if (mlstHit.species == expectedSpecies):
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
543 output.append("MLST determined species is the same as expected species")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
544 #notes.append("MLST determined species is the same as expected species")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
545 else:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
546 output.append("!!!MLST determined species is NOT the same as expected species, contamination? mislabeling?")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
547 notes.append("MLST: Not expected species. Possible contamination or mislabeling")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
548
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
549 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
550
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
551 #region output the parsed plasmid/amr results
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
552 output.append("\n\n\n~~~~~~~~Plasmids~~~~~~~~\n")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
553
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
554 output.append("predicted plasmid origins: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
555 output.append(";".join(origins))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
556
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
557 output.append("\ndefinitely plasmid contigs")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
558 output.append(";".join(plasmidContigs))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
559
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
560 output.append("\nlikely plasmid contigs")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
561 output.append(";".join(likelyPlasmidContigs))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
562
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
563 output.append("\nmob-suite prediction details: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
564 for key in mSuite:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
565 output.append(mSuite[key].row)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
566
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
567 output.append("\n\n\n~~~~~~~~AMR Genes~~~~~~~~\n")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
568 output.append("predicted carbapenamase Genes: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
569 output.append(",".join(carbapenamases))
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
570 output.append("other RGI AMR Genes: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
571 for key in rgiAMR:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
572 output.append(rgiAMR[key].Best_Hit_ARO + "(" + rgiAMR[key].source + ")")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
573
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
574 output.append("\nDetails about the carbapenamase Genes: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
575 for key in rFinder:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
576 output.append(rFinder[key].row)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
577 output.append("\nDetails about the RGI AMR Genes: ")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
578 for key in rgiAMR:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
579 output.append(rgiAMR[key].row)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
580
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
581 #write summary to a file
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
582 summaryDir = outputDir + "/summary/" + ID
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
583 out = open(summaryDir + ".txt", 'w')
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
584 for item in output:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
585 out.write("%s\n" % item)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
586
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
587
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
588 #TSV output
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
589 tsvOut = []
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
590 tsvOut.append("ID\tExpected Species\tMLST Species\tSequence Type\tMLST Scheme\tCarbapenem Resistance Genes\tOther AMR Genes\tTotal Plasmids\tPlasmids ID\tNum_Contigs\tPlasmid Length\tPlasmid RepType\tPlasmid Mobility\tNearest Reference\tDefinitely Plasmid Contigs\tLikely Plasmid Contigs")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
591 #start with ID
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
592 temp = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
593 temp += (ID + "\t")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
594 temp += expectedSpecies + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
595
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
596 #move into MLST
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
597 temp += mlstHit.species + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
598 temp += str(mlstHit.seqType) + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
599 temp += mlstHit.scheme + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
600
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
601 #now onto AMR genes
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
602 temp += ";".join(carbapenamases) + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
603 temp += ";".join(amrGenes) + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
604
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
605 #lastly plasmids
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
606 temp+= str(len(mSuitePlasmids)) + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
607 plasmidID = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
608 contigs = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
609 lengths = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
610 rep_type = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
611 mobility = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
612 neighbour = ""
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
613 for keys in mSuitePlasmids:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
614 plasmidID += str(mSuitePlasmids[keys].mash_neighbor_cluster) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
615 contigs += str(mSuitePlasmids[keys].num_contigs) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
616 lengths += str(mSuitePlasmids[keys].total_length) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
617 rep_type += str(mSuitePlasmids[keys].rep_types) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
618 mobility += str(mSuitePlasmids[keys].PredictedMobility) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
619 neighbour += str(mSuitePlasmids[keys].mash_nearest_neighbor) + ";"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
620 temp += plasmidID + "\t" + contigs + "\t" + lengths + "\t" + rep_type + "\t" + mobility + "\t" + neighbour + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
621 temp += ";".join(plasmidContigs) + "\t"
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
622 temp += ";".join(likelyPlasmidContigs)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
623 tsvOut.append(temp)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
624
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
625 summaryDir = outputDir + "/summary/" + ID
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
626 out = open(summaryDir + ".tsv", 'w')
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
627 for item in tsvOut:
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
628 out.write("%s\n" % item)
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
629 #endregion
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
630
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
631
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
632 start = time.time()#time the analysis
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
633 print("Starting workflow...")
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
634 #analysis time
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
635 Main()
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
636
fea89c4d5227 Uploaded
jjjjia
parents:
diff changeset
637 end = time.time()
2
29302ffdf137 planemo upload
jjjjia
parents: 1
diff changeset
638 print("Finished!\nThe analysis used: " + str(end-start) + " seconds")