Mercurial > repos > greg > draw_amr_matrix
comparison draw_amr_matrix.py @ 15:487a3c008812 draft
Uploaded
author | greg |
---|---|
date | Mon, 01 May 2023 17:52:05 +0000 |
parents | c5e80637cf3d |
children | 7bd48449ee79 |
comparison
equal
deleted
inserted
replaced
14:c5e80637cf3d | 15:487a3c008812 |
---|---|
56 def stop_err(msg): | 56 def stop_err(msg): |
57 sys.stderr.write(msg) | 57 sys.stderr.write(msg) |
58 sys.exit(1) | 58 sys.exit(1) |
59 | 59 |
60 | 60 |
61 def draw_amr_matrix(amr_feature_hits_files, amr_deletions_file, varscan_vcf_file, amr_mutation_regions_bed_file, amr_gene_drug_file, reference, reference_size, mutation_regions_dir, amr_matrix_png_dir, errors, in_test_mode): | 61 def draw_amr_matrix(amr_feature_hits_files, amr_deletions_file, varscan_vcf_file, amr_mutation_regions_bed_file, amr_gene_drug_file, reference, reference_size, mutation_regions_dir, amr_matrix_png_dir, errors): |
62 efh = open(errors, 'w') | 62 efh = open(errors, 'w') |
63 ofh = open('process_log', 'w') | 63 ofh = open('process_log', 'w') |
64 | 64 |
65 # Read amr_feature_hits_files. | 65 # Read amr_feature_hits_files. |
66 amr_feature_hits = pandas.Series(dtype=object) | 66 amr_feature_hits = pandas.Series(dtype=object) |
190 for deletion_idx, deleted_gene in amr_deletions.iterrows(): | 190 for deletion_idx, deleted_gene in amr_deletions.iterrows(): |
191 amr_to_draw = amr_to_draw.append(pandas.Series(['\u0394' + deleted_gene[3], deleted_gene[5]], name=amr_to_draw.shape[0], index=amr_to_draw.columns)) | 191 amr_to_draw = amr_to_draw.append(pandas.Series(['\u0394' + deleted_gene[3], deleted_gene[5]], name=amr_to_draw.shape[0], index=amr_to_draw.columns)) |
192 ofh.write("\nAfter processing deletions, amr_to_draw: %s\n" % str(amr_to_draw)) | 192 ofh.write("\nAfter processing deletions, amr_to_draw: %s\n" % str(amr_to_draw)) |
193 | 193 |
194 ofh.write("\namr_to_draw.shape[0]: %s\n" % str(amr_to_draw.shape[0])) | 194 ofh.write("\namr_to_draw.shape[0]: %s\n" % str(amr_to_draw.shape[0])) |
195 # I have no idea why, but when running functional test with planemo | 195 # I have no idea why, but when running functional tests with planemo |
196 # the value of amr_to_draw.shape[0] is 1 even though the tests use the | 196 # the value of amr_to_draw.shape[0] is 1 even though the tests use the |
197 # exact inputs when running outside of planeo that result in the value | 197 # exact inputs when running outside of planeo that result in the value |
198 # being 2. So we have to pass this in_test_mode flag in order to get | 198 # being 2. So we cannot test with planemo unless we incorporate a hack |
199 # functional tests to work. | 199 # like a hidden in_test_mode parameter. |
200 if in_test_mode == 'true': | 200 if amr_to_draw.shape[0] > 1: |
201 shape_val = 0 | |
202 else: | |
203 shape_val = 1 | |
204 if amr_to_draw.shape[0] > shape_val: | |
205 ofh.write("\nDrawing AMR matrix...\n") | 201 ofh.write("\nDrawing AMR matrix...\n") |
206 present_genes = amr_to_draw['gene'].unique() | 202 present_genes = amr_to_draw['gene'].unique() |
207 present_drugs = amr_to_draw['drug'].unique() | 203 present_drugs = amr_to_draw['drug'].unique() |
208 amr_matrix = pandas.DataFrame(0, index=present_genes, columns=present_drugs) | 204 amr_matrix = pandas.DataFrame(0, index=present_genes, columns=present_drugs) |
209 for hit_idx, hit in amr_to_draw.iterrows(): | 205 for hit_idx, hit in amr_to_draw.iterrows(): |