« blib/lib/Bio/AutomatedAnnotation/CommandLine/AnnotateBacteria.pm
↑ Summary
blib/lib/Bio/AutomatedAnnotation/External/Cmscan.pm »
| 1 | package Bio::AutomatedAnnotation::CommandLine::ParseGenesFromGFFs; | ||
| 2 | |||
| 3 | # ABSTRACT: provide a commandline interface to pull out genes from multiple GFF files | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Getopt::Long qw(GetOptionsFromArray); | ||
| 8 | use Bio::AutomatedAnnotation::ParseGenesFromGFFs; | ||
| 9 | |||
| 10 | has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | ||
| 11 | has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
| 12 | has 'help' => ( is => 'rw', isa => 'Bool', default => 0 ); | ||
| 13 | |||
| 14 | has 'amino_acids' => ( is => 'rw', isa => 'Bool', default => 0); | ||
| 15 | has 'gff_files' => ( is => 'rw', isa => 'ArrayRef' ); | ||
| 16 | has 'search_query' => ( is => 'rw', isa => 'Str' ); | ||
| 17 | has 'search_qualifiers' => ( is => 'rw', isa => 'ArrayRef', default => sub { ['gene'] } ); | ||
| 18 | has 'output_filename' => ( is => 'rw', isa => 'Str' ); | ||
| 19 | |||
| 20 | has '_error_message' => ( is => 'rw', isa => 'Str' ); | ||
| 21 | |||
| 22 | sub BUILD { | ||
| 23 | my ($self) = @_; | ||
| 24 | |||
| 25 | my ( | ||
| 26 | $nucleotides, $gff_files, $search_query, $search_qualifiers, $output_filename, $help | ||
| 27 | ); | ||
| 28 | |||
| 29 | GetOptionsFromArray( | ||
| 30 | $self->args, | ||
| 31 | 'g|gene=s' => \$search_query, | ||
| 32 | 'p|search_products' => \$search_qualifiers, | ||
| 33 | 'o|output=s' => \$output_filename, | ||
| 34 | 'n|nucleotides' => \$nucleotides, | ||
| 35 | 'h|help' => \$help, | ||
| 36 | ); | ||
| 37 | |||
| 38 | if(defined($nucleotides)) | ||
| 39 | { | ||
| 40 | $self->amino_acids(0); | ||
| 41 | } | ||
| 42 | else | ||
| 43 | { | ||
| 44 | $self->amino_acids(1); | ||
| 45 | } | ||
| 46 | |||
| 47 | if(defined($search_query)) | ||
| 48 | { | ||
| 49 | $self->search_query($search_query); | ||
| 50 | } | ||
| 51 | else | ||
| 52 | { | ||
| 53 | $self->_error_message("Error: You must provide a gene to search for"); | ||
| 54 | } | ||
| 55 | |||
| 56 | $self->output_filename($output_filename) if(defined($output_filename)); | ||
| 57 | push(@{$self->search_qualifiers}, 'product') if(defined($search_qualifiers)); | ||
| 58 | |||
| 59 | if(@{$self->args} == 0) | ||
| 60 | { | ||
| 61 | $self->_error_message("Error: You need to provide at least 1 GFF file"); | ||
| 62 | } | ||
| 63 | |||
| 64 | for my $filename (@{$self->args}) | ||
| 65 | { | ||
| 66 | if(! -e $filename) | ||
| 67 | { | ||
| 68 | $self->_error_message("Error: Cant access file $filename"); | ||
| 69 | last; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | $self->gff_files($self->args); | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | sub run { | ||
| 77 | my ($self) = @_; | ||
| 78 | |||
| 79 | ( !$self->help ) or die $self->usage_text; | ||
| 80 | if(defined($self->_error_message)) | ||
| 81 | { | ||
| 82 | print $self->_error_message."\n"; | ||
| 83 | die $self->usage_text; | ||
| 84 | } | ||
| 85 | |||
| 86 | my %input_params = (gff_files => $self->gff_files, | ||
| 87 | search_query => $self->search_query, | ||
| 88 | search_qualifiers => $self->search_qualifiers, | ||
| 89 | amino_acids => $self->amino_acids); | ||
| 90 | |||
| 91 | if(defined($self->output_filename)) | ||
| 92 | { | ||
| 93 | $input_params{output_file} = $self->output_filename; | ||
| 94 | } | ||
| 95 | |||
| 96 | my $gene_finder = Bio::AutomatedAnnotation::ParseGenesFromGFFs->new( | ||
| 97 | \%input_params | ||
| 98 | ); | ||
| 99 | |||
| 100 | $gene_finder->create_fasta_file; | ||
| 101 | |||
| 102 | print "Samples containing gene:\t".$gene_finder->files_with_hits()."\n"; | ||
| 103 | print "Samples missing gene:\t".$gene_finder->files_without_hits()."\n"; | ||
| 104 | } | ||
| 105 | |||
| 106 | sub usage_text { | ||
| 107 | my ($self) = @_; | ||
| 108 | |||
| 109 | return <<USAGE; | ||
| 110 | Usage: parse_genes_from_gffs [options] | ||
| 111 | Parse Genes from GFF files into a Fasta file | ||
| 112 | |||
| 113 | # Get the protein sequence for the 'gryA' gene from two GFF files | ||
| 114 | parse_genes_from_gffs -g gryA example1.gff example2.gff | ||
| 115 | |||
| 116 | # Get the protein sequence for the 'gryA' gene from loads of GFF files | ||
| 117 | parse_genes_from_gffs -g gryA *.gff | ||
| 118 | |||
| 119 | # Expand the search to include the information in the product field | ||
| 120 | parse_genes_from_gffs -g gryA -p example1.gff example2.gff | ||
| 121 | |||
| 122 | # Output the nucleotide sequence to the FASTA file | ||
| 123 | parse_genes_from_gffs -g gryA -n example1.gff example2.gff | ||
| 124 | |||
| 125 | # Provide an output filename | ||
| 126 | parse_genes_from_gffs -g gryA -o outputfile.fa example1.gff example2.gff | ||
| 127 | |||
| 128 | # This help message | ||
| 129 | parse_genes_from_gffs -h | ||
| 130 | |||
| 131 | USAGE | ||
| 132 | } | ||
| 133 | |||
| 134 | __PACKAGE__->meta->make_immutable; | ||
| 135 | no Moose; | ||
| 136 | 1; | ||
| 137 | |||
| 138 | __END__ | ||
| 139 | |||
| 140 | =pod | ||
| 141 | |||
| 142 | =encoding UTF-8 | ||
| 143 | |||
| 144 | =head1 NAME | ||
| 145 | |||
| 146 | Bio::AutomatedAnnotation::CommandLine::ParseGenesFromGFFs - provide a commandline interface to pull out genes from multiple GFF files | ||
| 147 | |||
| 148 | =head1 VERSION | ||
| 149 | |||
| 150 | version 1.182685 | ||
| 151 | |||
| 152 | =head1 SYNOPSIS | ||
| 153 | |||
| 154 | provide a commandline interface to pull out genes from multiple GFF files | ||
| 155 | |||
| 156 | =head1 AUTHOR | ||
| 157 | |||
| 158 | Andrew J. Page <ap13@sanger.ac.uk> | ||
| 159 | |||
| 160 | =head1 COPYRIGHT AND LICENSE | ||
| 161 | |||
| 162 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||
| 163 | |||
| 164 | This is free software, licensed under: | ||
| 165 | |||
| 166 | The GNU General Public License, Version 3, June 2007 | ||
| 167 | |||
| 168 | =cut |