| Example Program Blast Reports Parsing the output of BLAST call. A tutorial about parsing a blast report.
| 1 | #include <iostream>
| | 2 | #include <seqan/blast.h>
| | 3 |
| | 4 | using namespace seqan;
| | 5 |
| | 6 |
| | 7 | template <typename TFile>
| | 8 | void read_blast_report(TFile & strm)
| | 9 | {
| | 10 |
|
| 11 | typedef BlastHsp<BlastN, FullInfo> TBlastHsp;
| | 12 |
|
| 13 | typedef BlastReport<TBlastHsp, StreamReport<TFile> > TBlastReport;
| | 14 | typedef typename Hit<TBlastReport>::Type TBlastHit;
| | 15 | typedef typename Iterator<TBlastReport,HitIterator>::Type THitIterator;
| | 16 | typedef typename Iterator<TBlastHit,HspIterator>::Type THspIterator;
| | 17 |
| | 18 |
|
| 21 | unsigned hspcount = 0;
| | 22 | unsigned hitcount = 0;
| | 23 | unsigned highsignif = 0;
| | 24 |
| | 25 | while(!atEnd(strm,blast))
| | 26 | {
|
| 27 | read(strm,blast,Blast());
| | 28 | ::std::cout << "Query: "<<getQueryName(blast) <<"\n";
| | 29 | ::std::cout << "Database: "<<getDatabaseName(blast) <<"\n\n";
| | 30 |
|
| 31 | THitIterator hit_it(blast);
| | 32 | for(; !atEnd(strm,hit_it); goNext(strm,hit_it))
| | 33 | {
| | 34 | ++hitcount;
| | 35 | TBlastHit hit = getValue(strm,hit_it);
| | 36 | ::std::cout << " Hit: " <<name(hit) <<"\n\n";
| | 37 |
| | 38 | /// iterate over alignments (HSPs)
| | 39 | THspIterator hsp_it(hit);
| | 40 | for(; !atEnd(strm,hsp_it); goNext(strm,hsp_it))
| | 41 | {
| | 42 | ++hspcount;
| | 43 | TBlastHsp hsp = getValue(strm,hsp_it);
| | 44 |
|
| 45 | ::std::cout << " Score = " << getBitScore(hsp) << "\n";
| | 46 | ::std::cout << " Length = " << length(hsp) << "\n\n";
|
| 47 | if(getEValue(hsp)<0.01)
| | 48 | ++highsignif;
| | 49 |
| | 50 | }
| | 51 | }
| | 52 | }
| | 53 | ::std::cout <<"Total number of Hits: "<< hitcount<<::std::endl;
| | 54 | ::std::cout <<"Total number of HSPs: "<< hspcount<<::std::endl;
| | 55 | ::std::cout <<"Number of highly significant HSPs: "<< highsignif<<::std::endl;
| | 56 |
| | 57 | }
| | 58 |
| | 59 |
| | 60 | int main()
| | 61 | {
| | 62 | ::std::fstream strm;
| | 63 | strm.open("ecoln.out", ::std::ios_base::in | ::std::ios_base::binary);
| | 64 | read_blast_report(strm);
| | 65 | return 0;
| | 66 | }
|
|