| 1 | package Bio::Graphics::Browser2::Plugin::CreateBlastDB; | ||
| 2 | # $Id: CreateBlastDB.pm,v 1.1 2003-11-17 22:01:38 markwilkinson Exp $ | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Bio::Graphics::Browser2::Plugin::CreateBlastDB -- a plugin that creates a Blast-formatted database from a Bio::DB::GFF database | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | in 0X.organism.conf: | ||
| 13 | |||
| 14 | [CreateBlastDB:plugin] | ||
| 15 | formatdb_executable = /usr/local/BLAST/formatdb | ||
| 16 | blast_db_folder = /home/username/my/blast_db/folder | ||
| 17 | blast_db_name = myname.fas | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | This Gbrowse plugin will take a sequence database, extract all sequences | ||
| 22 | in it, and create a Blast-formatted database in the folder configured in | ||
| 23 | the 0X.organism.conf file | ||
| 24 | |||
| 25 | You must, of course, have the NCBI Blast suite of programs installed, | ||
| 26 | you must have configured the plugin to be visible, and you must | ||
| 27 | set two parameters in the 0X.organism.conf file: | ||
| 28 | [CreateBlastDB:plugin] | ||
| 29 | formatdb_executable = /usr/local/BLAST/formatdb | ||
| 30 | blast_db_folder = /home/username/my/blast_db/folder | ||
| 31 | blast_db_name = myname.fas | ||
| 32 | |||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | |||
| 37 | use strict; | ||
| 38 | use Bio::Graphics::Browser2::Plugin; | ||
| 39 | use Bio::Graphics::Feature; | ||
| 40 | use DBI; | ||
| 41 | use CGI qw(:standard *table); | ||
| 42 | |||
| 43 | use vars '$VERSION','@ISA', '$formatdb', '$outdir', '$dbname'; | ||
| 44 | $VERSION = '0.15'; | ||
| 45 | |||
| 46 | @ISA = qw(Bio::Graphics::Browser2::Plugin); | ||
| 47 | |||
| 48 | sub name { "Blast Database" } | ||
| 49 | |||
| 50 | sub description { | ||
| 51 | p("This will dump EVERY sequence out of the Bio::DB::GFF database and then run a BLAST formatdb on these sequences. ", | ||
| 52 | "This, of course, requires that you have the Blast binaries installed and configured in your 0X.organism.conf file."). | ||
| 53 | p("This plugin was written by Mark Wilkinson."); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub type { 'dumper' } | ||
| 57 | |||
| 58 | sub mime_type { | ||
| 59 | return "text/html"; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub init { | ||
| 63 | my $self = shift; | ||
| 64 | my $conf = $self->browser_config; | ||
| 65 | $formatdb = $conf->plugin_setting('formatdb_executable'); | ||
| 66 | $outdir = $conf->plugin_setting('blast_db_folder'); | ||
| 67 | $dbname = $conf->plugin_setting('blast_db_name'); | ||
| 68 | $outdir || die "No Configured Blast Database Folder"; | ||
| 69 | die "Blast Database Folder $outdir does not exist" unless (-e $outdir); | ||
| 70 | die "Blast Database Folder $outdir is not a folder" unless (-d $outdir); | ||
| 71 | |||
| 72 | open OUT, ">$outdir/$dbname" || die "can't create/overwrite fasta file $outdir/$dbname: $!\n"; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub config_defaults { | ||
| 76 | my $self = shift; | ||
| 77 | return { }; | ||
| 78 | } | ||
| 79 | |||
| 80 | # we have no stable configuration | ||
| 81 | # sub reconfigure { } | ||
| 82 | |||
| 83 | sub configure_form { | ||
| 84 | my $self = shift; | ||
| 85 | return "<h2>nothing to configure</h2>" | ||
| 86 | } | ||
| 87 | |||
| 88 | sub dump { | ||
| 89 | my $self = shift; | ||
| 90 | my $segment = shift; | ||
| 91 | my $db = $self->database or die "I do not have a database"; | ||
| 92 | my $dbh = $db->features_db; | ||
| 93 | my $sth = $dbh->prepare("select fref,foffset,fdna from fdna order by fref,foffset") or die "Couldn't prepare ",$db->errstr; | ||
| 94 | $sth->execute or die "Couldn't execute ",$db->errstr; | ||
| 95 | my ($current_ref,$offset,$dna,@results); | ||
| 96 | |||
| 97 | while (my ($ref,$off,$d) = $sth->fetchrow_array) { | ||
| 98 | if (!defined($current_ref)) { | ||
| 99 | $dna = ''; | ||
| 100 | $current_ref = $ref | ||
| 101 | } | ||
| 102 | if ($current_ref ne $ref) { | ||
| 103 | open OUT, ">>$outdir/$dbname" || die "can't open fasta file $outdir/$dbname for writing: $!\n"; | ||
| 104 | print OUT ">$ref\n$dna\n\n"; | ||
| 105 | $dna = ''; | ||
| 106 | close OUT; | ||
| 107 | } | ||
| 108 | $current_ref = $ref; | ||
| 109 | $dna .= lc $d; | ||
| 110 | } | ||
| 111 | print "<h3>Executing $formatdb -t 'Bio::DB::GFF Blast Database' -i $outdir/$dbname -p F -o T -a F</h3>"; | ||
| 112 | my $res = system ("$formatdb -t 'Bio::DB::GFF Blast Database' -i $outdir/$dbname -p F -o T -a F"); | ||
| 113 | unless ($res == -1){ | ||
| 114 | print "<h3>Blast Database Created Successfully</h3>"; | ||
| 115 | } else { | ||
| 116 | print "Database Formatting Failed: $!\n"; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | 1; |