comparison draw_amr_matrix.py @ 3:7d7884f2d921 draft

Uploaded
author greg
date Fri, 10 Feb 2023 20:04:31 +0000
parents 5c923c77cf5f
children 33a0ea992043
comparison
equal deleted inserted replaced
2:9fcc1ffd7526 3:7d7884f2d921
60 # TODO: So far, no samples have produced mutations, so we haven't been able 60 # TODO: So far, no samples have produced mutations, so we haven't been able
61 # to produce a populated VarScan VCF file of mutations - https://github.com/appliedbinf/pima_md/blob/main/pima.py#L2923. 61 # to produce a populated VarScan VCF file of mutations - https://github.com/appliedbinf/pima_md/blob/main/pima.py#L2923.
62 # The call_amr_mutations Galaxy tool will currently produce this VarScan VCF file, but we need a sample that 62 # The call_amr_mutations Galaxy tool will currently produce this VarScan VCF file, but we need a sample that
63 # will produce a populated file. After we find one, we'll need to figure out how to implement this loop 63 # will produce a populated file. After we find one, we'll need to figure out how to implement this loop
64 # https://github.com/appliedbinf/pima_md/blob/main/pima.py#L2925 in a Galaxy tool so that the VarScan VCF 64 # https://github.com/appliedbinf/pima_md/blob/main/pima.py#L2925 in a Galaxy tool so that the VarScan VCF
65 # file will be converted to the TSV amr_mutations_file that thsi tool expects. 65 # file will be converted to the TSV amr_mutations_file that thsi tool expects.
66 amr_mutations = pandas.DataFrame()
66 # Roll up potentially resistance conferring mutations. 67 # Roll up potentially resistance conferring mutations.
67 for mutation_region, mutation_hits in amr_mutations.iteritems(): 68 for mutation_region, mutation_hits in amr_mutations.iteritems():
68 for mutation_idx, mutation_hit in mutation_hits.iterrows(): 69 for mutation_idx, mutation_hit in mutation_hits.iterrows():
69 mutation_name = mutation_region + ' ' + mutation_hit['REF'] + '->' + mutation_hit['ALT'] 70 mutation_name = mutation_region + ' ' + mutation_hit['REF'] + '->' + mutation_hit['ALT']
70 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)) 71 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))
72 if amr_deletions_file is not None: 73 if amr_deletions_file is not None:
73 # TODO: So far, no samples have produced deletions, but we do have all the pices in place 74 # TODO: So far, no samples have produced deletions, but we do have all the pices in place
74 # within the workflow to receive the amr_deletions_file here, although it is currently 75 # within the workflow to receive the amr_deletions_file here, although it is currently
75 # always empty... 76 # always empty...
76 # Roll up deletions that might confer resistance. 77 # Roll up deletions that might confer resistance.
77 amr_deletions = pandas.read_csv(filepath_or_buffer=amr_deletions_file, sep='\t', header=None) 78 try:
79 amr_deletions = pandas.read_csv(filepath_or_buffer=amr_deletions_file, sep='\t', header=None)
80 except Exception:
81 amr_deletions = pandas.DataFrame()
78 if amr_deletions.shape[0] > 0: 82 if amr_deletions.shape[0] > 0:
79 amr_deletions.columns = ['contig', 'start', 'stop', 'name', 'type', 'drug', 'note'] 83 amr_deletions.columns = ['contig', 'start', 'stop', 'name', 'type', 'drug', 'note']
80 amr_deletions = amr_deletions.loc[amr_deletions['type'].isin(['large-deletion', 'any']), :] 84 amr_deletions = amr_deletions.loc[amr_deletions['type'].isin(['large-deletion', 'any']), :]
81 for deletion_idx, deleted_gene in amr_deletions.iterrows(): 85 for deletion_idx, deleted_gene in amr_deletions.iterrows():
82 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)) 86 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))