#!/usr/bin/perl -w ####### # make_fastas.pl # my $purpose = "Extracts sequences from mast as FASTA"; # ######## use strict; use DBI; use Dumpvalue; use Data::Dumper; use Term::ReadKey; use Getopt::Long; use Bio::Seq; use Bio::SeqIO; my %options = (); GetOptions(\%options,'saskatoon|s!','saskatoonfile=s'); my $opts = &validate_options(\%options); # create a few global variables my $dumper = new Dumpvalue(); my $stdouth = new Bio::SeqIO( -fh => \*STDOUT, -format => 'fasta'); my $handle; if ($opts->{saskatoonfile}) { $handle = new Bio::SeqIO( -file => ">".$opts->{saskatoonfile}, -format => 'fasta'); } else { $handle = $stdouth; } if ($opts->{saskatoon}) { my $dbh = DBI->connect("DBI:mysql:database=MAST_Stoon;host=****",'****','******',{ PrintError => 1, RaiseError =>1 }); my $sql = "select Clone_Name,Sequence from tbl_bgene"; my $sth = $dbh->prepare($sql); $sth->execute(); while (my $hash = $sth->fetchrow_hashref()) { # print("Name: ".$hash->{'Clone_Name'}."\n"); print Dumper($hash); my $seq = new Bio::Seq( -display_id => $hash->{'Clone_Name'}, -seq => $hash->{'Sequence'}); $handle->write_seq($seq); # print("Sequence: ".$hash->{'Sequence'}."\n"); } } sub validate_options { my ($opts) = @_; if ($opts->{saskatoonfile}) { $opts->{saskatoon} = 1; } if (!$opts->{saskatoon}) { warn "You did not ask for any sequences to be extracted from MAST\n".&usage()."\n"; } return $opts; } sub usage { my $returner =<<__END__; $0 Usage: --saskatoon -s Get the sequences from MAST_Stoon --saskatoonfile Put sequences from MAST_Stoon into this file (automatically turns on -s) ./mast_fasta.pl --saskatoonfile MAST_Saskatoon __END__ return $returner; }