Skip to content

Commit

Permalink
Adding tests, switching some things to pd.NA.
Browse files Browse the repository at this point in the history
  • Loading branch information
emarinier committed Aug 17, 2023
1 parent c5d11f8 commit 5585aa2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_matches(self, results_table, hit):
result = [hit.get_genome_id(),
", ".join(intersection), # Technically these are also Pointfinder co-ords
row.phenotype,
None, # CGE-predicted phenotype
pd.NA, # CGE-predicted phenotype
"complex", # Type
", ".join(mutation_positions),
"complex", # Creating a mutation string would be confusing for this.
Expand All @@ -65,7 +65,10 @@ def get_matches(self, results_table, hit):
hit.get_genome_contig_start(),
hit.get_genome_contig_end(),
", ".join(intersection),
"This mutation represents a combination of multiple individual mutations."] # The notes.
"This mutation represents a combination of multiple individual mutations.", # The notes.
pd.NA,
pd.NA,
pd.NA]

matches.append(result)

Expand Down
60 changes: 54 additions & 6 deletions staramr/tests/integration/detection/test_AMRDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ def testPointfinderSalmonellaA67PSuccess(self):
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid,Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE Notes'].iloc[0], '', msg='The notes do not match.') # empty string (no notes)
self.assertEqual(result['CGE PMID'].iloc[0], '7492118', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], 'gyrA_G81C.S.H.D', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-A67P.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -503,6 +506,9 @@ def testPointfinderSalmonellaS83ISuccess(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ciprofloxacin I/R, nalidixic acid',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid,Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '7492118;10471553', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], 'gyrA_D87K', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-S83I.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -573,6 +579,9 @@ def testPointfinderSalmonellaA67PDelEndSuccess(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ciprofloxacin I/R, nalidixic acid',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid,Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '7492118', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], 'gyrA_G81C.S.H.D', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-A67P-del-end.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -666,6 +675,9 @@ def testPointfinderSalmonellaA67PReverseComplementSuccess(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ciprofloxacin I/R, nalidixic acid',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid,Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '7492118', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], 'gyrA_G81C.S.H.D', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-A67P-rc.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -707,6 +719,9 @@ def testPointfinderSalmonella_16S_rrSD_C1065T_Success(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'spectinomycin',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Spectinomycin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '12402084', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_16S_rrsD-1T1065.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -754,10 +769,13 @@ def testPointfinderEnterococcusFaecium_pbp5_Success(self):
self.assertEqual(result['CGE Notes'].iloc[0],
'The nineteen pbp5 mutations must be present simultaneously for resistance phenotype',
msg='The notes do not match.')

self.assertEqual(result['CGE PMID'].iloc[0], '25182648', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

# Test the complex mutation:
result = pointfinder_results[pointfinder_results['Gene'] == 'pbp5 (A216S), pbp5 (A499T), pbp5 (A68T), pbp5 (D204G), pbp5 (E100Q), pbp5 (E525D), pbp5 (E629V), pbp5 (E85D), pbp5 (G66E), pbp5 (K144Q), pbp5 (L177I), pbp5 (M485A), pbp5 (N496K), pbp5 (P667S), pbp5 (R34Q), pbp5 (S27G), pbp5 (T172A), pbp5 (T324A), pbp5 (V24A), pbp5 (V586L)']
print(result.iloc[0].values.tolist())

self.assertEqual(len(result.index), 1, 'Wrong number of results detected')
self.assertEqual(result.index[0], 'pbp5_20', msg='Wrong file')
self.assertEqual(result['Type'].iloc[0], 'complex', msg='Wrong type')
Expand All @@ -767,10 +785,13 @@ def testPointfinderEnterococcusFaecium_pbp5_Success(self):
self.assertAlmostEqual(result['%Overlap'].iloc[0], 100.00, places=2, msg='Wrong overlap')
self.assertEqual(result['HSP Length/Total Length'].iloc[0], '2037/2037', msg='Wrong lengths')
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ampicillin', 'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], None, 'Wrong phenotype')
self.assertTrue(pd.isna(result['CGE Predicted Phenotype'].iloc[0]), 'Wrong phenotype')
self.assertEqual(result['CGE Notes'].iloc[0],
'This mutation represents a combination of multiple individual mutations.',
msg='The notes do not match.') # empty string (no notes)
self.assertTrue(pd.isna(result['CGE PMID'].iloc[0]), msg='The PMIDs do not match.')
self.assertTrue(pd.isna(result['CGE Mechanism'].iloc[0]), msg='The mechanisms do not match.')
self.assertTrue(pd.isna(result['CGE Required Mutation'].iloc[0]), msg='The required mutation(s) do not match.')

def testPointfinderEnterococcusFaecium_pbp5_Failure(self):
# This test evaluates the correctness of NOT identifying a pbp5 complex mutation.
Expand Down Expand Up @@ -806,7 +827,10 @@ def testPointfinderEnterococcusFaecium_pbp5_Failure(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'unknown[pbp5 (A216S)]',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Ampicillin', 'Wrong phenotype')

self.assertEqual(result['CGE PMID'].iloc[0], '25182648', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

# Test correct numbers of complex- and codon-type mutations:
self.assertEqual(len(pointfinder_results[pointfinder_results['Type'] == 'codon']), 19, 'Wrong number of codon mutations')
self.assertEqual(len(pointfinder_results[pointfinder_results['Type'] == 'complex']), 0, 'Wrong number of complex mutations')
Expand Down Expand Up @@ -847,6 +871,9 @@ def testPointfinderEnterococcusFaecium_pbp5_3_m485a_Success(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'unknown[pbp5 (E629V)]',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Ampicillin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '25182648', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

# Test the complex mutation:
result = pointfinder_results[pointfinder_results['Gene'] == 'pbp5 (E629V), pbp5 (M485A), pbp5 (P667S)']
Expand All @@ -860,7 +887,10 @@ def testPointfinderEnterococcusFaecium_pbp5_3_m485a_Success(self):
self.assertEqual(result['HSP Length/Total Length'].iloc[0], '2037/2037', msg='Wrong lengths')
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ampicillin',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], None, 'Wrong phenotype')
self.assertTrue(pd.isna(result['CGE Predicted Phenotype'].iloc[0]), 'Wrong phenotype')
self.assertTrue(pd.isna(result['CGE PMID'].iloc[0]), msg='The PMIDs do not match.')
self.assertTrue(pd.isna(result['CGE Mechanism'].iloc[0]), msg='The mechanisms do not match.')
self.assertTrue(pd.isna(result['CGE Required Mutation'].iloc[0]), msg='The required mutation(s) do not match.')

def testPointfinderEnterococcusFaecium_pbp5_3_m485t_Success(self):
# This test evaluates the correctness of identifying a pbp5 complex mutation
Expand Down Expand Up @@ -898,6 +928,9 @@ def testPointfinderEnterococcusFaecium_pbp5_3_m485t_Success(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'unknown[pbp5 (E629V)]',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Ampicillin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '25182648', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

# Test the complex mutation:
result = pointfinder_results[pointfinder_results['Gene'] == 'pbp5 (E629V), pbp5 (M485T), pbp5 (P667S)']
Expand All @@ -911,7 +944,10 @@ def testPointfinderEnterococcusFaecium_pbp5_3_m485t_Success(self):
self.assertEqual(result['HSP Length/Total Length'].iloc[0], '2037/2037', msg='Wrong lengths')
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ampicillin',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], None, 'Wrong phenotype')
self.assertTrue(pd.isna(result['CGE Predicted Phenotype'].iloc[0]), 'Wrong phenotype')
self.assertTrue(pd.isna(result['CGE PMID'].iloc[0]), msg='The PMIDs do not match.')
self.assertTrue(pd.isna(result['CGE Mechanism'].iloc[0]), msg='The mechanisms do not match.')
self.assertTrue(pd.isna(result['CGE Required Mutation'].iloc[0]), msg='The required mutation(s) do not match.')

def testResfinderPointfinderSalmonella_16S_C1065T_gyrA_A67_beta_lactam_Success(self):
pointfinder_database = PointfinderBlastDatabase(self.pointfinder_dir, 'salmonella')
Expand Down Expand Up @@ -1061,6 +1097,9 @@ def testResfinderPointfinderSalmonella_16Src_C1065T_gyrArc_A67_beta_lactam_Succe
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'spectinomycin',
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Spectinomycin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '12402084', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

result = pointfinder_results[pointfinder_results['Gene'] == 'gyrA (A67P)']
self.assertEqual(len(result.index), 1, 'Wrong number of results detected')
Expand Down Expand Up @@ -1179,6 +1218,9 @@ def testPointfinderCampylobacterA70TSuccess(self):
self.assertEqual(result['HSP Length/Total Length'].iloc[0], '2592/2592', msg='Wrong lengths')
self.assertEqual(result['Predicted Phenotype'].iloc[0], 'ciprofloxacin, nalidixic acid', 'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid, Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '8384814', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-A70T.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -1216,6 +1258,9 @@ def testPointfinderCampylobacterA2075GSuccess(self):
self.assertEqual(result['Predicted Phenotype'].iloc[0],
'erythromycin, azithromycin, telithromycin, clindamycin', 'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Azithromycin, Erythromycin, Clindamycin, Telithromycin', 'Wrong phenotype')
self.assertEqual(result['CGE PMID'].iloc[0], '16713726', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], '', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_23S-A2075G.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down Expand Up @@ -1658,6 +1703,9 @@ def testPointfinderEcoliD87NSuccess(self):
'Wrong phenotype')
self.assertEqual(result['CGE Predicted Phenotype'].iloc[0], 'Nalidixic acid;Nalidixic acid,Ciprofloxacin', 'Wrong phenotype')
self.assertEqual(result['CGE Notes'].iloc[0], 'D87G or D87Y confer resistance to nalidixic acid only, if occurring alone. Unknown phenotype if D87H occurs alone;D87G or D87Y confer resistance to nalidixic acid only, if occurring alone. Unknown phenotype if D87H occurs alone', msg='The notes do not match.')
self.assertEqual(result['CGE PMID'].iloc[0], '12654733,12654733,12654733,22878251,12654733,1850972;12654733,12654733,12654733,22878251,12654733,1850972', msg='The PMIDs do not match.')
self.assertEqual(result['CGE Mechanism'].iloc[0], 'Target modification;Target modification', msg='The mechanisms do not match.')
self.assertEqual(result['CGE Required Mutation'].iloc[0], ';gyrA_S83L.W.A.V', msg='The required mutation(s) do not match.')

hit_file = path.join(self.outdir.name, 'pointfinder_gyrA-D87N.fsa')
records = SeqIO.to_dict(SeqIO.parse(hit_file, 'fasta'))
Expand Down

0 comments on commit 5585aa2

Please sign in to comment.