@@ -17,43 +17,40 @@ def mges_stats(bacannot_summary):
1717
1818 # init MGE annotation dictionary
1919 bacannot_summary [sample ]['MGE' ] = {}
20-
21- # load annotation stats
22- if os .path .exists (f"{ results_dir } /integron_finder" ):
2320
24- # integron_finder
25- if os .path .exists (f"{ results_dir } /integron_finder/{ sample } _integrons.gff" ):
26-
27- # init integron_finder annotation dictionary
28- bacannot_summary [sample ]['MGE' ]['integron_finder' ] = {}
29-
30- # load integron_finder results
31- results = pd .read_csv (
32- f"{ results_dir } /integron_finder/{ sample } _integrons.gff" ,
33- sep = '\t ' ,
34- header = None ,
35- names = [
36- 'chr' , 'source' , 'type' , 'start' , 'end' , 'score' , 'strand' , 'frame' , 'atts'
37- ]
38- )
39-
40- # number of integron_finder annotations
41- total_number = len (results .index )
42- bacannot_summary [sample ]['MGE' ]['integron_finder' ]['total' ] = total_number
43-
44- # per integron info
45- bacannot_summary [sample ]['MGE' ]['integron_finder' ] = {}
46- if int (results .shape [0 ]) > 0 :
47- for seq in [ str (x ) for x in results ['chr' ].unique () ]:
48-
49- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ] = {}
50- for index , row in results [results ['chr' ] == seq ].reset_index ().iterrows ():
51- id = row ['atts' ].split (';' )[0 ].split ('=' )[- 1 ]
52- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ] = {}
53- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['id' ] = id
54- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['contig' ] = row ['chr' ]
55- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['start' ] = row ['start' ]
56- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['end' ] = row ['end' ]
57- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['type' ] = row ['atts' ].split (';' )[1 ].split ('=' )[- 1 ]
58- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['source' ] = row ['source' ]
59- bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['product' ] = row ['type' ]
21+ # integron_finder
22+ if os .path .exists (f"{ results_dir } /integron_finder/{ sample } _integrons.gff" ):
23+
24+ # init integron_finder annotation dictionary
25+ bacannot_summary [sample ]['MGE' ]['integron_finder' ] = {}
26+
27+ # load integron_finder results
28+ results = pd .read_csv (
29+ f"{ results_dir } /integron_finder/{ sample } _integrons.gff" ,
30+ sep = '\t ' ,
31+ header = None ,
32+ names = [
33+ 'chr' , 'source' , 'type' , 'start' , 'end' , 'score' , 'strand' , 'frame' , 'atts'
34+ ]
35+ )
36+
37+ # number of integron_finder annotations
38+ total_number = len (results .index )
39+ bacannot_summary [sample ]['MGE' ]['integron_finder' ]['total' ] = total_number
40+
41+ # per integron info
42+ bacannot_summary [sample ]['MGE' ]['integron_finder' ] = {}
43+ if int (results .shape [0 ]) > 0 :
44+ for seq in [ str (x ) for x in results ['chr' ].unique () ]:
45+
46+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ] = {}
47+ for index , row in results [results ['chr' ] == seq ].reset_index ().iterrows ():
48+ id = row ['atts' ].split (';' )[0 ].split ('=' )[- 1 ]
49+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ] = {}
50+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['id' ] = id
51+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['contig' ] = row ['chr' ]
52+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['start' ] = row ['start' ]
53+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['end' ] = row ['end' ]
54+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['type' ] = row ['atts' ].split (';' )[1 ].split ('=' )[- 1 ]
55+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['source' ] = row ['source' ]
56+ bacannot_summary [sample ]['MGE' ]['integron_finder' ][seq ][id ]['product' ] = row ['type' ]
0 commit comments