| 1 | #!/usr/bin/env perl | ||
| 2 | # -*-CPerl-*- | ||
| 3 | # Last changed Time-stamp: <2014-12-10 00:34:41 mtw> | ||
| 4 | # | ||
| 5 | # Convert GFF3 to BED12; produce separate BED files for each gbkey | ||
| 6 | # (CDS/tRNA/rRNA/ncRNA etc.) | ||
| 7 | # | ||
| 8 | # usage: gff2bed.pl --gff input.gff | ||
| 9 | # | ||
| 10 | # *********************************************************************** | ||
| 11 | # * Copyright notice | ||
| 12 | # * | ||
| 13 | # * Copyright 2014 Michael T. Wolfinger <michael@wolfinger.eu> | ||
| 14 | # * All rights reserved | ||
| 15 | # * | ||
| 16 | # * This program is free software: you can redistribute it and/or modify | ||
| 17 | # * it under the terms of the GNU General Public License as published by | ||
| 18 | # * the Free Software Foundation, either version 3 of the License, or | ||
| 19 | # * (at your option) any later version. | ||
| 20 | # * | ||
| 21 | # * This program is distributed in the hope that it will be useful, | ||
| 22 | # * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 23 | # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 24 | # * GNU General Public License for more details. | ||
| 25 | # * | ||
| 26 | # * You should have received a copy of the GNU General Public License | ||
| 27 | # * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 28 | # * | ||
| 29 | # * This copyright notice MUST APPEAR in all copies of the script! | ||
| 30 | # *********************************************************************** | ||
| 31 | # | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | use Getopt::Long qw( :config posix_default bundling no_ignore_case ); | ||
| 36 | use Pod::Usage; | ||
| 37 | use Data::Dumper; | ||
| 38 | use File::Basename; | ||
| 39 | use Path::Class; | ||
| 40 | use Bio::ViennaNGS::AnnoC; | ||
| 41 | |||
| 42 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 43 | #^^^^^^^^^^ Variables ^^^^^^^^^^^# | ||
| 44 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 45 | |||
| 46 | my $feature = undef; # look for all features per default | ||
| 47 | my $gff_in = '-'; | ||
| 48 | my $outdir = './'; | ||
| 49 | my ($basename,$gffdir,$gffext,$obj); | ||
| 50 | |||
| 51 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 52 | #^^^^^^^^^^^^^^ Main ^^^^^^^^^^^^^# | ||
| 53 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 54 | |||
| 55 | Getopt::Long::config('no_ignore_case'); | ||
| 56 | pod2usage(-verbose => 1) unless GetOptions("gff=s" => \$gff_in, | ||
| 57 | "o|out=s" => \$outdir, | ||
| 58 | "f|feature=s" => \$feature, | ||
| 59 | "man" => sub{pod2usage(-verbose => 2)}, | ||
| 60 | "help|h" => sub{pod2usage(1)} | ||
| 61 | ); | ||
| 62 | |||
| 63 | unless ($gff_in =~ /^\// || $gff_in =~ /\.\//){$gff_in = "./".$gff_in;} | ||
| 64 | unless (-f $gff_in){ | ||
| 65 | warn "Could not find input file $gff_in given via --gff option"; | ||
| 66 | pod2usage(-verbose => 0); | ||
| 67 | } | ||
| 68 | |||
| 69 | #TODO check if we are allowed to write to $outdir | ||
| 70 | unless ($outdir =~ /\/$/){$outdir .= "/";} | ||
| 71 | unless (-d $outdir){mkdir $outdir or die $!;} | ||
| 72 | |||
| 73 | ($basename,$gffdir,$gffext) = fileparse($gff_in,qr/\..*/); | ||
| 74 | |||
| 75 | $obj = Bio::ViennaNGS::AnnoC->new(); | ||
| 76 | $obj->parse_gff($gff_in); | ||
| 77 | $obj->featstat; | ||
| 78 | $obj->feature_summary($outdir); | ||
| 79 | $obj->features2bed($feature,$outdir,$basename,undef); | ||
| 80 | |||
| 81 | |||
| 82 | __END__ |