def test_add_feature_to_record(self): from barkley import seqrecs from barkley import blast blast.make_blast_db(in_file_fasta=TARGET_FILE, db_name=BLAST_DB_NAME, out_dir=TEST_DATA_PATH) blast.run_blast( queries_file=QUERIES_FILE, results_file=BLAST_RESULTS_FILE, db=BLAST_DB_NAME, evalue=1e-1, program="blastn", task=None, blast_db_dir=TEST_DATA_PATH, output_format=5, num_threads=1, ) blast_hits = blast.parse_blast_results_xml(file_name=BLAST_RESULTS_FILE) record = seqrecs.read_sequence_file( file_path=TARGET_FILE, file_format="fasta", ret_type="list", key="id", # id gi description alphabet="dna", # dna aa rna )[0] hsps = blast_hits["query_01"][0] for hsp in hsps: seqrecs.add_feature_to_record( record=record, f_start=hsp["sbjct_start"], f_end=hsp["sbjct_end"], f_strand=hsp["strand"], f_type="BLAST_HIT", f_qualifiers_dict=hsp, ) # seqrecs.write_sequence_file( # records=[record], # file_path=TARGET_FILE_GB, # file_format='genbank') self.assertEqual(len(record.features), 1)
def test_run_blast(self): from barkley import blast blast.make_blast_db(in_file_fasta=TARGET_FILE, db_name=BLAST_DB_NAME, out_dir=TEST_DATA_PATH) blast.run_blast( queries_file=QUERIES_FILE, results_file=BLAST_RESULTS_FILE, db=BLAST_DB_NAME, evalue=1e-1, program="blastn", task=None, blast_db_dir=TEST_DATA_PATH, output_format=5, num_threads=1, ) self.assertTrue(os.path.exists(BLAST_RESULTS_FILE))
def test_parse_blast_results_xml(self): from barkley import blast blast.make_blast_db(in_file_fasta=TARGET_FILE, db_name=BLAST_DB_NAME, out_dir=TEST_DATA_PATH) blast.run_blast( queries_file=QUERIES_FILE, results_file=BLAST_RESULTS_FILE, db=BLAST_DB_NAME, evalue=1e-1, program="blastn", task=None, blast_db_dir=TEST_DATA_PATH, output_format=5, num_threads=1, ) return_value = blast.parse_blast_results_xml(file_name=BLAST_RESULTS_FILE) hsp_dict = { "sbjct_end": 351, "target_name": "target_01", "query_start": 1, "query_end": 280, "query_name": "query_01", "expect": 2.48939e-151, "sbjct_start": 629, "strand": -1, } self.assertEqual(len(return_value.keys()), 2) self.assertEqual(return_value["query_01"][0][0]["query_name"], hsp_dict["query_name"]) self.assertEqual(return_value["query_01"][0][0]["target_name"], hsp_dict["target_name"]) self.assertEqual(return_value["query_01"][0][0]["sbjct_start"], hsp_dict["sbjct_start"]) self.assertEqual(return_value["query_01"][0][0]["sbjct_end"], hsp_dict["sbjct_end"]) self.assertEqual(return_value["query_01"][0][0]["query_start"], hsp_dict["query_start"]) self.assertEqual(return_value["query_01"][0][0]["query_end"], hsp_dict["query_end"]) self.assertEqual(return_value["query_01"][0][0]["strand"], hsp_dict["strand"])