def create_fake_record(): """Set up a fake sequence record""" seq_record = helpers.DummyRecord( seq=Seq("acgtacgtacgtacgtacgtacgtacgtacgtacgtacgtacgtacgta" * 196)) seq_record.name = "test" locations = [ FeatureLocation(100, 300, strand=1), FeatureLocation(101, 299, strand=-1), FeatureLocation(250, 350, strand=1), FeatureLocation(500, 1000, strand=1), FeatureLocation(1111, 1500, strand=-1), FeatureLocation(2000, 2200, strand=-1), FeatureLocation(2999, 4000, strand=1), FeatureLocation(4321, 5678, strand=1), FeatureLocation(6660, 9000, strand=-1) ] for i in range(9): cds = helpers.DummyCDS(locus_tag="gene" + str(i + 1)) cds.location = locations[i] seq_record.add_cds_feature(cds) seq_record.add_gene( secmet.Gene(locations[i], locus_tag="gene" + str(i + 1))) if i == 3 or i == 5: cds.gene_functions.add(secmet.qualifiers.GeneFunction.CORE, "testtool", "dummy", "product") return seq_record
def test_classification_with_colon(self): # since SMCOG id and description are stored in a string separated by :, # ensure that descriptions containing : are properly handled # test gene is AQF52_5530 from CP013129.1 translation = ( "MDTHQREEDPVAARRDRTHYLYLAVIGAVLLGIAVGFLAPGVAVELKPLGTGFVN" "LIKMMISPIIFCTIVLGVGSVRKAAKVGAVGGLALGYFLVMSTVALAIGLLVGNL" "LEPGSGLHLTKEIAEAGAKQAEGGGESTPDFLLGIIPTTFVSAFTEGEVLQTLLV" "ALLAGFALQAMGAAGEPVLRGIGHIQRLVFRILGMIMWVAPVGAFGAIAAVVGAT" "GAAALKSLAVIMIGFYLTCGLFVFVVLGAVLRLVAGINIWTLLRYLGREFLLILS" "TSSSESALPRLIAKMEHLGVSKPVVGITVPTGYSFNLDGTAIYLTMASLFVAEAM" "GDPLSIGEQISLLVFMIIASKGAAGVTGAGLATLAGGLQSHRPELVDGVGLIVGI" "DRFMSEARALTNFAGNAVATVLVGTWTKEIDKARVTEVLAGNIPFDEKTLVDDHA" "PVPVPDQRAEGGEEKARAGV") cds = helpers.DummyCDS(0, len(translation)) cds.translation = translation results = smcogs.classify("test", [cds], get_config()) assert results.best_hits[cds.get_name( )].hit_id == "SMCOG1212:sodium:dicarboxylate symporter" record = helpers.DummyRecord(seq=translation) record.add_cds_feature(cds) record.add_protocluster(helpers.DummyProtocluster(0, len(translation))) # if we don't handle multiple semicolons right, this line will crash results.add_to_record(record) gene_functions = cds.gene_functions.get_by_tool("smcogs") assert len(gene_functions) == 1 assert str(gene_functions[0]).startswith( "transport (smcogs) SMCOG1212:sodium:dicarboxylate symporter" " (Score: 416; E-value: 2.3e-126)")
def test_cds_motifs(self): record = helpers.DummyRecord() non_as_motif = DummyCDSMotif() non_as_motif.created_by_antismash = False record.add_cds_motif(non_as_motif) as_motif = DummyCDSMotif() as_motif.created_by_antismash = True record.add_cds_motif(as_motif) record_processing.strip_record(record) assert record.get_cds_motifs() == (non_as_motif, )
def test_classification_with_colon(self): # since SMCOG id and description are stored in a string separated by :, # ensure that descriptions containing : are properly handled cds = helpers.DummyCDS(locus_tag="test") record = helpers.DummyRecord(features=[cds], seq="A" * 100) record.add_cluster(helpers.DummyCluster(0, 100)) results = SMCOGResults(record.id) results.best_hits[cds.get_name()] = HMMResult( "SMCOG1212:sodium:dicarboxylate_symporter", 0, 100, 2.3e-126, 416) results.add_to_record(record) gene_functions = cds.gene_functions.get_by_tool("smcogs") assert len(gene_functions) == 1 assert str(gene_functions[0]).startswith( "transport (smcogs) SMCOG1212:sodium:dicarboxylate_symporter" " (Score: 416; E-value: 2.3e-126)")
def test_add_when_regenerating(self): record = helpers.DummyRecord(seq="A"*3800) record.id = 'Y16952.3.trimmed' record.add_cds_feature(helpers.DummyCDS(start=0, end=1800, locus_tag="two_domains")) record.add_cds_feature(helpers.DummyCDS(start=1900, end=4000, locus_tag="one_domain")) record.add_cds_feature(helpers.DummyCDS(start=4100, end=4400, locus_tag="no_hits")) two_domain_json = {'domain_hmms': [{'bitscore': 360.7, 'query_end': 428, 'evalue': 2.1e-110, 'hit_id': 'AMP-binding', 'query_start': 35}, {'bitscore': 66.0, 'query_end': 569, 'evalue': 6.3e-21, 'hit_id': 'PCP', 'query_start': 504}], 'motif_hmms': [], 'type': 'NRPS'} one_domain_json = {'domain_hmms': [{'bitscore': 76.9, 'query_end': 382, 'evalue': 3.9e-24, 'hit_id': 'ECH', 'query_start': 170}], 'motif_hmms': [{'query_start': 18, 'evalue': 4.7e-05, 'query_end': 30, 'bitscore': 16.1, 'hit_id': 'C1_dual_004-017'}, {'query_start': 38, 'evalue': 1.4e-19, 'query_end': 78, 'bitscore': 62.4, 'hit_id': 'C2_DCL_024-062'}], 'type': 'other'} json = {'cds_results': {'two_domains': two_domain_json, 'one_domain': one_domain_json}, 'record_id': record.id, 'schema_version': 1} assert not record.get_antismash_domains() assert not record.get_cds_motifs() results = nrps_pks_domains.domain_identification.NRPSPKSDomains.from_json(json, record) assert len(results.cds_results) == 2 assert len(record.get_cds_motifs()) == 2 assert len(record.get_antismash_domains()) == 3 two_domains = record.get_cds_by_name("two_domains") assert two_domains.nrps_pks.type == "NRPS" assert len(two_domains.nrps_pks.domains) == 2 assert not two_domains.motifs one_domain = record.get_cds_by_name("one_domain") assert one_domain.nrps_pks.type == "other" assert len(one_domain.nrps_pks.domains) == 1 assert len(one_domain.motifs) == 2 no_hits = record.get_cds_by_name("no_hits") assert not no_hits.nrps_pks
def test_cds_motifs(self): record = helpers.DummyRecord() non_as_motif = DummyFeature(feature_type="CDS_motif") non_as_motif._qualifiers["stuff"] = ["thing"] record.add_feature(non_as_motif) as_motif = DummyCDSMotif(domain_id="as") as_motif.created_by_antismash = True record.add_cds_motif(as_motif) bio = record.to_biopython() assert len(bio.features) == 2 assert set(feat.type for feat in bio.features) == {"CDS_motif"} assert record_processing.strip_record(bio) is bio # strips and returns assert len(bio.features) == 1 record = Record.from_biopython(bio, taxon="bacteria") motifs = record.get_cds_motifs() assert len(motifs) == 1 assert motifs[0].domain_id.startswith("non_aS_motif")
def test_add_when_regenerating(self): record = helpers.DummyRecord(seq="A" * 3800) record.id = 'Y16952.3.trimmed' record.add_cds_feature( helpers.DummyCDS(start=0, end=1800, locus_tag="two_domains")) record.add_cds_feature( helpers.DummyCDS(start=1900, end=4000, locus_tag="one_domain")) record.add_cds_feature( helpers.DummyCDS(start=4100, end=4400, locus_tag="no_hits")) a_domain = { 'bitscore': 360.7, 'query_end': 428, 'evalue': 2.1e-110, 'hit_id': 'AMP-binding', 'query_start': 35 } pcp = { 'bitscore': 66.0, 'query_end': 569, 'evalue': 6.3e-21, 'hit_id': 'PCP', 'query_start': 504 } two_domain_json = { 'domain_hmms': [a_domain, pcp], 'motif_hmms': [], 'modules': [{ "components": [ { "domain": a_domain }, { "domain": pcp }, ] }], "ks_subtypes": [], 'type': 'NRPS' } one_domain_json = { 'domain_hmms': [{ 'bitscore': 76.9, 'query_end': 382, 'evalue': 3.9e-24, 'hit_id': 'ECH', 'query_start': 170 }], 'motif_hmms': [{ 'query_start': 18, 'evalue': 4.7e-05, 'query_end': 30, 'bitscore': 16.1, 'hit_id': 'C1_dual_004-017' }, { 'query_start': 38, 'evalue': 1.4e-19, 'query_end': 78, 'bitscore': 62.4, 'hit_id': 'C2_DCL_024-062' }], "modules": [], # arbitrarily none "ks_subtypes": [], 'type': 'other' } json = { 'cds_results': { 'two_domains': two_domain_json, 'one_domain': one_domain_json }, 'record_id': record.id, 'modules': [], 'schema_version': nrps_pks_domains.domain_identification.NRPSPKSDomains. schema_version } assert not record.get_antismash_domains() assert not record.get_cds_motifs() results = nrps_pks_domains.domain_identification.NRPSPKSDomains.from_json( json, record) assert len(results.cds_results) == 2 assert len(record.get_cds_motifs()) == 2 assert len(record.get_antismash_domains()) == 3 assert len( record.get_antismash_domains_by_tool("nrps_pks_domains")) == 3 two_domains = record.get_cds_by_name("two_domains") assert two_domains.nrps_pks.type == "NRPS" assert len(two_domains.nrps_pks.domains) == 2 assert not two_domains.motifs modules = results.cds_results[two_domains].modules assert modules assert modules[0]._loader._domain.hit_id == "AMP-binding" assert modules[0]._carrier_protein._domain.hit_id == "PCP" assert not two_domains.modules # added in add_to_record one_domain = record.get_cds_by_name("one_domain") assert one_domain.nrps_pks.type == "other" assert len(one_domain.nrps_pks.domains) == 1 assert len(one_domain.motifs) == 2 assert not results.cds_results[one_domain].modules assert not one_domain.modules no_hits = record.get_cds_by_name("no_hits") assert not no_hits.nrps_pks
def setUp(self): self.record = helpers.DummyRecord(seq=Seq("ACGT" * 25))