maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / examples / searchio / blast_example.pl
blob99c84186d25e11e660b27ba23c2497905751785a
1 #!/usr/bin/perl
2 # Example that shows values returned by Bio::SearchIO::Blast.
3 # Note that some methods will return objects or arrays, not text.
4 # For example, $hsp->get_aln will return a Bio::SimpleAlign object,
5 # not the alignment in a printable form.
6 # This script was used to create the table in the SearchIO HOWTO,
7 # found at http://bioperl.org/howtos/SearchIO_HOWTO.html
8 # Brian Osborne
10 use strict;
11 use Bio::SearchIO;
12 use Bio::SimpleAlign;
13 use Bio::AlignIO;
15 my $file = shift or die "Usage: $0 <BLAST-report-file>\n";
16 my $in = new Bio::SearchIO(-format => 'blast',
17 # comment out the next line to read STDIN
18 -file => $file );
20 while ( my $result = $in->next_result ) {
21 my @stats = $result->available_statistics;
22 my @params = $result->available_parameters;
23 print "Result\tavailable_statistics\t@stats\n";
24 print "Result\tavailable_parameters\t@params\n";
25 print "Result\talgorithm\t" . $result->algorithm . "\n";
26 print "Result\talgorithm_version\t" . $result->algorithm_version . "\n";
27 print "Result\tquery_name\t" . $result->query_name . "\n";
28 print "Result\tquery_accession\t" . $result->query_accession . "\n";
29 print "Result\tquery_length\t" . $result->query_length . "\n";
30 print "Result\tquery_description\t" . $result->query_description . "\n";
31 print "Result\tdatabase_name\t" . $result->database_name . "\n";
32 print "Result\tdatabase_letters\t" . $result->database_letters . "\n";
33 print "Result\tdatabase_entries\t" . $result->database_entries . "\n";
34 print "Result\tnum_hits\t" . $result->num_hits . "\n";
35 print "Result\thits\t" . $result->hits . "\n";
36 while ( my $hit = $result->next_hit ) {
37 my $id = $hit->matches('id');
38 my $cons = $hit->matches('cons');
39 my @accs = $hit->each_accession_number;
40 my @qidentical = $hit->seq_inds('query','identical');
41 my @qconserved = $hit->seq_inds('query','conserved');
42 my @hidentical = $hit->seq_inds('hit','identical');
43 my @hconserved = $hit->seq_inds('hit','conserved');
44 print "Hit\tseq_inds('query','identical')\t@qidentical\n";
45 print "Hit\tseq_inds('query','conserved')\t@qconserved\n";
46 print "Hit\tseq_inds('hit','identical')\t@hidentical\n";
47 print "Hit\tseq_inds('hit','conserved')\t@hconserved\n";
48 print "Hit\teach_accession_number\t@accs\n";
49 print "Hit\tmatches('id')\t" . $id . "\n";
50 print "Hit\tmatches('cons')\t" . $cons . "\n";
51 print "Hit\tname\t" . $hit->name . "\n";
52 print "Hit\taccession\t" . $hit->accession . "\n";
53 print "Hit\tdescription\t" . $hit->description . "\n";
54 print "Hit\tlength\t" . $hit->length . "\n";
55 print "Hit\talgorithm\t" . $hit->algorithm . "\n";
56 print "Hit\traw_score\t" . $hit->raw_score . "\n";
57 print "Hit\tsignificance\t" . $hit->significance . "\n";
58 print "Hit\tbits\t" . $hit->bits . "\n";
59 print "Hit\thsps\t" . $hit->hsps . "\n";
60 print "Hit\tnum_hsps\t" . $hit->num_hsps . "\n";
61 print "Hit\tambiguous_aln\t" . $hit->ambiguous_aln . "\n";
62 print "Hit\toverlap\t" . $hit->overlap . "\n";
63 print "Hit\tn\t" . $hit->n . "\n";
64 print "Hit\tlogical_length\t" . $hit->logical_length . "\n";
65 print "Hit\tlength_aln\t" . $hit->length_aln . "\n";
66 print "Hit\tgaps\t" . $hit->gaps . "\n";
67 print "Hit\tfrac_identical\t" . $hit->frac_identical . "\n";
68 print "Hit\tfrac_conserved\t" . $hit->frac_conserved . "\n";
69 print "Hit\tfrac_aligned_query\t" . $hit->frac_aligned_query . "\n";
70 print "Hit\tfrac_aligned_hit\t" . $hit->frac_aligned_hit . "\n";
71 print "Hit\tnum_unaligned_sbjct\t" . $hit->num_unaligned_sbjct . "\n";
72 print "Hit\tnum_unaligned_hit\t" . $hit->num_unaligned_hit . "\n";
73 print "Hit\tnum_unaligned_query\t" . $hit->num_unaligned_query . "\n";
74 print "Hit\tstrand\t" . $hit->strand . "\n";
75 print "Hit\tframe\t" . $hit->frame . "\n";
76 print "Hit\trank\t" . $hit->rank . "\n";
77 print "Hit\tlocus\t" . $hit->locus . "\n";
78 while ( my $hsp = $hit->next_hsp ) {
79 my ($qid,$qcons) = $hsp->matches('hit');
80 my ($id,$cons) = $hsp->matches('query');
81 @qidentical = $hsp->seq_inds('query','identical');
82 @qconserved = $hsp->seq_inds('query','conserved');
83 @hidentical = $hsp->seq_inds('hit','identical');
84 @hconserved = $hsp->seq_inds('hit','conserved');
85 my @hrange = $hsp->range('hit');
86 my @qrange = $hsp->range('query');
87 my $aln = $hsp->get_aln;
88 my $alnIO = Bio::AlignIO->new(-format=>"clustalw");
89 print "HSP\trange('hit')\t@hrange\n";
90 print "HSP\trange('query')\t@qrange\n";
91 print "HSP\tseq_inds('hit','identical')\t@hidentical\n";
92 print "HSP\tseq_inds('query','conserved')\t@qconserved\n";
93 print "HSP\tseq_inds('query','identical')\t@qidentical\n";
94 print "HSP\tseq_inds('hit','conserved')\t@hconserved\n";
95 print "HSP\tmatches('hit')\t" . $qid . " " . $qcons . "\n";
96 print "HSP\tmatches('query')\t" . $id . " " . $cons . "\n";
97 print "HSP\talgorithm\t" . $hsp->algorithm . "\n";
98 print "HSP\tevalue\t" . $hsp->evalue . "\n";
99 print "HSP\tfrac_identical\t" . $hsp->frac_identical . "\n";
100 print "HSP\tfrac_conserved\t" . $hsp->frac_conserved . "\n";
101 print "HSP\tgaps\t" . $hsp->gaps . "\n";
102 print "HSP\tquery_string\t" . $hsp->query_string . "\n";
103 print "HSP\thit_string\t" . $hsp->hit_string . "\n";
104 print "HSP\thomology_string\t" . $hsp->homology_string . "\n";
105 print "HSP\tlength('total')\t" . $hsp->length('total') . "\n";
106 print "HSP\tlength('hit')\t" . $hsp->length('hit') . "\n";
107 print "HSP\tlength('query')\t" . $hsp->length('query') . "\n";
108 print "HSP\thsp_length\t" . $hsp->hsp_length . "\n";
109 print "HSP\tframe\t" . $hsp->frame . "\n";
110 print "HSP\tnum_conserved\t" . $hsp->num_conserved . "\n";
111 print "HSP\tnum_identical\t" . $hsp->num_identical . "\n";
112 print "HSP\trank\t" . $hsp->rank . "\n";
113 print "HSP\tscore\t" . $hsp->score . "\n";
114 print "HSP\tbits\t" . $hsp->bits . "\n";
115 print "HSP\tpercent_identity\t" . $hsp->percent_identity . "\n";
116 print "HSP\tstrand()\t" . $hsp->strand() . "\n";
117 print "HSP\tstart('hit')\t" . $hsp->start('hit') . "\n";
118 print "HSP\tstart('query')\t" . $hsp->start('query') . "\n";
119 print "HSP\tend('hit')\t" . $hsp->end('hit') . "\n";
120 print "HSP\tend('query')\t" . $hsp->end('query') . "\n";
121 print "HSP\talignment\n";
122 print $alnIO->write_aln($aln),"\n\n";
127 __END__