changeset 6:caf554e039b2 draft

Uploaded
author greg
date Wed, 22 Feb 2023 21:23:25 +0000
parents 46d31ec5d24c
children 389c98d344ce
files draw_amr_matrix.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/draw_amr_matrix.py	Tue Feb 21 20:36:37 2023 +0000
+++ b/draw_amr_matrix.py	Wed Feb 22 21:23:25 2023 +0000
@@ -133,7 +133,14 @@
                         os.mkdir(region_dir)
                         region_bed = os.path.join(region_dir, 'region.bed')
                         mutation_regions.loc[[region_i], ].to_csv(path_or_buf=region_bed, sep='\t', header=False, index=False)
-                        cmd = "bedtools intersect -nonamecheck -wb -a '%s' -b '%s' | awk '{BEGIN{getline < \"%s\" ;printf $0\"\t\";getline < \"%s\"; getline < \"%s\";print $0}{print}' > %s" % (region_bed, amr_mutations_file, amr_mutation_regions_file, amr_mutations_file, amr_mutations_file, region_mutations_output_file)
+                        cmd = ' '.join(['bedtools intersect -nonamecheck -wb -a',
+                                        region_bed,
+                                        '-b',
+                                        amr_mutations_file,
+                                        ' | awk \'BEGIN{getline < "' + amr_mutation_regions_file + '";printf $0"\\t";',
+                                        'getline < "' + amr_mutations_file + '"; getline < "' + amr_mutations_file + '";print $0}{print}\'',
+                                        '1>' + region_mutations_output_file])
+                        ofh.write("\ncmd:\n%s\n" % cmd)
                         run_command(cmd)
                         try:
                             region_mutations = pandas.read_csv(region_mutations_output_file, sep='\t', header=0, index_col=False)
@@ -158,9 +165,6 @@
                     amr_to_draw = amr_to_draw.append(pandas.Series([mutation_name, mutation_hit['DRUG']], name=amr_to_draw.shape[0], index=amr_to_draw.columns))
 
         if amr_deletions_file not in [None, 'None'] and os.path.getsize(amr_deletions_file) > 0:
-            # TODO: So far, no samples have produced deletions, but we do have all the pices in place
-            # within the workflow to receive the amr_deletions_file here, although it is currently
-            # always empty...
             # Roll up deletions that might confer resistance.
             try:
                 amr_deletions = pandas.read_csv(filepath_or_buffer=amr_deletions_file, sep='\t', header=None)
@@ -182,6 +186,7 @@
             amr_matrix_png = os.path.join(output_dir, 'amr_matrix.png')
             int_matrix = amr_matrix[amr_matrix.columns].astype(int)
             figure, axis = pyplot.subplots()
+            heatmap = axis.pcolor(int_matrix, cmap=pyplot.cm.Blues, linewidth=0)
             axis.invert_yaxis()
             axis.set_yticks(numpy.arange(0.5, len(amr_matrix.index)), minor=False)
             axis.set_yticklabels(int_matrix.index.values)