#!/usr/bin/perl ############################################################################# #retrieve_sequences_from_ncbi.pl #version 0.1 #Retrieving sequences from NCBI #Only one request every three seconds!!! #Copyright (c) 2005 Diego Mauricio Riaño Pachón #http://www.geocities.com/dmrp.geo # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################# use strict; use warnings; use diagnostics; use Getopt::Long; use LWP::Simple; my $ids_file=''; my $output=''; my $license=''; my $format=''; my $help=''; GetOptions( 'ids|i=s' => \$ids_file, 'output|o=s' => \$output, 'format|f=s' => \$format, 'license|l' => \$license, 'help|h|?' => \$help ); if ($ids_file && $output){ open IN, $ids_file; open OUT, ">$output"; while(my $line=){ chomp $line; my ($id,$coords)=split(/\t/,$line); my $fetch="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nucleotide&id=$id&retmode=text"; if(defined($format) && $format ne ""){ $fetch.="&rettype=$format"; } else{ $fetch.="&rettype=fasta"; } if (defined($coords)){ my ($start,$end)=split(/-/,$coords); $fetch.="&seq_start=$start&seq_stop=$end"; } my $result=get($fetch); print OUT "$result\n" || die "Cannot write to file $output\n"; print STDERR "Retrieving sequence id: $id\t". localtime(time)."\n"; sleep 3; } } elsif($license){ &license; } else{ &usage; } sub usage{ print STDERR "$0 version 0.1, Copyright (C) 2005 Diego Mauricio Riaño Pachón\n"; print STDERR "$0 comes with ABSOLUTELY NO WARRANTY; for details type `$0 -l'.\n"; print STDERR "This is free software, and you are welcome to redistribute it under certain conditions;\n"; print STDERR "type `$0 -l' for details.\n"; print STDERR <