Mercurial > repos > ucsb-phylogenetics > osiris_phylogenetics
comparison getdata/get_gb_sp.pl @ 0:5b9a38ec4a39 draft default tip
First commit of old repositories
author | osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu> |
---|---|
date | Tue, 11 Mar 2014 12:19:13 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5b9a38ec4a39 |
---|---|
1 #!/usr/bin/perl | |
2 use strict; | |
3 no warnings; #genbank produces annoying warning if no sequence is found | |
4 | |
5 #use FindBin; | |
6 #use lib "$FindBin::Bin/lib"; | |
7 use Bio::DB::GenBank; | |
8 use Bio::SeqIO; | |
9 use Bio::Root::Exception; | |
10 use Error qw(:try); | |
11 | |
12 | |
13 my $datafile = $ARGV[0]; | |
14 my $datatype = $ARGV[1]; | |
15 my $outtype = $ARGV[2]; | |
16 my $outfile = $ARGV[3]; | |
17 my $nodata = $ARGV[4]; | |
18 | |
19 my $accessions; | |
20 my @accnums; | |
21 | |
22 open (FILE,"<$datafile") or die "Cannot open file containing accession numbers\n"; | |
23 open (OUT,">$outfile") or die "Cannot open outfile\n"; | |
24 close OUT; #This overwrites old file if it exists | |
25 open (ND,">$nodata") or die "Cannot open file\n"; | |
26 my $fh = Bio::SeqIO->newFh(-format=>$outtype, -file=>">>$outfile"); | |
27 | |
28 | |
29 while (<FILE>) | |
30 { | |
31 chomp; | |
32 next unless ($_); | |
33 push(@accnums, $_); | |
34 } | |
35 close FILE; | |
36 | |
37 my $countnames = 0; | |
38 foreach (@accnums){ | |
39 #Should check input for one word per line and throw error if not, which is not done | |
40 | |
41 $accessions = $_; | |
42 chomp; | |
43 if($accessions eq ""){ | |
44 die "Put spaces between accession numbers. No Empty Lines allowed.\n"; | |
45 } | |
46 my $qry_string .= $accessions."[organism]"." "; | |
47 | |
48 # my $GBseq; | |
49 my $gb = new Bio::DB::GenBank; | |
50 my $query = Bio::DB::Query::GenBank->new | |
51 (-query =>$qry_string, | |
52 -db =>$datatype); | |
53 | |
54 my $seqio; | |
55 | |
56 if (eval {$gb->get_Stream_by_query($query)}){ | |
57 $seqio = $gb->get_Stream_by_query($query); | |
58 while( my $GBseq = $seqio->next_seq ) { | |
59 my $sequence = $GBseq; # read a sequence object | |
60 print $fh $sequence; # write a sequence object | |
61 } | |
62 }else{ | |
63 print ND "$accessions\n"; | |
64 } | |
65 } | |
66 exit; | |
67 | |
68 |