lib/Bio/AutomatedAnnotation/GeneNamesFromGFF.pm

filter: Statementstmt 100% 40 / 40 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 91.6% 55 / 60 CC 7 SCAR 12.2
CC
7
Cov
90%
_build_gene_names
6.2
_build__gff_parser
2.0
BEGIN
1.0
CRAP 3.4
« lib/Bio/AutomatedAnnotation/CommandLine/GeneNameOccurances.pm ↑ Summary blib/lib/Bio/AutomatedAnnotation/GeneNameOccurances.pm »
1 package Bio::AutomatedAnnotation::GeneNamesFromGFF;
2  
3 # ABSTRACT: Parse a GFF and efficiently extract out the Gene Names
4  
5  
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Bio::Tools::GFF;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 has 'gff_file' => ( is => 'ro', isa => 'Str', required => 1 );
10  
11 4 has '_tags_to_filter' => ( is => 'ro', isa => 'Str', default => 'CDS' );
12 4 has '_tags_to_ignore' => ( is => 'ro', isa => 'Str', default => 'rRNA|tRNA|ncRNA|tmRNA' );
13 4 has '_gff_parser' => ( is => 'ro', isa => 'Bio::Tools::GFF', lazy => 1, builder => '_build__gff_parser' );
14 4 has '_awk_filter' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__awk_filter' );
15 4 has '_remove_sequence_filter' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__remove_sequence_filter' );
16  
17 4 has 'gene_names' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_gene_names' );
18  
19 sub _build_gene_names {
20 25 ▶ my ($self) = @_;
Subroutine _build_gene_names: called CC=6 SCAR=18.3
21 25 my %gene_names;
22  
23 25 ▶ while ( my $raw_feature = $self->_gff_parser->next_feature() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $raw_feature = $self->_gff_parser->next_feature) 95 25 120
24 95 ▶ last unless defined($raw_feature); # No more features
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_feature 0 95 95
25 95 ▶ next if !( $raw_feature->primary_tag eq 'CDS' );
Branch: 1 branch
BranchTrueFalseTotal
unless $raw_feature->primary_tag eq "CDS" 0 95 95
26  
27 95 ▶ if ( $raw_feature->has_tag('gene') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw_feature->has_tag("gene")) 95 0 95
28 95 my ( $gene_name, @junk ) = $raw_feature->get_tag_values('gene');
29 95 $gene_name =~ s!"!!g;
30 95 ▶ next if ( $gene_name eq "" );
Branch: 1 branch
BranchTrueFalseTotal
if $gene_name eq "" 0 95 95
31 95 $gene_names{$gene_name} = 1;
32 }
33 }
34 25 $self->_gff_parser->close();
35 25 return \%gene_names;
36 }
37  
38 # Bio::Tools::GFF->ignore_sequence(1) doesnt work with our data, triggers an infinite loop
39 sub _build__gff_parser {
40 25 ▶ my ($self) = @_;
Subroutine _build__gff_parser: called CC=2 SCAR=7.0
41 25 ▶ open( my $fh, '-|', $self->_gff_fh_input_string ) or die "Couldnt open GFF file";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "-|", $self->_gff_fh_input_string or die "Couldnt open GFF file" 0 25 25
42 25 my $gff_parser = Bio::Tools::GFF->new( -fh => $fh, gff_version => 3 );
43 25 return $gff_parser;
44 }
45  
46 sub _gff_fh_input_string {
47 25 ▶ my ($self) = @_;
Subroutine _gff_fh_input_string: called CC=1 SCAR=0.0
48 25 return $self->_awk_filter . " " . $self->gff_file . " | " . $self->_remove_sequence_filter;
49 }
50  
51 # Parsing a GFF file with perl is slow, so filter out CDSs which dont contain a gene name
52 sub _build__awk_filter {
53 25 ▶ my ($self) = @_;
Subroutine _build__awk_filter: called CC=1 SCAR=0.0
54 return
55 25 'awk \'BEGIN {FS="\t"};{ if ($3 ~/'
56 . $self->_tags_to_filter
57 . '/ && $9 ~ /gene=/) print $0;else if ($3 ~/'
58 . $self->_tags_to_filter . '|'
59 . $self->_tags_to_ignore
60 . '/) ; else print $0;}\' ';
61 }
62  
63 # Cut out the FASTA sequence at the bottom of the file
64 sub _build__remove_sequence_filter {
65 25 ▶ my ($self) = @_;
Subroutine _build__remove_sequence_filter: called CC=1 SCAR=0.0
66 25 return 'sed -n \'/##gff-version 3/,/##FASTA/p\' | grep -v \'##FASTA\'';
67 }
68  
69 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 4 __PACKAGE__->meta->make_immutable;
71  
72 4 1;
73  
74 __END__
75  
76 =pod
77  
78 =encoding UTF-8
79  
80 =head1 NAME
81  
82 Bio::AutomatedAnnotation::GeneNamesFromGFF - Parse a GFF and efficiently extract out the Gene Names
83  
84 =head1 VERSION
85  
86 version 1.182680
87  
88 =head1 SYNOPSIS
89  
90 Parse a GFF and efficiently extract out the Gene Names
91 use Bio::AutomatedAnnotation::GeneNamesFromGFF;
92  
93 my $obj = Bio::AutomatedAnnotation::GeneNamesFromGFF->new(
94 gff_file => 'abc.gff'
95 );
96 $obj->gene_names;
97  
98 =head1 AUTHOR
99  
100 Andrew J. Page <ap13@sanger.ac.uk>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
105  
106 This is free software, licensed under:
107  
108 The GNU General Public License, Version 3, June 2007
109  
110 =cut
« lib/Bio/AutomatedAnnotation/CommandLine/GeneNameOccurances.pm ↑ Summary blib/lib/Bio/AutomatedAnnotation/GeneNameOccurances.pm »