lib/Bio/ViennaNGS/Fasta.pm

filter: Statementstmt 55.7% 29 / 52 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 66.6% 2 / 3 totaltotal 48.1% 39 / 81 CC 8 SCAR 24.4
CC
8
Cov
45%
stranded_subsequence
30.0
BUILD
12.0
has_sequid
6.0
CRAP 11.4
« lib/Bio/ViennaNGS/Expression.pm ↑ Summary lib/Bio/ViennaNGS/FeatureChain.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2017-06-10 19:01:14 michl>
3  
4 =head1 NAME
5  
6 Bio::ViennaNGS::Fasta - Moose wrapper for Bio::DB::Fasta
7  
8 =head1 SYNOPSIS
9  
10 use Bio::ViennaNGS::Fasta;
11  
12 my $f = Bio::ViennaNGS::Fasta->new(fasta => "data/foo.fa", );
13  
14 # get all FASTA IDs
15 my @ids = $f->fastaids;
16  
17 # get a reference to a hash of Bio::PrimarySeq::Fasta objects whose
18 # keys are the Fasta IDs seen in the input file
19 my $ps = $f->primaryseqH;
20  
21 # get the strand-specific genomic sequence for a certain Fasta ID
22 my $id = "chr1";
23 my $start = 287;
24 my $end = 1289;
25 my $strand = "+";
26 my $seq = $f->stranded_subsequence($id,$start,$end,$strand);
27  
28 =head1 DESCRIPTION
29  
30 L<Bio::ViennaNGS::Fasta> provides a L<Moose> interface to
31 L<Bio::DB::Fasta>, spiced up with a few convenience methods for easy
32 sequence data retrieval.
33  
34 =head2 ATTRIBUTES
35  
36 =over 3
37  
38 =item fasta (required)
39  
40 Upcon object construction, this attribute expects an input fasta file,
41 which is transparently coerced into a L<Bio::DB::Fasta> object and
42 hitherto available via the C<fasta> attribute.
43  
44 =item fastaids (auto-computed)
45  
46 Arrary reference to the Fasta IDs found in the input file
47  
48 =item primaryseqH (auto-computed)
49  
50 Hash reference to L<Bio::PrimarySeq::Fasta> objects whose keys are the
51 Fasta IDs found in the input file
52  
53 =back
54  
55 =cut
56  
57 package Bio::ViennaNGS::Fasta;
58  
59 1 ▶use Bio::ViennaNGS;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use Bio::ViennaNGS::Subtypes;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 ▶use Bio::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 has 'fasta' => (
69 is => 'ro',
70 isa => 'Bio::ViennaNGS::MyFasta',
71 required => 1,
72 predicate => 'has_fasta',
73 coerce => 1,
74 );
75  
76  
77 1 has 'fastaids' => (
78 is => 'rw',
79 isa => 'ArrayRef',
80 predicate => 'has_ids',
81 init_arg => undef,
82 );
83  
84 1 has 'primaryseqH' => (
85 is => 'rw',
86 isa => 'HashRef',
87 predicate => 'has_primaryseq',
88 init_arg => undef,
89 );
90  
91  
92 0 ▶sub BUILD {
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod undocumented
93 0 my $self = shift;
94 0 my $this_function = (caller(0))[3];
95 0 $self->fastaids([$self->fasta->ids]);
96 0 ▶ confess "ERROR [$this_function] \$self->fastsids not available"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_ids 0 0 0
97 unless ($self->has_ids);
98 0 my %ps = ();
99 0 foreach my $id (@{$self->fastaids}){
100 0 $ps{$id} = $self->fasta->get_Seq_by_id($id);
101 }
102 0 $self->primaryseqH(\%ps);
103 }
104  
105 =head2 METHODS
106  
107 =over 2
108  
109 =item stranded_subsequence
110  
111 Title : stranded_subsequence
112  
113 Usage : C<$obj-E<gt>stranded_subsequence($id,$start,$end,$strand)>
114  
115 Function : Returns the DNA/RNA sequence for ID C<$id> from C<$start>
116 to C<$end>. Internally, sequence data is retrieved from
117 C<$self-E<gt>$primaryseqH> HashRef to
118 L<Bio::PrimarySeqI>/L<Bio::PrimarySeq::Fasta> objects.
119  
120 Args : C<$id> is the Fasta ID to retrieve sequence data from,
121 C<$start> and C<$end> are (1-based) start and end coordinates
122 of the requested interval, where C<$start> must be <= C<$end>,
123 and C<$strand> is 1 or -1 for [+] or [-] strand, respectively.
124  
125 Returns : A string.
126  
127 =item has_sequid
128  
129 Title : has_sequid
130  
131 Usage : C<$obj-E<gt>has_seqid($id)>
132  
133 Function : Checks whether the current object contains Fasta ID C<$id>.
134  
135 Args : C<$id> if the Fasta ID to check for.
136  
137 Returns : 1 if ID C<$id> was found, 0 else.
138  
139 =back
140  
141 =cut
142  
143 0 ▶sub stranded_subsequence {
Subroutine stranded_subsequence: not called CC=5 SCAR=34.0
Pod documented
144 0 my ($self,$id,$start,$end,$strand) = @_;
145 0 my ($this_function,$seq,$rc,$p,$obj);
146 0 $this_function = (caller(0))[3];
147 0 ▶ confess "ERROR [$this_function] start corrdinate must be <= end coordinate"
Branch: 1 branch
BranchTrueFalseTotal
unless $start <= $end 0 0 0
148 unless ($start <= $end);
149 0 ▶ confess "ERROR [$this_function] Id $id not found in input Fasta file"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_sequid($id) 0 0 0
150 unless ($self->has_sequid($id));
151 0 $seq = ${$self->primaryseqH}{$id}->subseq($start => $end);
152 0 ▶ if ($strand eq '-1' || $strand eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq -1 or $strand eq "-") 0 0 0
Condition0%0/3
$strand eq -1 or $strand eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$strand eq -1 or $strand eq "-"
$strand eq -1 $strand eq "-"
Truth table0%0/3
A or B
A= $strand eq -1B= $strand eq "-"
ABresult
1X1
011
000
153 0 $rc = revcom($seq);
154 0 $seq = $rc->seq();
155 }
156 #print "id:$id\nstart:$start\nend:$end\n";
157 0 return $seq;
158 }
159  
160  
161 0 ▶sub has_sequid {
Subroutine has_sequid: not called CC=2 SCAR=17.9
Pod documented
162 0 my ($self,$id) = @_;
163 0 ▶ return exists ${$self->primaryseqH}{$id} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists do { $self->primaryseqH }->{$id} ? : 0 0 0
164 }
165  
166  
167 =head1 DEPENDENCIES
168  
169 =over
170  
171 =item L<Bio::Perl> >= 1.00690001
172  
173 =item L<Bio::DB::Fasta>
174  
175 =item L<Moose>
176  
177 =item L<Carp>
178  
179 =item L<namespace::autoclean>
180  
181 =back
182  
183 =head1 SEE ALSO
184  
185 =over
186  
187 =item L<Bio::ViennaNGS>
188  
189 =item L<Bio::DB::Fasta>
190  
191 =back
192  
193 =head1 AUTHOR
194  
195 Michael T. Wolfinger, E<lt>michael@wolfinger.euE<gt>
196  
197 =head1 COPYRIGHT AND LICENSE
198  
199 Copyright (C) 2014-2017 by Michael T. Wolfinger
200  
201 This library is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself, either Perl version 5.10.0 or,
203 at your option, any later version of Perl 5 you may have available.
204  
205 This software is distributed in the hope that it will be useful, but
206 WITHOUT ANY WARRANTY; without even the implied warranty of
207 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
208  
209 =cut
210  
211 1 1;
« lib/Bio/ViennaNGS/Expression.pm ↑ Summary lib/Bio/ViennaNGS/FeatureChain.pm »