| 1 | package Bio::Graphics::Browser2::Plugin::AlignTwoSequences; | ||
| 2 | # $Id: AlignTwoSequences.pm,v 1.2 2003-08-27 21:17:46 markwilkinson Exp $ | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use Bio::Graphics::Browser2::Plugin; | ||
| 6 | use CGI qw(:standard *table); | ||
| 7 | use vars '$VERSION','@ISA','$blast_executable'; | ||
| 8 | |||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Bio::Graphics::Browser2::Plugin::AlignTwoSequences -- a plugin that executes NCBI's bl2seq on the current view | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | in 0X.organism.conf: | ||
| 17 | |||
| 18 | [AlignTwoSequences:plugin] | ||
| 19 | bl2seq_executable = /usr/local/BLAST/bl2seq | ||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | This Gbrowse plugin will take a sequence (entered in the configuration screen) | ||
| 26 | and BLAST it against the current display, with hits as new sequence features. | ||
| 27 | |||
| 28 | You must, of course, have the NCBI Blast suite of programs installed, | ||
| 29 | you must have configured the plugin to be visible, and you must | ||
| 30 | set a single plugin parameter in the 0X.organism.conf file: | ||
| 31 | [AlignTwoSequences:plugin] | ||
| 32 | bl2seq_executable = /path/to/your/bl2seq | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | |||
| 37 | $blast_executable = ""; | ||
| 38 | |||
| 39 | $VERSION = '0.02'; | ||
| 40 | |||
| 41 | @ISA = qw(Bio::Graphics::Browser2::Plugin); | ||
| 42 | |||
| 43 | my @COLORS = qw(red green blue orange cyan black | ||
| 44 | turquoise brown indigo wheat yellow emerald); | ||
| 45 | |||
| 46 | sub name { "Blast Against Displayed Sequence" } | ||
| 47 | |||
| 48 | sub description { | ||
| 49 | p("This plugin will take an input sequence - entered in the 'Configure' scren - and run bl2seq (a Blast sequence alignment) ", | ||
| 50 | "against any sequence raised in the current view as new features."). | ||
| 51 | p("This plugin was written by Mark Wilkinson."); | ||
| 52 | } | ||
| 53 | |||
| 54 | sub type { 'annotator' } | ||
| 55 | sub init { | ||
| 56 | my $self = shift; | ||
| 57 | my $conf = $self->browser_config; | ||
| 58 | $blast_executable = $conf->plugin_setting('bl2seq_executable'); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub config_defaults { | ||
| 62 | my $self = shift; | ||
| 63 | return {sequence_to_blast => '', | ||
| 64 | p => 'blastn', | ||
| 65 | g => 'T', | ||
| 66 | G => -1, | ||
| 67 | E => -1, | ||
| 68 | X => 0, | ||
| 69 | W => 0, | ||
| 70 | M => 'BLOSUM62', | ||
| 71 | q => -3, | ||
| 72 | r => 1, | ||
| 73 | F => 'T', | ||
| 74 | e => 10, | ||
| 75 | S => 3, | ||
| 76 | 'm' => 'F', | ||
| 77 | Y => 0, | ||
| 78 | t => 0, | ||
| 79 | U => 'F', | ||
| 80 | }; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub reconfigure { | ||
| 84 | my $self = shift; | ||
| 85 | my $current = $self->configuration; | ||
| 86 | $current->{'sequence_to_blast'} = $self->config_param('sequence_to_blast'); | ||
| 87 | $current->{'p'} = $self->config_param('p'); | ||
| 88 | $current->{'g'} = $self->config_param('g'); | ||
| 89 | $current->{'G'} = $self->config_param('G'); | ||
| 90 | $current->{'E'} = $self->config_param('E'); | ||
| 91 | $current->{'X'} = $self->config_param('X'); | ||
| 92 | $current->{'W'} = $self->config_param('W'); | ||
| 93 | $current->{'M'} = $self->config_param('M'); | ||
| 94 | $current->{'q'} = $self->config_param('q'); | ||
| 95 | $current->{'r'} = $self->config_param('r'); | ||
| 96 | $current->{'F'} = $self->config_param('F'); | ||
| 97 | $current->{'e'} = $self->config_param('e'); | ||
| 98 | $current->{'S'} = $self->config_param('S'); | ||
| 99 | $current->{'m'} = $self->config_param('m'); | ||
| 100 | $current->{'Y'} = $self->config_param('Y'); | ||
| 101 | $current->{'t'} = $self->config_param('t'); | ||
| 102 | $current->{'U'} = $self->config_param('U'); | ||
| 103 | } | ||
| 104 | sub configure_form { | ||
| 105 | my $self = shift; | ||
| 106 | my $current_config = $self->configuration; | ||
| 107 | |||
| 108 | my $form = h3("Default bl2seq values have been selected for you"). | ||
| 109 | table({-border => 0},TR([ | ||
| 110 | td([b("Sequence To Align"), textfield(-name => $self->config_name('sequence_to_blast'),-size => 100, -value=>$current_config->{'sequence_to_blast'})]), | ||
| 111 | td(["Blast Program: ", popup_menu($self->config_name('p'),['blastn','tblastx'], $current_config->{'p'})]), | ||
| 112 | td("Gapped: ").td(radio_group( -name=>$self->config_name('g'), -values=>['T','F'],-default=>$current_config->{'g'})), | ||
| 113 | td(["Gap Penalty: ", textfield(-name=>$self->config_name('G'),-default=>$current_config->{'G'},-size=>3,-maxlength=>3)]), | ||
| 114 | td(["Extend Penalty: ", textfield(-name=>$self->config_name('E'),-default=>$current_config->{'E'},-size=>3,-maxlength=>3)]), | ||
| 115 | td(["Dropoff value: ", textfield(-name=>$self->config_name('X'),-default=>$current_config->{'X'},-size=>3,-maxlength=>3)]), | ||
| 116 | td(["Word size: " , textfield(-name=>$self->config_name('W'),-default=>$current_config->{'W'},-size=>3,-maxlength=>3)]), | ||
| 117 | td(["Matrix: ", popup_menu($self->config_name('M'), ['BLOSUM62'],$current_config->{'M'})]), | ||
| 118 | td(["Mismatch Penalty: ", textfield(-name=>$self->config_name('q'),-default=>$current_config->{'q'},-size=>3,-maxlength=>3)]), | ||
| 119 | td(["Match Reward: ", textfield(-name=>$self->config_name('r'),-default=>$current_config->{'r'},-size=>3,-maxlength=>3)]), | ||
| 120 | td("Filter query: ").td(radio_group(-name=>$self->config_name('F'), -values=>['T','F'],-default=>$current_config->{'F'})), | ||
| 121 | td(["Expect: ", textfield(-name=>$self->config_name('e'),-default=>$current_config->{'e'},-size=>10,-maxlength=>10)]), | ||
| 122 | td(["Strands to search: ", textfield(-name=>$self->config_name('S'),-default=>$current_config->{'S'},-size=>1,-maxlength=>1)]), | ||
| 123 | td(["Search Space: ", textfield(-name=>$self->config_name('Y'),-default=>$current_config->{'Y'},-size=>3,-maxlength=>3)]), | ||
| 124 | td(["Length of largest intron: ", textfield(-name=>$self->config_name('t'),-default=>$current_config->{'t'},-size=>3,-maxlength=>3)]), | ||
| 125 | td("Filter Lower Case: ").td(radio_group(-name=>$self->config_name('U'), -values=>['T','F'],-default=>$current_config->{'U'})) | ||
| 126 | ])); | ||
| 127 | return $form; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | sub annotate { | ||
| 132 | my $self = shift; | ||
| 133 | my $segment = shift; | ||
| 134 | my $ref = $segment->ref; | ||
| 135 | my $abs_start = $segment->start; | ||
| 136 | my $dna = $segment->seq; | ||
| 137 | my $conf = $self->configuration; | ||
| 138 | my $feature_list = Bio::Graphics::FeatureFile->new(-smart_features => 1); | ||
| 139 | $feature_list->add_type(bl2seq=>{glyph => 'alignment', | ||
| 140 | key => "BLAST alignment", | ||
| 141 | fgcolor => 'brown', | ||
| 142 | bgcolor => 'brown', | ||
| 143 | point => 0, | ||
| 144 | 'link' => 'AUTO', | ||
| 145 | orient => 'N', | ||
| 146 | }); | ||
| 147 | # I should add a "link" section to the feature | ||
| 148 | # with the configuration set to open up an alignment window | ||
| 149 | # of some kind via an [AlignTwoSequences:plugin]section... | ||
| 150 | |||
| 151 | my $file = $self->do_blast($dna); | ||
| 152 | use Bio::SearchIO; | ||
| 153 | my $searchio = new Bio::SearchIO(-format => 'blast', | ||
| 154 | -file => $file); | ||
| 155 | while( my $result = $searchio->next_result ) { | ||
| 156 | while( my $hit = $result->next_hit ) { | ||
| 157 | while( my $hsp = $hit->next_hsp ) { | ||
| 158 | my $start = $abs_start + $hsp->start; | ||
| 159 | my $stop = $abs_start + $hsp->end; | ||
| 160 | my $feature = Bio::Graphics::Feature->new( | ||
| 161 | -start=>$start, | ||
| 162 | -type => "bl2seq", | ||
| 163 | -subtype => "similarity", | ||
| 164 | -desc => "Blast alignment", | ||
| 165 | -source => "NCBI_Blast", | ||
| 166 | -strand => "0", | ||
| 167 | -stop=>$stop, | ||
| 168 | -ref=>$ref, | ||
| 169 | -name=>'bl2seq'); | ||
| 170 | $feature_list->add_feature($feature,'bl2seq'); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | unlink $file; | ||
| 175 | return $feature_list; | ||
| 176 | } | ||
| 177 | |||
| 178 | sub do_blast { | ||
| 179 | my ($self, $dna) = @_; | ||
| 180 | use File::Temp; | ||
| 181 | use File::Temp qw/ tempfile tempdir /; | ||
| 182 | |||
| 183 | my ($fh_q, $filename_q) = tempfile(); | ||
| 184 | my ($fh_t, $filename_t) = tempfile(); | ||
| 185 | my $seq2 = $self->configuration->{'sequence_to_blast'}; | ||
| 186 | print $fh_q ">seq1\n$dna\n"; | ||
| 187 | print $fh_t ">seq2\n$seq2\n"; | ||
| 188 | open IN, "$blast_executable -i $filename_q -j $filename_t -p blastn |" || die "can't execute the blast bl2seq call $!\n"; | ||
| 189 | my $result = join "", <IN>; | ||
| 190 | my ($fh_r, $filename_r) = tempfile(); | ||
| 191 | print $fh_r $result; | ||
| 192 | unlink $filename_q; | ||
| 193 | unlink $filename_t; | ||
| 194 | return $filename_r; | ||
| 195 | } | ||
| 196 | |||
| 197 | 1; | ||
| 198 |