Exemplo n.º 1
0
 def test_local_blastn(self):
     # prepare query
     seqfile_ops.write_fasta(self.single_q_file, self.single_record)
     query_record = seqfile_ops.load_fasta(self.single_q_file)
     self.assertEqual(query_record.id,self.record_1.id)
     self.assertEqual(str(query_record.seq),str(self.record_1.seq))
     # prepare database
     seqfile_ops.write_fasta(self.db_file, self.db_records)
     records_list = seqfile_ops.load_multifasta(self.db_file)
     index = 0
     for record in records_list:
         self.assertEqual(record.id,self.db_records[index].id)
         self.assertEqual(str(record.seq),str(self.db_records[index].seq))
         index +=1
     # make database
     self.dbfile_path, db_report = blasting.make_blastDB(self.temp_dir,
                                                         self.db_name,
                                                         self.db_file,
                                                         'nucl')
     self.assertIs(db_report['status'], 0)
     self.assertEquals(db_report['message'], 'database exists')
     # run local blast with single query
     self.status = blasting.local_blastn(self.single_q_file,
                                         self.single_out_file,
                                         self.dbfile_path,
                                         self.prefs)
     self.assertEquals(self.status['output'], '')
     self.assertIsNone(self.status['error'])
     # parse blast output
     matches_single = blasting.parse_blast_out6(self.single_out_file,
                                                self.prefs)
     self.assertIs(len(matches_single), 1)
     self.assertEqual(matches_single[0]['contig_id'],
                      self.single_record.id)
     self.assertEqual(matches_single[0]['details']['match_p100'], 100)
Exemplo n.º 2
0
def blast_record_set(dbfile_path, fasta_records, blast_prefs):
    """Loop through fasta entries and blast against database."""
    import os
    from analysis.seqfile_ops import write_fasta
    from analysis.blasting import local_blastn
    matches = {}
    for query_record in fasta_records:
        query_file = 'temp.fas'
        out_file = 'temp.blast'
        write_fasta(query_file,query_record)
        try:
            status = local_blastn(query_file, out_file, dbfile_path,
                                  blast_prefs) 
        except: raise
        else:
            query_matches = parse_blast_out6(out_file, blast_prefs)
            matches[query_record.id] = query_matches
        finally:
            os.remove(query_file)
            os.remove(out_file)
    return matches