def test_genome_to_seqrecord_2(self): """Verify that genome_to_seqrecord can correctly populate seqrecord annotations""" self.gnm.seq = Seq("ATA") self.gnm.date = "2019" self.gnm.accession = "gnm12345" self.gnm.host_genus = "Mycobacterium" self.gnm.id = "Trixie" self.gnm.cluster = "A" self.gnm.subcluster = "A2" self.gnm.annotation_status = "1" self.gnm.annotation_author = 1 self.gnm.retrieve_record = 1 record = flat_files.genome_to_seqrecord(self.gnm) record_comments = record.annotations["comment"] exp_source = "Mycobacterium phage Trixie" exp_comment0 = "Cluster: A; Subcluster: A2" exp_comment2 = "Annotation Status: 1; Annotation Author: 1" exp_comment3 = "RetrieveRecord: 1" with self.subTest(): self.assertEqual(record.annotations["date"], "2019") with self.subTest(): self.assertEqual(record.annotations["source"], exp_source) with self.subTest(): self.assertEqual(record_comments[0], exp_comment0) with self.subTest(): self.assertEqual(record_comments[2], exp_comment2) with self.subTest(): self.assertEqual(record_comments[3], exp_comment3)
def get_genome_seqrecords(alchemist, values=[], verbose=False): genomes = mysqldb.parse_genome_data(alchemist.engine, phage_id_list=values, phage_query=PHAGE_QUERY, gene_query=GENE_QUERY) seqrecords = [] for gnm in genomes: process_cds_features(gnm) if verbose: print(f"Converting {gnm.name}...") seqrecords.append(flat_files.genome_to_seqrecord(gnm)) return seqrecords
def get_genome_seqrecords(alchemist, values, data_cache=None, verbose=False): if data_cache is None: data_cache = {} seqrecords = [] for genome_id in values: genome = data_cache.get(genome_id) if genome is None: genome = get_single_genome(alchemist, genome_id, get_features=True, data_cache=data_cache) seqrecord = flat_files.genome_to_seqrecord(genome) flat_files.sort_seqrecord_features(seqrecord) seqrecords.append(seqrecord) return seqrecords
def build_id_record_map(alchemist, phageids): id_record_map = {} if not phageids: return id_record_map genomes = mysqldb.parse_genome_data(alchemist.engine, phage_id_list=phageids, phage_query=PHAGE_QUERY, gene_query=GENE_QUERY, trna_query=TRNA_QUERY, tmrna_query=TMRNA_QUERY) for genome in genomes: record = flat_files.genome_to_seqrecord(genome) id_record_map[record.id] = record return id_record_map
def test_genome_to_seqrecord_1(self): """Verify that genome_to_seqrecord can initialize a SeqRecord given the basic conditions""" self.gnm.seq = Seq("ATA") self.gnm.name = "Trixie" self.gnm.id = "Trixie" self.gnm.cds_features = [] self.gnm.host_genus = "Mycobacterium" record = flat_files.genome_to_seqrecord(self.gnm) exp_description = "Mycobacterium phage Trixie, complete genome" with self.subTest(): self.assertEqual(record.name, "Trixie") with self.subTest(): self.assertEqual(record.features, []) with self.subTest(): self.assertEqual(record.description, exp_description) with self.subTest(): self.assertEqual(record.seq, Seq("ATA"))
def execute_ffx_export(alchemist, output_path, file_format, db_version, table="phage", values=[], verbose=False): if verbose: print(f"Retrieving {data_name} data from {sql_handle.database}...") if table == "phage": genomes = mysqldb.parse_genome_data(alchemist.engine, phage_id_list=values, phage_query="SELECT * FROM phage", gene_query="SELECT * FROM gene") else: raise ValueError if verbose: print(f"Converting {data_name} data to SeqRecord format...") seqrecords = [] if table == "phage": for gnm in genomes: set_cds_seqfeatures(gnm) if verbose: print(f"Converting {gnm.name}...") seqrecords.append(flat_files.genome_to_seqrecord(gnm)) if verbose: print("Appending database version...") for record in seqrecords: append_database_version(record, db_version) else: raise ValueError write_seqrecord(seqrecords, file_format, output_path, verbose=verbose)
def test_genome_to_seqrecord_4(self): gnm = "" with self.assertRaises(AttributeError): record = flat_files.genome_to_seqrecord(gnm)
def test_genome_to_seqrecord_3(self): gnm = None with self.assertRaises(AssertionError): record = flat_files.genome_to_seqrecord(gnm)