lib/Bio/Roary/ContigsToGeneIDsFromGFF.pm

filter: Statementstmt 69.3% 52 / 75 Branchbran 34.6% 9 / 26 Conditioncond 55.5% 5 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 60.9% 75 / 123 CC 17 SCAR 28.8
CC
17
Cov
60%
_build_overlapping_hypothetical_protein_ids
40.1
_percent_overlap
12.0
_build_contig_to_ids
8.1
CRAP 17.7
« lib/Bio/Roary/External/CheckTools.pm ↑ Summary blib/lib/Bio/Roary/CommandLine/UniqueGenesPerSample.pm »
1 package Bio::Roary::ContigsToGeneIDsFromGFF;
2 4 $Bio::Roary::ContigsToGeneIDsFromGFF::VERSION = '3.13.0';
3 # ABSTRACT: Parse a GFF and efficiently and extract ordered gene ids on each contig
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 4 with 'Bio::Roary::ParseGFFAnnotationRole';
9  
10 4 has 'contig_to_ids' => ( is => 'rw', isa => 'HashRef', lazy => 1, builder => '_build_contig_to_ids');
11  
12 4 has 'overlapping_hypothetical_protein_ids' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_overlapping_hypothetical_protein_ids');
13 110 ▶has '_genes_annotation' => ( is => 'rw', isa => 'ArrayRef', default => sub{[]});
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 4 has '_min_nucleotide_overlap_percentage' => ( is => 'ro', isa => 'Int', default => 10);
16  
17 # Manually parse the GFF file because the BioPerl module is too slow
18 sub _build_contig_to_ids
19 110 ▶{
Subroutine _build_contig_to_ids: called CC=8 SCAR=20.9
20 110 my ($self) = @_;
21 110 my %contigs_to_ids;
22 my @genes_annotation;
23
24 110 ▶ 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" 110 0 110
25 110 ▶ while(<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 1001 110 1111
26 {
27 1001 chomp;
28 1001 my $line = $_;
29 1001 my $id_name;
30 1001 ▶ if($line =~/ID=["']?([^;"']+)["']?;?/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /ID=["']?([^;"']+)["']?;?/i) { } 1001 0 1001
31 {
32 1001 $id_name= $1;
33 }
34 else
35 {
36 0 next;
37 }
38
39 1001 my @annotation_elements = split(/\t/,$line);
40 # Map gene IDs to the contig
41 1001 push(@{$contigs_to_ids{$annotation_elements[0]}}, $id_name);
42
43 1001 ▶ if($line =~/product=["']?([^;,"']+)[,"']?;?/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /product=["']?([^;,"']+)[,"']?;?/i) 143 858 1001
44 {
45 143 my %gene_data;
46 143 $gene_data{product} = $1;
47 143 $gene_data{id_name} = $id_name;
48 143 ▶ if($line =~ /UniProtKB/ || $line =~ /RefSeq/ || $line =~ /protein motif/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /UniProtKB/ or $line =~ /RefSeq/ or $line =~ /protein motif/) { } 103 40 143
Condition83%5/6
$line =~ /UniProtKB/ or $line =~ /RefSeq/ or $line =~ /protein motif/
l!l&&r!l&&!r
713240
$line =~ /UniProtKB/ or $line =~ /RefSeq/
l!l&&r!l&&!r
71072
MC/DC66%2/3
$line =~ /UniProtKB/ or $line =~ /RefSeq/ or $line =~ /protein motif/
$line =~ /UniProtKB/ $line =~ /RefSeq/ $line =~ /protein motif/
Truth table75%3/4
A or B or C
A= $line =~ /UniProtKB/B= $line =~ /RefSeq/C= $line =~ /protein motif/
ABCresult
1XX1
01X1
0011
0000
49 {
50 103 $gene_data{database_annotation_exists} = 1;
51 }
52 else
53 {
54 40 $gene_data{database_annotation_exists} = 0;
55 }
56
57 143 $gene_data{contig} = $annotation_elements[0];
58 143 $gene_data{start} = $annotation_elements[1];
59 143 $gene_data{end} = $annotation_elements[2];
60 143 push(@genes_annotation,\%gene_data);
61 }
62  
63 }
64 110 close($fh);
65
66 110 $self->_genes_annotation(\@genes_annotation);
67 110 return \%contigs_to_ids;
68 }
69  
70 sub _build_overlapping_hypothetical_protein_ids
71 45 ▶{
Subroutine _build_overlapping_hypothetical_protein_ids: called CC=8 SCAR=36.9
72 45 my ($self) = @_;
73 45 $self->contig_to_ids;
74
75 45 my %overlapping_protein_ids;
76
77 #Checking to see if the current feature is hypotheitical and if the next one has annotation
78 45 ▶ for(my $i = 0; $i< (@{$self->_genes_annotation} -1) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$self->_genes_annotation;} - 1) 0 45 45
79 {
80 0 my $current_feature = $self->_genes_annotation->[$i];
81 0 my $next_feature = $self->_genes_annotation->[$i+1];
82
83 0 ▶ next if($current_feature->{database_annotation_exists} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $current_feature->{"database_annotation_exists"} == 1 0 0 0
84 0 ▶ next unless($current_feature->{product} =~ /hypothetical/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $current_feature->{"product"} =~ /hypothetical/i 0 0 0
85 0 ▶ next unless($next_feature->{database_annotation_exists} == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $next_feature->{"database_annotation_exists"} == 1 0 0 0
86
87 0 my $start_coord = $current_feature->{start} ;
88 0 my $end_coord = $current_feature->{end} ;
89 0 my $comparison_start_coord =$next_feature->{start} ;
90 0 my $comparison_end_coord =$next_feature->{end} ;
91 0 ▶ if($comparison_start_coord < $end_coord && $comparison_end_coord > $start_coord )
Branch: 1 branch
BranchTrueFalseTotal
if ($comparison_start_coord < $end_coord and $comparison_end_coord > $start_coord) 0 0 0
Condition0%0/3
$comparison_start_coord < $end_coord and $comparison_end_coord > $start_coord
!ll&&!rl&&r
000
MC/DC0%0/2
$comparison_start_coord < $end_coord and $comparison_end_coord > $start_coord
$comparison_start_coord < $end_coord $comparison_end_coord > $start_coord
Truth table0%0/3
A and B
A= $comparison_start_coord < $end_coordB= $comparison_end_coord > $start_coord
ABresult
0X0
100
111
92 {
93 0 my $percent_overlap = $self->_percent_overlap($start_coord, $end_coord , $comparison_start_coord,$comparison_end_coord);
94 0 ▶ if($percent_overlap >= $self->_min_nucleotide_overlap_percentage)
Branch: 1 branch
BranchTrueFalseTotal
if ($percent_overlap >= $self->_min_nucleotide_overlap_percentage) 0 0 0
95 {
96 0 $overlapping_protein_ids{$current_feature->{id_name}}++;
97 }
98 }
99 }
100
101 45 return \%overlapping_protein_ids;
102 }
103  
104 sub _percent_overlap
105 0 ▶{
Subroutine _percent_overlap: not called CC=3 SCAR=24.8
106 0 my ($self, $start_coord, $end_coord , $comparison_start_coord,$comparison_end_coord) = @_;
107 0 my $size_of_hypothetical_gene = $end_coord - $start_coord;
108
109 0 my $lower_bound = $start_coord;
110 0 ▶ if($comparison_start_coord > $start_coord)
Branch: 1 branch
BranchTrueFalseTotal
if ($comparison_start_coord > $start_coord) 0 0 0
111 {
112 0 $lower_bound = $comparison_start_coord;
113 }
114 0 my $upper_bound = $end_coord;
115 0 ▶ if($comparison_end_coord < $end_coord )
Branch: 1 branch
BranchTrueFalseTotal
if ($comparison_end_coord < $end_coord) 0 0 0
116 {
117 0 $upper_bound = $comparison_end_coord;
118 }
119 0 return (($upper_bound-$lower_bound)*100) / $size_of_hypothetical_gene;
120 }
121  
122  
123 110 ▶sub _build__awk_filter {
Subroutine _build__awk_filter: called CC=1 SCAR=0.0
124 110 my ($self) = @_;
125 return
126 110 'awk \'BEGIN {FS="\t"};{ if ($3 ~/'
127 . $self->_tags_to_filter
128 . '/) print $1"\t"$4"\t"$5"\t"$9;}\' ';
129 }
130  
131 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 4 __PACKAGE__->meta->make_immutable;
133  
134 4 1;
135  
136 __END__
« lib/Bio/Roary/External/CheckTools.pm ↑ Summary blib/lib/Bio/Roary/CommandLine/UniqueGenesPerSample.pm »