@@ -1300,35 +1300,66 @@ def blast_mge(contig_fasta, mge_fasta,tmp_dir, min_length, logging, min_rpp_iden
1300
1300
return results
1301
1301
1302
1302
def writeMGEresults (contig_membership ,mge_results ,outfile ):
1303
+ out_string = ["\t " .join (MGE_INFO_HEADER )]
1303
1304
if len (mge_results ) == 0 :
1304
1305
return
1305
- header = "\t " .join (["\t " .join (MGE_INFO_HEADER )])
1306
- with open (outfile ,'w' ) as out :
1307
- out .write (f'{ header } \n ' )
1308
- for molecule_type in contig_membership :
1309
- for contig_id in contig_membership [molecule_type ]:
1310
- if not contig_id in mge_results :
1311
- continue
1312
- for i in range (0 , len (mge_results [contig_id ])):
1313
- row = {}
1314
- for field in MGE_INFO_HEADER :
1315
- row [field ] = ''
1316
- if field in mge_results [contig_id ]:
1317
- row [field ] = mge_results [contig_id ][field ]
1318
-
1319
- id = mge_results [contig_id ][i ]['qseqid' ].split ('|' )
1320
- row ['mge_id' ] = id [0 ]
1321
- row ['mge_acs' ] = id [1 ]
1322
- row ['mge_type' ] = id [2 ]
1323
- row ['mge_subtype' ] = id [3 ]
1324
- row ['mge_length' ] = mge_results [contig_id ][i ]['qlen' ]
1325
- row ['mge_start' ] = mge_results [contig_id ][i ]['qstart' ]
1326
- row ['mge_end' ] = mge_results [contig_id ][i ]['qend' ]
1327
- row ['contig_start' ] = mge_results [contig_id ][i ]['sstart' ]
1328
- row ['contig_end' ] = mge_results [contig_id ][i ]['send' ]
1329
-
1330
- for field in contig_membership [molecule_type ][contig_id ]:
1331
- if field in row :
1332
- row [field ] = contig_membership [molecule_type ][contig_id ][field ]
1333
-
1334
- out .write ("{}\n " .format ("\t " .join ([str (x ) for x in list (row .values ())])))
1306
+ for contig_id in contig_membership ['chromosome' ]:
1307
+ if not contig_id in mge_results :
1308
+ continue
1309
+
1310
+ for i in range (0 , len (mge_results [contig_id ])):
1311
+ row = {}
1312
+ for field in MGE_INFO_HEADER :
1313
+ row [field ] = ''
1314
+ if field in mge_results [contig_id ]:
1315
+ row [field ] = mge_results [contig_id ][field ]
1316
+
1317
+ id = mge_results [contig_id ][i ]['qseqid' ].split ('|' )
1318
+ row ['mge_id' ] = id [0 ]
1319
+ row ['mge_acs' ] = id [1 ]
1320
+ row ['mge_type' ] = id [2 ]
1321
+ row ['mge_subtype' ] = id [3 ]
1322
+ row ['mge_length' ] = mge_results [contig_id ][i ]['qlen' ]
1323
+ row ['mge_start' ] = mge_results [contig_id ][i ]['qstart' ]
1324
+ row ['mge_end' ] = mge_results [contig_id ][i ]['qend' ]
1325
+ row ['contig_start' ] = mge_results [contig_id ][i ]['sstart' ]
1326
+ row ['contig_end' ] = mge_results [contig_id ][i ]['send' ]
1327
+
1328
+ for field in contig_membership ['chromosome' ][contig_id ]:
1329
+ if field in row :
1330
+ row [field ] = contig_membership ['chromosome' ][contig_id ][field ]
1331
+
1332
+ out_string .append ("\t " .join ([str (x ) for x in list (row .values ())]))
1333
+
1334
+ for mobcluster in contig_membership ['plasmid' ]:
1335
+ for contig_id in contig_membership ['plasmid' ][mobcluster ]:
1336
+ if not contig_id in mge_results :
1337
+ continue
1338
+
1339
+ for i in range (0 , len (mge_results [contig_id ])):
1340
+ row = {}
1341
+ for field in MGE_INFO_HEADER :
1342
+ row [field ] = ''
1343
+ if field in mge_results [contig_id ][i ]:
1344
+ row [field ] = mge_results [contig_id ][i ][field ]
1345
+ id = mge_results [contig_id ][i ]['qseqid' ].split ('|' )
1346
+ row ['mge_id' ] = id [0 ]
1347
+ row ['mge_acs' ] = id [1 ]
1348
+ row ['mge_type' ] = id [2 ]
1349
+ row ['mge_subtype' ] = id [3 ]
1350
+ row ['mge_length' ] = mge_results [contig_id ][i ]['qlen' ]
1351
+ row ['mge_start' ] = mge_results [contig_id ][i ]['qstart' ]
1352
+ row ['mge_end' ] = mge_results [contig_id ][i ]['qend' ]
1353
+ row ['contig_start' ] = mge_results [contig_id ][i ]['sstart' ]
1354
+ row ['contig_end' ] = mge_results [contig_id ][i ]['send' ]
1355
+
1356
+ for field in contig_membership ['plasmid' ][mobcluster ][contig_id ]:
1357
+ if field in row :
1358
+ row [field ] = contig_membership ['plasmid' ][mobcluster ][contig_id ][field ]
1359
+
1360
+ out_string .append ("\t " .join ([str (x ) for x in list (row .values ())]))
1361
+
1362
+
1363
+ fh = open (outfile ,'w' )
1364
+ fh .write ("\n " .join (out_string ))
1365
+ fh .close ()
0 commit comments