Bio/Seq.pm

filter: Statementstmt 86.9% 113 / 130 Branchbran 74.0% 40 / 54 Conditioncond 61.1% 11 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 84.6% 33 / 39 Podpod 90.9% 30 / 33 totaltotal 81.3% 231 / 284 CC 37 SCAR 17.7
CC
37
Cov
81%
new
17.4
add_SeqFeature
7.9
primary_seq
5.9
CRAP 5.9
« Bio/Seq/RichSeq.pm ↑ Summary Bio/Search/Hit/BlastPullHit.pm »
1 #
2 # BioPerl module for Bio::Seq
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Seq - Sequence object, with features
17  
18 =head1 SYNOPSIS
19  
20 # This is the main sequence object in Bioperl
21  
22 # gets a sequence from a file
23 $seqio = Bio::SeqIO->new( '-format' => 'embl' , -file => 'myfile.dat');
24 $seqobj = $seqio->next_seq();
25  
26 # SeqIO can both read and write sequences; see Bio::SeqIO
27 # for more information and examples
28  
29 # get from database
30 $db = Bio::DB::GenBank->new();
31 $seqobj = $db->get_Seq_by_acc('X78121');
32  
33 # make from strings in script
34 $seqobj = Bio::Seq->new( -display_id => 'my_id',
35 -seq => $sequence_as_string);
36  
37 # gets sequence as a string from sequence object
38 $seqstr = $seqobj->seq(); # actual sequence as a string
39 $seqstr = $seqobj->subseq(10,50); # slice in biological coordinates
40  
41 # retrieves information from the sequence
42 # features must implement Bio::SeqFeatureI interface
43  
44 @features = $seqobj->get_SeqFeatures(); # just top level
45 foreach my $feat ( @features ) {
46 print "Feature ",$feat->primary_tag," starts ",$feat->start," ends ",
47 $feat->end," strand ",$feat->strand,"\n";
48  
49 # features retain link to underlying sequence object
50 print "Feature sequence is ",$feat->seq->seq(),"\n"
51 }
52  
53 # sequences may have a species
54  
55 if( defined $seq->species ) {
56 print "Sequence is from ",$species->binomial," [",$species->common_name,"]\n";
57 }
58  
59 # annotation objects are Bio::AnnotationCollectionI's
60 $ann = $seqobj->annotation(); # annotation object
61  
62 # references is one type of annotations to get. Also get
63 # comment and dblink. Look at Bio::AnnotationCollection for
64 # more information
65  
66 foreach my $ref ( $ann->get_Annotations('reference') ) {
67 print "Reference ",$ref->title,"\n";
68 }
69  
70 # you can get truncations, translations and reverse complements, these
71 # all give back Bio::Seq objects themselves, though currently with no
72 # features transferred
73  
74 my $trunc = $seqobj->trunc(100,200);
75 my $rev = $seqobj->revcom();
76  
77 # there are many options to translate - check out the docs
78 my $trans = $seqobj->translate();
79  
80 # these functions can be chained together
81  
82 my $trans_trunc_rev = $seqobj->trunc(100,200)->revcom->translate();
83  
84  
85  
86 =head1 DESCRIPTION
87  
88 A Seq object is a sequence with sequence features placed on it. The
89 Seq object contains a PrimarySeq object for the actual sequence and
90 also implements its interface.
91  
92 In Bioperl we have 3 main players that people are going to use frequently
93  
94 Bio::PrimarySeq - just the sequence and its names, nothing else.
95 Bio::SeqFeatureI - a feature on a sequence, potentially with a sequence
96 and a location and annotation.
97 Bio::Seq - A sequence and a collection of sequence features
98 (an aggregate) with its own annotation.
99  
100 Although Bioperl is not tied heavily to file formats these distinctions do
101 map to file formats sensibly and for some bioinformaticians this might help
102  
103 Bio::PrimarySeq - Fasta file of a sequence
104 Bio::SeqFeatureI - A single entry in an EMBL/GenBank/DDBJ feature table
105 Bio::Seq - A single EMBL/GenBank/DDBJ entry
106  
107 By having this split we avoid a lot of nasty circular references
108 (sequence features can hold a reference to a sequence without the sequence
109 holding a reference to the sequence feature). See L<Bio::PrimarySeq> and
110 L<Bio::SeqFeatureI> for more information.
111  
112 Ian Korf really helped in the design of the Seq and SeqFeature system.
113  
114 =head2 Examples
115  
116 A simple and fundamental block of code:
117  
118 use Bio::SeqIO;
119  
120 my $seqIOobj = Bio::SeqIO->new(-file=>"1.fa"); # create a SeqIO object
121 my $seqobj = $seqIOobj->next_seq; # get a Seq object
122  
123 With the Seq object in hand one has access to a powerful set of Bioperl
124 methods and related Bioperl objects. This next script will take a file of sequences
125 in EMBL format and create a file of the reverse-complemented sequences
126 in Fasta format using Seq objects. It also prints out details about the
127 exons it finds as sequence features in Genbank Flat File format.
128  
129 use Bio::Seq;
130 use Bio::SeqIO;
131  
132 $seqin = Bio::SeqIO->new( -format => 'EMBL' , -file => 'myfile.dat');
133 $seqout= Bio::SeqIO->new( -format => 'Fasta', -file => '>output.fa');
134  
135 while((my $seqobj = $seqin->next_seq())) {
136 print "Seen sequence ",$seqobj->display_id,", start of seq ",
137 substr($seqobj->seq,1,10),"\n";
138 if( $seqobj->alphabet eq 'dna') {
139 $rev = $seqobj->revcom;
140 $id = $seqobj->display_id();
141 $id = "$id.rev";
142 $rev->display_id($id);
143 $seqout->write_seq($rev);
144 }
145  
146 foreach $feat ( $seqobj->get_SeqFeatures() ) {
147 if( $feat->primary_tag eq 'exon' ) {
148 print STDOUT "Location ",$feat->start,":",
149 $feat->end," GFF[",$feat->gff_string,"]\n";
150 }
151 }
152 }
153  
154 Let's examine the script. The lines below import the Bioperl modules.
155 Seq is the main Bioperl sequence object and SeqIO is the Bioperl support
156 for reading sequences from files and to files
157  
158 use Bio::Seq;
159 use Bio::SeqIO;
160  
161 These two lines create two SeqIO streams: one for reading in sequences
162 and one for outputting sequences:
163  
164 $seqin = Bio::SeqIO->new( -format => 'EMBL' , -file => 'myfile.dat');
165 $seqout= Bio::SeqIO->new( -format => 'Fasta', -file => '>output.fa');
166  
167 Notice that in the "$seqout" case there is a greater-than sign,
168 indicating the file is being opened for writing.
169  
170 Using the
171  
172 '-argument' => value
173  
174 syntax is common in Bioperl. The file argument is like an argument
175 to open() . You can also pass in filehandles or FileHandle objects by
176 using the -fh argument (see L<Bio::SeqIO> documentation for details).
177 Many formats in Bioperl are handled, including Fasta, EMBL, GenBank,
178 Swissprot (swiss), PIR, and GCG.
179  
180 $seqin = Bio::SeqIO->new( -format => 'EMBL' , -file => 'myfile.dat');
181 $seqout= Bio::SeqIO->new( -format => 'Fasta', -file => '>output.fa');
182  
183 This is the main loop which will loop progressively through sequences
184 in a file, and each call to $seqio-E<gt>next_seq() provides a new Seq
185 object from the file:
186  
187 while((my $seqobj = $seqio->next_seq())) {
188  
189 This print line below accesses fields in the Seq object directly. The
190 $seqobj-E<gt>display_id is the way to access the display_id attribute
191 of the Seq object. The $seqobj-E<gt>seq method gets the actual
192 sequence out as string. Then you can do manipulation of this if
193 you want to (there are however easy ways of doing truncation,
194 reverse-complement and translation).
195  
196 print "Seen sequence ",$seqobj->display_id,", start of seq ",
197 substr($seqobj->seq,1,10),"\n";
198  
199 Bioperl has to guess the alphabet of the sequence, being either 'dna',
200 'rna', or 'protein'. The alphabet attribute is one of these three
201 possibilities.
202  
203 if( $seqobj->alphabet eq 'dna') {
204  
205 The $seqobj-E<gt>revcom method provides the reverse complement of the Seq
206 object as another Seq object. Thus, the $rev variable is a reference to
207 another Seq object. For example, one could repeat the above print line
208 for this Seq object (putting $rev in place of $seqobj). In this
209 case we are going to output the object into the file stream we built
210 earlier on.
211  
212 $rev = $seqobj->revcom;
213  
214 When we output it, we want the id of the outputted object
215 to be changed to "$id.rev", ie, with .rev on the end of the name. The
216 following lines retrieve the id of the sequence object, add .rev
217 to this and then set the display_id of the rev sequence object to
218 this. Notice that to set the display_id attribute you just need
219 call the same method, display_id(), with the new value as an argument.
220 Getting and setting values with the same method is common in Bioperl.
221  
222 $id = $seqobj->display_id();
223 $id = "$id.rev";
224 $rev->display_id($id);
225  
226 The write_seq method on the SeqIO output object, $seqout, writes the
227 $rev object to the filestream we built at the top of the script.
228 The filestream knows that it is outputting in fasta format, and
229 so it provides fasta output.
230  
231 $seqout->write_seq($rev);
232  
233 This block of code loops over sequence features in the sequence
234 object, trying to find ones who have been tagged as 'exon'.
235 Features have start and end attributes and can be outputted
236 in Genbank Flat File format, GFF, a standarized format for sequence
237 features.
238  
239 foreach $feat ( $seqobj->get_SeqFeatures() ) {
240 if( $feat->primary_tag eq 'exon' ) {
241 print STDOUT "Location ",$feat->start,":",
242 $feat->end," GFF[",$feat->gff_string,"]\n";
243 }
244 }
245  
246 The code above shows how a few Bio::Seq methods suffice to read, parse,
247 reformat and analyze sequences from a file. A full list of methods
248 available to Bio::Seq objects is shown below. Bear in mind that some of
249 these methods come from PrimarySeq objects, which are simpler
250 than Seq objects, stripped of features (see L<Bio::PrimarySeq> for
251 more information).
252  
253 # these methods return strings, and accept strings in some cases:
254  
255 $seqobj->seq(); # string of sequence
256 $seqobj->subseq(5,10); # part of the sequence as a string
257 $seqobj->accession_number(); # when there, the accession number
258 $seqobj->alphabet(); # one of 'dna','rna',or 'protein'
259 $seqobj->version() # when there, the version
260 $seqobj->keywords(); # when there, the Keywords line
261 $seqobj->length() # length
262 $seqobj->desc(); # description
263 $seqobj->primary_id(); # a unique id for this sequence regardless
264 # of its display_id or accession number
265 $seqobj->display_id(); # the human readable id of the sequence
266  
267 Some of these values map to fields in common formats. For example, The
268 display_id() method returns the LOCUS name of a Genbank entry,
269 the (\S+) following the E<gt> character in a Fasta file, the ID from
270 a SwissProt file, and so on. The desc() method will return the DEFINITION
271 line of a Genbank file, the description following the display_id in a
272 Fasta file, and the DE field in a SwissProt file.
273  
274 # the following methods return new Seq objects, but
275 # do not transfer features across to the new object:
276  
277 $seqobj->trunc(5,10) # truncation from 5 to 10 as new object
278 $seqobj->revcom # reverse complements sequence
279 $seqobj->translate # translation of the sequence
280  
281 # if new() can be called this method returns 1, else 0
282  
283 $seqobj->can_call_new
284  
285 # the following method determines if the given string will be accepted
286 # by the seq() method - if the string is acceptable then validate()
287 # returns 1, or 0 if not
288  
289 $seqobj->validate_seq($string)
290  
291 # the following method returns or accepts a Species object:
292  
293 $seqobj->species();
294  
295 Please see L<Bio::Species> for more information on this object.
296  
297 # the following method returns or accepts an Annotation object
298 # which in turn allows access to Annotation::Reference
299 # and Annotation::Comment objects:
300  
301 $seqobj->annotation();
302  
303 These annotations typically refer to entire sequences, unlike
304 features. See L<Bio::AnnotationCollectionI>,
305 L<Bio::Annotation::Collection>, L<Bio::Annotation::Reference>, and
306 L<Bio::Annotation::Comment> for details.
307  
308 It is also important to be able to describe defined portions of a
309 sequence. The combination of some description and the corresponding
310 sub-sequence is called a feature - an exon and its coordinates within
311 a gene is an example of a feature, or a domain within a protein.
312  
313 # the following methods return an array of SeqFeatureI objects:
314  
315 $seqobj->get_SeqFeatures # The 'top level' sequence features
316 $seqobj->get_all_SeqFeatures # All sequence features, including sub-seq
317 # features, such as features in an exon
318  
319 # to find out the number of features use:
320  
321 $seqobj->feature_count
322  
323 Here are just some of the methods available to SeqFeatureI objects:
324  
325 # these methods return numbers:
326  
327 $feat->start # start position (1 is the first base)
328 $feat->end # end position (2 is the second base)
329 $feat->strand # 1 means forward, -1 reverse, 0 not relevant
330  
331 # these methods return or accept strings:
332  
333 $feat->primary_tag # the name of the sequence feature, eg
334 # 'exon', 'glycoslyation site', 'TM domain'
335 $feat->source_tag # where the feature comes from, eg, 'EMBL_GenBank',
336 # or 'BLAST'
337  
338 # this method returns the more austere PrimarySeq object, not a
339 # Seq object - the main difference is that PrimarySeq objects do not
340 # themselves contain sequence features
341  
342 $feat->seq # the sequence between start,end on the
343 # correct strand of the sequence
344  
345 See L<Bio::PrimarySeq> for more details on PrimarySeq objects.
346  
347 # useful methods for feature comparisons, for start/end points
348  
349 $feat->overlaps($other) # do $feat and $other overlap?
350 $feat->contains($other) # is $other completely within $feat?
351 $feat->equals($other) # do $feat and $other completely agree?
352  
353 # one can also add features
354  
355 $seqobj->add_SeqFeature($feat) # returns 1 if successful
356  
357 # sub features. For complex join() statements, the feature
358 # is one sequence feature with many sub SeqFeatures
359  
360 $feat->sub_SeqFeature # returns array of sub seq features
361  
362 Please see L<Bio::SeqFeatureI> and L<Bio::SeqFeature::Generic>,
363 for more information on sequence features.
364  
365 It is worth mentioning that one can also retrieve the start and end
366 positions of a feature using a Bio::LocationI object:
367  
368 $location = $feat->location # $location is a Bio::LocationI object
369 $location->start; # start position
370 $location->end; # end position
371  
372 This is useful because one needs a Bio::Location::SplitLocationI object
373 in order to retrieve the coordinates inside the Genbank or EMBL join()
374 statements (e.g. "CDS join(51..142,273..495,1346..1474)"):
375  
376 if ( $feat->location->isa('Bio::Location::SplitLocationI') &&
377 $feat->primary_tag eq 'CDS' ) {
378 foreach $loc ( $feat->location->sub_Location ) {
379 print $loc->start . ".." . $loc->end . "\n";
380 }
381 }
382  
383 See L<Bio::LocationI> and L<Bio::Location::SplitLocationI> for more
384 information.
385  
386 =head1 Implemented Interfaces
387  
388 This class implements the following interfaces.
389  
390 =over 4
391  
392 =item Bio::SeqI
393  
394 Note that this includes implementing Bio::PrimarySeqI.
395  
396 =item Bio::IdentifiableI
397  
398 =item Bio::DescribableI
399  
400 =item Bio::AnnotatableI
401  
402 =item Bio::FeatureHolderI
403  
404 =back
405  
406 =head1 FEEDBACK
407  
408  
409 =head2 Mailing Lists
410  
411 User feedback is an integral part of the evolution of this and other
412 Bioperl modules. Send your comments and suggestions preferably to one
413 of the Bioperl mailing lists. Your participation is much appreciated.
414  
415 bioperl-l@bioperl.org - General discussion
416 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
417  
418 =head2 Support
419  
420 Please direct usage questions or support issues to the mailing list:
421  
422 I<bioperl-l@bioperl.org>
423  
424 rather than to the module maintainer directly. Many experienced and
425 reponsive experts will be able look at the problem and quickly
426 address it. Please include a thorough description of the problem
427 with code and data examples if at all possible.
428  
429 =head2 Reporting Bugs
430  
431 Report bugs to the Bioperl bug tracking system to help us keep track
432 the bugs and their resolution. Bug reports can be submitted via the
433 web:
434  
435 https://github.com/bioperl/bioperl-live/issues
436  
437 =head1 AUTHOR - Ewan Birney, inspired by Ian Korf objects
438  
439 Email birney@ebi.ac.uk
440  
441 =head1 CONTRIBUTORS
442  
443 Jason Stajich E<lt>jason@bioperl.orgE<gt>
444 Mark A. Jensen maj -at- fortinbras -dot- us
445  
446 =head1 APPENDIX
447  
448  
449 The rest of the documentation details each of the object
450 methods. Internal methods are usually preceded with a "_".
451  
452 =cut
453  
454 #'
455 # Let the code begin...
456  
457  
458 package Bio::Seq;
459 299 $Bio::Seq::VERSION = '1.7.8';
460 299 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
461  
462 299 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
463  
464 299 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
465 299 ▶use Bio::PrimarySeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
466  
467 299 ▶use base qw(Bio::Root::Root Bio::SeqI Bio::IdentifiableI Bio::DescribableI Bio::AnnotatableI Bio::FeatureHolderI Bio::AnnotationCollectionI);
Subroutine BEGIN: called CC=1 SCAR=0.0
468  
469 =head2 new
470  
471 Title : new
472 Usage : $seq = Bio::Seq->new( -seq => 'ATGGGGGTGGTGGTACCCT',
473 -id => 'human_id',
474 -accession_number => 'AL000012',
475 );
476  
477 Function: Returns a new Seq object from
478 basic constructors, being a string for the sequence
479 and strings for id and accession_number
480 Returns : a new Bio::Seq object
481  
482 =cut
483  
484 490 ▶sub new {
Subroutine new: called CC=15 SCAR=28.6
Pod documented
485 490 my($caller,@args) = @_;
486  
487 490 ▶ if( $caller ne 'Bio::Seq') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller ne "Bio::Seq") 342 148 490
488 342 ▶ $caller = ref($caller) if ref($caller);
Branch: 1 branch
BranchTrueFalseTotal
if ref $caller 0 342 342
489 }
490  
491 # we know our inherietance hierarchy
492 490 my $self = Bio::Root::Root->new(@args);
493 490 bless $self,$caller;
494  
495 # this is way too sneaky probably. We delegate the construction of
496 # the Seq object onto PrimarySeq and then pop primary_seq into
497 # our primary_seq slot
498  
499 490 my $pseq = Bio::PrimarySeq->new(@args);
500  
501 # as we have just made this, we know it is ok to set hash directly
502 # rather than going through the method
503  
504 490 $self->{'primary_seq'} = $pseq;
505  
506 # setting this array is now delayed until the final
507 # moment, again speed ups for non feature containing things
508 # $self->{'_as_feat'} = [];
509  
510  
511 490 my ($ann, $pid,$feat,$species) = &Bio::Root::RootI::_rearrange($self,[qw(ANNOTATION PRIMARY_ID FEATURES SPECIES)], @args);
512  
513 # for a number of cases - reading fasta files - these are never set. This
514 # gives a quick optimisation around testing things later on
515  
516 490 ▶ if( defined $ann || defined $pid || defined $feat || defined $species ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ann or defined $pid or defined $feat or defined $species) 262 228 490
Condition88%8/9
defined $ann or defined $pid or defined $feat or defined $species
l!l&&r!l&&!r
2620228
defined $ann or defined $pid or defined $feat
l!l&&r!l&&!r
2611228
defined $ann or defined $pid
l!l&&r!l&&!r
24219229
MC/DC75%3/4
defined $ann or defined $pid or defined $feat or defined $species
defined $ann defined $pid defined $feat defined $species
Truth table80%4/5
A or B or C or D
A= defined $annB= defined $pidC= defined $featD= defined $species
ABCDresult
1XXX1
01XX1
001X1
00011
00000
517 262 ▶ $pid && $self->primary_id($pid);
Branch: 1 branch
BranchTrueFalseTotal
$pid and $self->primary_id($pid) 125 137 262
518 262 ▶ $species && $self->species($species);
Branch: 1 branch
BranchTrueFalseTotal
$species and $self->species($species) 223 39 262
519 262 ▶ $ann && $self->annotation($ann);
Branch: 1 branch
BranchTrueFalseTotal
$ann and $self->annotation($ann) 242 20 262
520
521 262 ▶ if( defined $feat ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $feat) 193 69 262
522 193 ▶ if( ref($feat) !~ /ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($feat) =~ /ARRAY/i) { } 0 193 193
523 0 ▶ if( ref($feat) && $feat->isa('Bio::SeqFeatureI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $feat and $feat->isa('Bio::SeqFeatureI')) { } 0 0 0
Condition0%0/3
ref $feat and $feat->isa("Bio::SeqFeatureI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $feat and $feat->isa("Bio::SeqFeatureI")
ref $feat $feat->isa("Bio::SeqFeatureI")
Truth table0%0/3
A and B
A= ref $featB= $feat->isa("Bio::SeqFeatureI")
ABresult
0X0
100
111
524 0 $self->add_SeqFeature($feat);
525 } else {
526 0 $self->warn("Must specify a valid Bio::SeqFeatureI or ArrayRef of Bio::SeqFeatureI's with the -features init parameter for ".ref($self));
527 }
528 } else {
529 193 foreach my $feature ( @$feat ) {
530 9595 $self->add_SeqFeature($feature);
531 }
532 }
533 }
534 }
535  
536 490 return $self;
537 }
538  
539  
540 =head1 PrimarySeq interface
541  
542  
543 The PrimarySeq interface provides the basic sequence getting
544 and setting methods for on all sequences.
545  
546 These methods implement the Bio::PrimarySeq interface by delegating
547 to the primary_seq inside the object. This means that you
548 can use a Seq object wherever there is a PrimarySeq, and
549 of course, you are free to use these functions anyway.
550  
551 =cut
552  
553 =head2 seq
554  
555 Title : seq
556 Usage : $string = $obj->seq()
557 Function: Get/Set the sequence as a string of letters. The
558 case of the letters is left up to the implementer.
559 Suggested cases are upper case for proteins and lower case for
560 DNA sequence (IUPAC standard),
561 but implementations are suggested to keep an open mind about
562 case (some users... want mixed case!)
563 Returns : A scalar
564 Args : Optionally on set the new value (a string). An optional second
565 argument presets the alphabet (otherwise it will be guessed).
566 Both parameters may also be given in named parameter style
567 with -seq and -alphabet being the names.
568  
569 =cut
570  
571 813 ▶sub seq {
Subroutine seq: called CC=1 SCAR=0.0
Pod documented
572 813 return shift->primary_seq()->seq(@_);
573 }
574  
575  
576 =head2 validate_seq
577  
578 Title : validate_seq
579 Usage : if(! $seqobj->validate_seq($seq_str) ) {
580 print "sequence $seq_str is not valid for an object of
581 alphabet ",$seqobj->alphabet, "\n";
582 }
583 Function: Test that the given sequence is valid, i.e. contains only valid
584 characters. The allowed characters are all letters (A-Z) and '-','.',
585 '*','?','=' and '~'. Spaces are not valid. Note that this
586 implementation does not take alphabet() into account.
587 Returns : 1 if the supplied sequence string is valid, 0 otherwise.
588 Args : - Sequence string to be validated
589 - Boolean to throw an error if the sequence is invalid
590  
591 =cut
592  
593 0 ▶sub validate_seq {
Subroutine validate_seq: not called CC=1 SCAR=6.9
Pod documented
594 0 return shift->primary_seq()->validate_seq(@_);
595 }
596  
597  
598 =head2 length
599  
600 Title : length
601 Usage : $len = $seq->length()
602 Function:
603 Example :
604 Returns : Integer representing the length of the sequence.
605 Args : None
606  
607 =cut
608  
609 146 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
610 146 return shift->primary_seq()->length(@_);
611 }
612  
613  
614 =head1 Methods from the Bio::PrimarySeqI interface
615  
616 =head2 subseq
617  
618 Title : subseq
619 Usage : $substring = $obj->subseq(10,40);
620 Function: Returns the subseq from start to end, where the first base
621 is 1 and the number is inclusive, ie 1-2 are the first two
622 bases of the sequence
623  
624 Start cannot be larger than end but can be equal
625  
626 Returns : A string
627 Args : 2 integers
628  
629  
630 =cut
631  
632 109 ▶sub subseq {
Subroutine subseq: called CC=1 SCAR=0.0
Pod documented
633 109 return shift->primary_seq()->subseq(@_);
634 }
635  
636  
637 =head2 display_id
638  
639 Title : display_id
640 Usage : $id = $obj->display_id or $obj->display_id($newid);
641 Function: Gets or sets the display id, also known as the common name of
642 the Seq object.
643  
644 The semantics of this is that it is the most likely string
645 to be used as an identifier of the sequence, and likely to
646 have "human" readability. The id is equivalent to the LOCUS
647 field of the GenBank/EMBL databanks and the ID field of the
648 Swissprot/sptrembl database. In fasta format, the >(\S+) is
649 presumed to be the id, though some people overload the id
650 to embed other information. Bioperl does not use any
651 embedded information in the ID field, and people are
652 encouraged to use other mechanisms (accession field for
653 example, or extending the sequence object) to solve this.
654  
655 Notice that $seq->id() maps to this function, mainly for
656 legacy/convenience issues.
657 Returns : A string
658 Args : None or a new id
659  
660 =cut
661  
662 340 ▶sub display_id {
Subroutine display_id: called CC=1 SCAR=0.0
Pod documented
663 340 return shift->primary_seq->display_id(@_);
664 }
665  
666  
667 =head2 accession_number
668  
669 Title : accession_number
670 Usage : $unique_biological_key = $obj->accession_number;
671 Function: Returns the unique biological id for a sequence, commonly
672 called the accession_number. For sequences from established
673 databases, the implementors should try to use the correct
674 accession number. Notice that primary_id() provides the
675 unique id for the implementation, allowing multiple objects
676 to have the same accession number in a particular implementation.
677  
678 For sequences with no accession number, this method should return
679 "unknown".
680  
681 Can also be used to set the accession number.
682 Example : $key = $seq->accession_number or $seq->accession_number($key)
683 Returns : A string
684 Args : None or an accession number
685  
686 =cut
687  
688 185 ▶sub accession_number {
Subroutine accession_number: called CC=1 SCAR=0.0
Pod documented
689 185 return shift->primary_seq->accession_number(@_);
690 }
691  
692  
693 =head2 desc
694  
695 Title : desc
696 Usage : $seqobj->desc($string) or $seqobj->desc()
697 Function: Sets or gets the description of the sequence
698 Example :
699 Returns : The description
700 Args : The description or none
701  
702 =cut
703  
704 123 ▶sub desc {
Subroutine desc: called CC=1 SCAR=0.0
Pod documented
705 123 return shift->primary_seq->desc(@_);
706 }
707  
708  
709 =head2 primary_id
710  
711 Title : primary_id
712 Usage : $unique_implementation_key = $obj->primary_id;
713 Function: Returns the unique id for this object in this
714 implementation. This allows implementations to manage
715 their own object ids in a way the implementation can control
716 clients can expect one id to map to one object.
717  
718 For sequences with no natural id, this method should return
719 a stringified memory location.
720  
721 Can also be used to set the primary_id (or unset to undef).
722  
723 [Note this method name is likely to change in 1.3]
724  
725 Example : $id = $seq->primary_id or $seq->primary_id($id)
726 Returns : A string
727 Args : None or an id, or undef to unset the primary id.
728  
729 =cut
730  
731 178 ▶sub primary_id {
Subroutine primary_id: called CC=1 SCAR=0.0
Pod documented
732 # Note: this used to not delegate to the primary seq. This is
733 # really bad in very subtle ways. E.g., if you created the object
734 # with a primary id given to the constructor and then later you
735 # change the primary id, if this method wouldn't delegate you'd
736 # have different values for primary id in the PrimarySeq object
737 # compared to this instance. Not good.
738  
739 # I can't remember why not delegating was ever deemed
740 # advantageous, but I hereby claim that its problems far outweigh
741 # its advantages, if there are any. Convince me otherwise if you
742 # disagree. HL 2004/08/05
743  
744 178 return shift->primary_seq->primary_id(@_);
745 }
746  
747  
748 =head2 can_call_new
749  
750 Title : can_call_new
751 Usage : if ( $obj->can_call_new ) {
752 $newobj = $obj->new( %param );
753 }
754 Function: can_call_new returns 1 or 0 depending
755 on whether an implementation allows new
756 constructor to be called. If a new constructor
757 is allowed, then it should take the followed hashed
758 constructor list.
759  
760 $myobject->new( -seq => $sequence_as_string,
761 -display_id => $id
762 -accession_number => $accession
763 -alphabet => 'dna',
764 );
765 Example :
766 Returns : 1 or 0
767 Args : None
768  
769 =cut
770  
771 3 ▶sub can_call_new {
Subroutine can_call_new: called CC=1 SCAR=0.0
Pod documented
772 3 return 1;
773 }
774  
775  
776 =head2 alphabet
777  
778 Title : alphabet
779 Usage : if ( $obj->alphabet eq 'dna' ) { /Do Something/ }
780 Function: Get/Set the type of sequence being one of
781 'dna', 'rna' or 'protein'. This is case sensitive.
782  
783 This is not called <type> because this would cause
784 upgrade problems from the 0.5 and earlier Seq objects.
785  
786 Returns : A string either 'dna','rna','protein'. NB - the object must
787 make a call of the type - if there is no type specified it
788 has to guess.
789 Args : optional string to set : 'dna' | 'rna' | 'protein'
790  
791 =cut
792  
793 386 ▶sub alphabet {
Subroutine alphabet: called CC=3 SCAR=11.0
Pod documented
794 386 my $self = shift;
795 386 ▶ return $self->primary_seq->alphabet(@_) if @_ && defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if @_ and defined $_[0] 76 310 386
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
310076
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
796 310 return $self->primary_seq->alphabet();
797 }
798  
799  
800 =head2 is_circular
801  
802 Title : is_circular
803 Usage : if( $obj->is_circular) { /Do Something/ }
804 Function: Returns true if the molecule is circular
805 Returns : Boolean value
806 Args : none
807  
808 =cut
809  
810 325 ▶sub is_circular {
Subroutine is_circular: called CC=1 SCAR=0.0
Pod documented
811 325 return shift->primary_seq()->is_circular(@_);
812 }
813  
814  
815 =head1 Methods for Bio::IdentifiableI compliance
816  
817 =head2 object_id
818  
819 Title : object_id
820 Usage : $string = $obj->object_id()
821 Function: a string which represents the stable primary identifier
822 in this namespace of this object. For DNA sequences this
823 is its accession_number, similarly for protein sequences
824  
825 This is aliased to accession_number().
826 Returns : A scalar
827  
828 =cut
829  
830 2 ▶sub object_id {
Subroutine object_id: called CC=1 SCAR=0.0
Pod documented
831 2 return shift->accession_number(@_);
832 }
833  
834  
835 =head2 version
836  
837 Title : version
838 Usage : $version = $obj->version()
839 Function: a number which differentiates between versions of
840 the same object. Higher numbers are considered to be
841 later and more relevant, but a single object described
842 the same identifier should represent the same concept
843  
844 Returns : A number
845  
846 =cut
847  
848 34 ▶sub version{
Subroutine version: called CC=1 SCAR=0.0
Pod documented
849 34 return shift->primary_seq->version(@_);
850 }
851  
852  
853 =head2 authority
854  
855 Title : authority
856 Usage : $authority = $obj->authority()
857 Function: a string which represents the organisation which
858 granted the namespace, written as the DNS name for
859 organisation (eg, wormbase.org)
860  
861 Returns : A scalar
862  
863 =cut
864  
865 2 ▶sub authority {
Subroutine authority: called CC=1 SCAR=0.0
Pod documented
866 2 return shift->primary_seq()->authority(@_);
867 }
868  
869  
870 =head2 namespace
871  
872 Title : namespace
873 Usage : $string = $obj->namespace()
874 Function: A string representing the name space this identifier
875 is valid in, often the database name or the name
876 describing the collection
877  
878 Returns : A scalar
879  
880 =cut
881  
882 18 ▶sub namespace{
Subroutine namespace: called CC=1 SCAR=0.0
Pod documented
883 18 return shift->primary_seq()->namespace(@_);
884 }
885  
886  
887 =head1 Methods for Bio::DescribableI compliance
888  
889 =head2 display_name
890  
891 Title : display_name
892 Usage : $string = $obj->display_name()
893 Function: A string which is what should be displayed to the user
894 the string should have no spaces (ideally, though a cautious
895 user of this interface would not assume this) and should be
896 less than thirty characters (though again, double checking
897 this is a good idea)
898  
899 This is aliased to display_id().
900 Returns : A scalar
901  
902 =cut
903  
904 1 ▶sub display_name {
Subroutine display_name: called CC=1 SCAR=0.0
Pod documented
905 1 return shift->display_id(@_);
906 }
907  
908 =head2 description
909  
910 Title : description
911 Usage : $string = $obj->description()
912 Function: A text string suitable for displaying to the user a
913 description. This string is likely to have spaces, but
914 should not have any newlines or formatting - just plain
915 text. The string should not be greater than 255 characters
916 and clients can feel justified at truncating strings at 255
917 characters for the purposes of display
918  
919 This is aliased to desc().
920 Returns : A scalar
921  
922 =cut
923  
924 6 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
925 6 return shift->desc(@_);
926 }
927  
928  
929 =head1 Methods for implementing Bio::AnnotatableI
930  
931 =head2 annotation
932  
933 Title : annotation
934 Usage : $ann = $seq->annotation or
935 $seq->annotation($ann)
936 Function: Gets or sets the annotation
937 Returns : Bio::AnnotationCollectionI object
938 Args : None or Bio::AnnotationCollectionI object
939  
940 See L<Bio::AnnotationCollectionI> and L<Bio::Annotation::Collection>
941 for more information
942  
943 =cut
944  
945 2517 ▶sub annotation {
Subroutine annotation: called CC=4 SCAR=13.9
Pod documented
946 2517 my ($obj,$value) = @_;
947 2517 ▶ if( defined $value ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 287 2230 2517
elsif (not defined $obj->{'_annotation'}) { } 29 2201 2230
948 287 ▶ $obj->throw("object of class ".ref($value)." does not implement ".
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::AnnotationCollectionI") 0 287 287
949 "Bio::AnnotationCollectionI. Too bad.")
950 unless $value->isa("Bio::AnnotationCollectionI");
951 287 $obj->{'_annotation'} = $value;
952 } elsif( ! defined $obj->{'_annotation'}) {
953 29 $obj->{'_annotation'} = Bio::Annotation::Collection->new();
954 }
955 2517 return $obj->{'_annotation'};
956 }
957  
958  
959 =head1 Methods for delegating Bio::AnnotationCollectionI
960  
961 =head2 get_Annotations()
962  
963 Usage : my @annotations = $seq->get_Annotations('key')
964 Function: Retrieves all the Bio::AnnotationI objects for a specific key
965 for this object
966 Returns : list of Bio::AnnotationI - empty if no objects stored for a key
967 Args : string which is key for annotations
968  
969 =cut
970  
971 17 ▶sub get_Annotations { shift->annotation->get_Annotations(@_); }
Subroutine get_Annotations: called CC=1 SCAR=0.0
Pod documented
972  
973  
974 =head2 add_Annotation()
975  
976 Usage : $seq->add_Annotation('reference',$object);
977 $seq->add_Annotation($object,'Bio::MyInterface::DiseaseI');
978 $seq->add_Annotation($object);
979 $seq->add_Annotation('disease',$object,'Bio::MyInterface::DiseaseI');
980 Function: Adds an annotation for a specific key for this sequence object.
981  
982 If the key is omitted, the object to be added must provide a value
983 via its tagname().
984  
985 If the archetype is provided, this and future objects added under
986 that tag have to comply with the archetype and will be rejected
987 otherwise.
988  
989 Returns : none
990 Args : annotation key ('disease', 'dblink', ...)
991 object to store (must be Bio::AnnotationI compliant)
992 [optional] object archetype to map future storage of object
993 of these types to
994  
995 =cut
996  
997 8 ▶sub add_Annotation { shift->annotation->add_Annotation(@_) }
Subroutine add_Annotation: called CC=1 SCAR=0.0
Pod documented
998  
999  
1000 =head2 remove_Annotations()
1001  
1002 Usage : $seq->remove_Annotations()
1003 Function: Remove the annotations for the specified key from this sequence
1004 object
1005 Returns : an list of Bio::AnnotationI compliant objects which were stored
1006 under the given key(s) for this sequence object
1007 Args : the key(s) (tag name(s), one or more strings) for which to
1008 remove annotations (optional; if none given, flushes all
1009 annotations)
1010  
1011 =cut
1012  
1013 0 ▶sub remove_Annotations { shift->annotation->remove_Annotations(@_) }
Subroutine remove_Annotations: not called CC=1 SCAR=6.9
Pod documented
1014  
1015  
1016 =head2 get_num_of_annotations()
1017  
1018 Usage : my $count = $seq->get_num_of_annotations()
1019 Alias : num_Annotations
1020 Function: Returns the count of all annotations stored for this sequence
1021 object
1022 Returns : integer
1023 Args : none
1024  
1025 =cut
1026  
1027 0 ▶sub get_num_of_annotations { shift->annotation->get_num_of_annotations(@_) }
Subroutine get_num_of_annotations: not called CC=1 SCAR=6.9
Pod documented
1028 0 ▶sub num_Annotations { shift->get_num_of_annotations }; #DWYM
Subroutine num_Annotations: not called CC=1 SCAR=6.9
Pod undocumented
1029  
1030  
1031 =head1 Methods to implement Bio::FeatureHolderI
1032  
1033 This includes methods for retrieving, adding, and removing features.
1034  
1035 =cut
1036  
1037 =head2 get_SeqFeatures
1038  
1039 Title : get_SeqFeatures
1040 Usage :
1041 Function: Get the feature objects held by this feature holder.
1042  
1043 Features which are not top-level are subfeatures of one or
1044 more of the returned feature objects, which means that you
1045 must traverse the subfeature arrays of each top-level
1046 feature object in order to traverse all features associated
1047 with this sequence.
1048  
1049 Specific features can be obtained by primary tag, specified in
1050 the argument.
1051  
1052 Use get_all_SeqFeatures() if you want the feature tree
1053 flattened into one single array.
1054  
1055 Example : my @feats = $seq->get_SeqFeatures or
1056 my @genefeats = $seq->get_SeqFeatures('gene')
1057 Returns : an array of Bio::SeqFeatureI implementing objects
1058 Args : [optional] string (feature tag)
1059  
1060 =cut
1061  
1062 181 ▶sub get_SeqFeatures{
Subroutine get_SeqFeatures: called CC=4 SCAR=15.8
Pod documented
1063 181 my $self = shift;
1064 181 my $tag = shift;
1065  
1066 181 ▶ if( !defined $self->{'_as_feat'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_as_feat"}) 38 143 181
1067 38 $self->{'_as_feat'} = [];
1068 }
1069 181 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) { } 0 181 181
1070 0 ▶ return map { $_->primary_tag eq $tag ? $_ : () } @{$self->{'_as_feat'}};
Branch: 1 branch
BranchTrueFalseTotal
$_->primary_tag eq $tag ? : 0 0 0
1071 }
1072 else {
1073 181 return @{$self->{'_as_feat'}};
1074 }
1075 }
1076  
1077  
1078 =head2 get_all_SeqFeatures
1079  
1080 Title : get_all_SeqFeatures
1081 Usage : @feat_ary = $seq->get_all_SeqFeatures();
1082 Function: Returns the tree of feature objects attached to this
1083 sequence object flattened into one single array. Top-level
1084 features will still contain their subfeature-arrays, which
1085 means that you will encounter subfeatures twice if you
1086 traverse the subfeature tree of the returned objects.
1087  
1088 Use get_SeqFeatures() if you want the array to contain only
1089 the top-level features.
1090  
1091 Returns : An array of Bio::SeqFeatureI implementing objects.
1092 Args : None
1093  
1094 =cut
1095  
1096 # this implementation is inherited from FeatureHolderI
1097  
1098 =head2 feature_count
1099  
1100 Title : feature_count
1101 Usage : $seq->feature_count()
1102 Function: Return the number of SeqFeatures attached to a sequence
1103 Returns : integer representing the number of SeqFeatures
1104 Args : None
1105  
1106 =cut
1107  
1108 10 ▶sub feature_count {
Subroutine feature_count: called CC=2 SCAR=6.9
Pod documented
1109 10 my ($self) = @_;
1110  
1111 10 ▶ if (defined($self->{'_as_feat'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_as_feat'}) { } 9 1 10
1112 9 return ($#{$self->{'_as_feat'}} + 1);
1113 } else {
1114 1 return 0;
1115 }
1116 }
1117  
1118  
1119 =head2 add_SeqFeature
1120  
1121 Title : add_SeqFeature
1122 Usage : $seq->add_SeqFeature($feat);
1123 Function: Adds the given feature object to the feature array of this
1124 sequence. The object passed is required to implement the
1125 Bio::SeqFeatureI interface.
1126 The 'EXPAND' qualifier (see L<Bio::FeatureHolderI>) is supported, but
1127 has no effect,
1128 Returns : 1 on success
1129 Args : A Bio::SeqFeatureI implementing object.
1130  
1131 =cut
1132  
1133 11899 ▶sub add_SeqFeature {
Subroutine add_SeqFeature: called CC=7 SCAR=20.6
Pod documented
1134 11899 my ($self, @feat) = @_;
1135  
1136 11899 ▶ $self->{'_as_feat'} = [] unless $self->{'_as_feat'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_as_feat"} 209 11690 11899
1137  
1138 11899 ▶ if (scalar @feat > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @feat > 1) 0 11899 11899
1139 0 Carp::carp('Providing an array of features to Bio::Seq add_SeqFeature()'
1140 . ' is deprecated and will be removed in a future version.'
1141 . ' Add a single feature at a time instead.');
1142 }
1143  
1144 11899 for my $feat ( @feat ) {
1145  
1146 11899 ▶ next if $feat eq 'EXPAND'; # Need to support it for FeatureHolderI compliance
Branch: 1 branch
BranchTrueFalseTotal
if $feat eq "EXPAND" 0 11899 11899
1147  
1148 11899 ▶ if( !$feat->isa("Bio::SeqFeatureI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($feat->isa("Bio::SeqFeatureI")) 0 11899 11899
1149 0 $self->throw("Expected a Bio::SeqFeatureI object, but got a $feat.");
1150 }
1151  
1152 # make sure we attach ourselves to the feature if the feature wants it
1153 11899 my $aseq = $self->primary_seq;
1154 11899 ▶ $feat->attach_seq($aseq) if $aseq;
Branch: 1 branch
BranchTrueFalseTotal
if $aseq 11899 0 11899
1155  
1156 11899 push(@{$self->{'_as_feat'}},$feat);
1157 }
1158 11899 return 1;
1159 }
1160  
1161  
1162 =head2 remove_SeqFeatures
1163  
1164 Title : remove_SeqFeatures
1165 Usage : $seq->remove_SeqFeatures();
1166 Function: Removes all attached SeqFeatureI objects or those with the
1167 specified primary tag
1168 Example : my @gene_feats = $seq->remove_seqFeatures('gene') or
1169 my @feats = $seq->remove_seqFeatures()
1170 Returns : The array of Bio::SeqFeatureI objects removed from the sequence
1171 Args : None, or a feature primary tag
1172  
1173 =cut
1174  
1175 16 ▶sub remove_SeqFeatures {
Subroutine remove_SeqFeatures: called CC=3 SCAR=11.0
Pod documented
1176 16 my ( $self, $tag ) = @_;
1177 16 ▶ return () unless $self->{'_as_feat'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_as_feat"} 0 16 16
1178  
1179 16 ▶ if ( $tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) { } 1 15 16
1180 1 my @selected_feats = grep { $_->primary_tag eq $tag } @{ $self->{'_as_feat'} };
1181 1 my @unselected_feats = grep { $_->primary_tag ne $tag } @{ $self->{'_as_feat'} };
1182 1 $self->{'_as_feat'} = \@unselected_feats;
1183 1 return @selected_feats;
1184 }
1185 else {
1186 15 my @all_feats = @{ $self->{'_as_feat'} };
1187 15 $self->{'_as_feat'} = [];
1188 15 return @all_feats;
1189 }
1190 }
1191  
1192 =head1 Methods provided in the Bio::PrimarySeqI interface
1193  
1194 These methods are inherited from the PrimarySeq interface
1195 and work as one expects, building new Bio::Seq objects
1196 or other information as expected. See L<Bio::PrimarySeq>
1197 for more information.
1198  
1199 Sequence Features are B<not> transferred to the new objects.
1200 To reverse complement and include the features use
1201 L<Bio::SeqUtils::revcom_with_features>.
1202  
1203 =head2 revcom
1204  
1205 Title : revcom
1206 Usage : $rev = $seq->revcom()
1207 Function: Produces a new Bio::Seq object which
1208 is the reversed complement of the sequence. For protein
1209 sequences this throws an exception of "Sequence is a protein.
1210 Cannot revcom"
1211  
1212 The id is the same id as the original sequence, and the
1213 accession number is also identical. If someone wants to track
1214 that this sequence has be reversed, it needs to define its own
1215 extensions
1216  
1217 To do an in-place edit of an object you can go:
1218  
1219 $seq = $seq->revcom();
1220  
1221 This of course, causes Perl to handle the garbage collection of
1222 the old object, but it is roughly speaking as efficient as an
1223 in-place edit.
1224  
1225 Returns : A new (fresh) Bio::Seq object
1226 Args : None
1227  
1228 =head2 trunc
1229  
1230 Title : trunc
1231 Usage : $subseq = $myseq->trunc(10,100);
1232 Function: Provides a truncation of a sequence
1233  
1234 Example :
1235 Returns : A fresh Seq object
1236 Args : A Seq object
1237  
1238 =head2 id
1239  
1240 Title : id
1241 Usage : $id = $seq->id()
1242 Function: This is mapped on display_id
1243 Returns : value of display_id()
1244 Args : [optional] value to update display_id
1245  
1246 =cut
1247  
1248 68 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
1249 68 return shift->display_id(@_);
1250 }
1251  
1252  
1253 =head1 Seq only methods
1254  
1255 These methods are specific to the Bio::Seq object, and not
1256 found on the Bio::PrimarySeq object
1257  
1258 =head2 primary_seq
1259  
1260 Title : primary_seq
1261 Usage : $seq->primary_seq or $seq->primary_seq($newval)
1262 Function: Get or set a PrimarySeq object
1263 Example :
1264 Returns : PrimarySeq object
1265 Args : None or PrimarySeq object
1266  
1267 =cut
1268  
1269 14612 ▶sub primary_seq {
Subroutine primary_seq: called CC=5 SCAR=17.8
Pod documented
1270 14612 my ($obj,$value) = @_;
1271  
1272 14612 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 25 14587 14612
1273 25 ▶ if( ! ref $value || ! $value->isa('Bio::PrimarySeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value and $value->isa("Bio::PrimarySeqI")) 0 25 25
Condition33%1/3
ref $value and $value->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
0025
MC/DC0%0/2
ref $value and $value->isa("Bio::PrimarySeqI")
ref $value $value->isa("Bio::PrimarySeqI")
Truth table33%1/3
A and B
A= ref $valueB= $value->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
1274 0 $obj->throw("$value is not a Bio::PrimarySeq compliant object");
1275 }
1276  
1277 25 $obj->{'primary_seq'} = $value;
1278 # descend down over all seqfeature objects, seeing whether they
1279 # want an attached seq.
1280  
1281 25 foreach my $sf ( $obj->get_SeqFeatures() ) {
1282 0 $sf->attach_seq($value);
1283 }
1284  
1285 }
1286 14612 return $obj->{'primary_seq'};
1287  
1288 }
1289  
1290  
1291 =head2 species
1292  
1293 Title : species
1294 Usage : $species = $seq->species() or $seq->species($species)
1295 Function: Gets or sets the species
1296 Returns : L<Bio::Species> object
1297 Args : None or L<Bio::Species> object
1298  
1299 See L<Bio::Species> for more information
1300  
1301 =cut
1302  
1303 449 ▶sub species {
Subroutine species: called CC=2 SCAR=6.9
Pod documented
1304 449 my ($self, $species) = @_;
1305 449 ▶ if ($species) {
Branch: 1 branch
BranchTrueFalseTotal
if ($species) { } 231 218 449
1306 231 $self->{'species'} = $species;
1307 } else {
1308 218 return $self->{'species'};
1309 }
1310 }
1311  
1312  
1313 # Internal methods follow...
1314  
1315 # keep AUTOLOAD happy
1316 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
1317  
1318 ############################################################################
1319 # aliases due to name changes or to compensate for our lack of consistency #
1320 ############################################################################
1321  
1322 # in all other modules we use the object in the singular --
1323 # lack of consistency sucks
1324 299 *flush_SeqFeature = \&remove_SeqFeatures;
1325 299 *flush_SeqFeatures = \&remove_SeqFeatures;
1326  
1327 # this is now get_SeqFeatures() (from FeatureHolderI)
1328 299 *top_SeqFeatures = \&get_SeqFeatures;
1329  
1330 # this is now get_all_SeqFeatures() in FeatureHolderI
1331 16 ▶sub all_SeqFeatures{
Subroutine all_SeqFeatures: called CC=1 SCAR=0.0
Pod undocumented
1332 16 return shift->get_all_SeqFeatures(@_);
1333 }
1334  
1335 0 ▶sub accession {
Subroutine accession: not called CC=1 SCAR=6.9
Pod undocumented
1336 0 my $self = shift;
1337 0 $self->warn(ref($self)."::accession is deprecated, ".
1338 "use accession_number() instead");
1339 0 return $self->accession_number(@_);
1340 }
1341  
1342 299 1;
« Bio/Seq/RichSeq.pm ↑ Summary Bio/Search/Hit/BlastPullHit.pm »