| 1 | #!/usr/bin/env perl | ||
| 2 | # -*-CPerl-*- | ||
| 3 | # Last changed Time-stamp: <2017-06-08 17:07:55 michl> | ||
| 4 | # | ||
| 5 | # Extract individual sequences from a multi-Fasta file | ||
| 6 | # | ||
| 7 | # *********************************************************************** | ||
| 8 | # * Copyright notice | ||
| 9 | # * | ||
| 10 | # * Copyright 2017 Michael T. Wolfinger <michael@wolfinger.eu> | ||
| 11 | # * All rights reserved | ||
| 12 | # * | ||
| 13 | # * This program is free software: you can redistribute it and/or modify | ||
| 14 | # * it under the terms of the GNU General Public License as published by | ||
| 15 | # * the Free Software Foundation, either version 3 of the License, or | ||
| 16 | # * (at your option) any later version. | ||
| 17 | # * | ||
| 18 | # * This program is distributed in the hope that it will be useful, | ||
| 19 | # * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | # * GNU General Public License for more details. | ||
| 22 | # * | ||
| 23 | # * You should have received a copy of the GNU General Public License | ||
| 24 | # * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 25 | # * | ||
| 26 | # * This copyright notice MUST APPEAR in all copies of the script! | ||
| 27 | # *********************************************************************** | ||
| 28 | |||
| 29 | use strict; | ||
| 30 | use warnings; | ||
| 31 | use Getopt::Long qw( :config posix_default bundling no_ignore_case ); | ||
| 32 | use Pod::Usage; | ||
| 33 | use Data::Dumper; | ||
| 34 | use Cwd; | ||
| 35 | use Path::Class; | ||
| 36 | use Bio::ViennaNGS::Fasta; | ||
| 37 | use Carp; | ||
| 38 | |||
| 39 | my ($fastaO,$grep,$line,$cwd,$f,$seq,$theid, $intervals); | ||
| 40 | my @fids = (); | ||
| 41 | my $fa_in = undef; | ||
| 42 | |||
| 43 | |||
| 44 | Getopt::Long::config('no_ignore_case'); | ||
| 45 | pod2usage(-verbose => 1) unless GetOptions("l|list=s" => \$grep, | ||
| 46 | "f|fa=s" => \$fa_in, | ||
| 47 | "man" => sub{pod2usage(-verbose => 2)}, | ||
| 48 | "help|h" => sub{pod2usage(1)} | ||
| 49 | ); | ||
| 50 | |||
| 51 | unless(-f $fa_in){ | ||
| 52 | warn "Could not find input FASTA input file provided via --fa option"; | ||
| 53 | pod2usage(-verbose => 0); | ||
| 54 | } | ||
| 55 | $cwd = getcwd(); | ||
| 56 | |||
| 57 | unless ($fa_in =~ /^\// || $fa_in =~ /^\.\//){$fa_in = file($cwd,$fa_in);} | ||
| 58 | |||
| 59 | $fastaO = Bio::ViennaNGS::Fasta->new(fasta=>"$fa_in"); | ||
| 60 | |||
| 61 | my @list = split /:/, $grep; | ||
| 62 | foreach my $id (@list){ | ||
| 63 | croak "ERROR: ID $id not found in Fasta file $fa_in" | ||
| 64 | unless ($fastaO->has_sequid($id)); | ||
| 65 | # print ">$id\n"; | ||
| 66 | my $seq = $fastaO->fasta->get_Seq_by_id($id); | ||
| 67 | |||
| 68 | print join "\n", (">$id", unpack "(a70)*",$seq->seq); | ||
| 69 | print "\n"; | ||
| 70 | } | ||
| 71 | |||
| 72 | __END__ |