File Coverage

Bio/SeqIO/lasergene.pm
Criterion Covered Total %
statement 38 41 92.6
branch 16 18 88.8
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 62 68 91.1


line stmt bran cond sub pod time code
1             #-----------------------------------------5~------------------------------------
2             # PACKAGE : Bio::SeqIO::lasergene
3             # AUTHOR : Malcolm Cook
4             # CREATED : Feb 16 1999
5             #
6             # _History_
7             #
8             # This code is based on the Bio::SeqIO::raw module with
9             # the necessary minor tweaks necessary to get it to read (only)
10             # Lasergene formatted sequences
11             #
12             # Cleaned up by Torsten Seemann June 2006
13              
14             # POD documentation - main docs before the code
15              
16             =head1 NAME
17              
18             Bio::SeqIO::lasergene - Lasergene sequence file input/output stream
19              
20             =head1 SYNOPSIS
21              
22             Do not use this module directly. Use it via the L class.
23              
24             =head1 DESCRIPTION
25              
26             This object can product Bio::Seq::RichSeq objects from Lasergene sequence files.
27              
28             IT DOES NOT PARSE ANY ATTIBUTE VALUE PAIRS IN THE HEADER OF THE LASERGENE FORMATTED FILE.
29              
30             IT DOES NOT WRITE THESE FILES EITHER.
31              
32             =head1 REFERENCES
33              
34             https://www.dnastar.com/products/lasergene.php
35              
36             =head1 FEEDBACK
37              
38             =head2 Mailing Lists
39              
40             User feedback is an integral part of the evolution of this and other
41             Bioperl modules. Send your comments and suggestions preferably to one
42             of the Bioperl mailing lists. Your participation is much appreciated.
43              
44             bioperl-l@bioperl.org - General discussion
45             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46              
47             =head2 Support
48              
49             Please direct usage questions or support issues to the mailing list:
50              
51             I
52              
53             rather than to the module maintainer directly. Many experienced and
54             reponsive experts will be able look at the problem and quickly
55             address it. Please include a thorough description of the problem
56             with code and data examples if at all possible.
57              
58             =head2 Reporting Bugs
59              
60             Report bugs to the Bioperl bug tracking system to help us keep track
61             of the bugs and their resolution. Bug reports can be submitted via
62             the web:
63              
64             https://github.com/bioperl/bioperl-live/issues
65              
66             =head1 AUTHORS
67              
68             Torsten Seemann - torsten.seemann AT infotech.monash.edu.au
69             Malcolm Cook - mec AT stowers-institute.org
70              
71             =head1 APPENDIX
72              
73             The rest of the documentation details each of the object methods.
74             Internal methods are usually preceded with a _
75              
76             =cut
77              
78              
79             # Let the code begin...
80              
81             package Bio::SeqIO::lasergene;
82              
83 1     1   351 use strict;
  1         1  
  1         24  
84              
85 1     1   3 use base qw(Bio::SeqIO);
  1         1  
  1         325  
86              
87             =head2 next_seq
88              
89             Title : next_seq
90             Usage : $seq = $stream->next_seq()
91             Function: returns the next sequence in the stream
92             Returns : Bio::Seq object
93             Args : none
94              
95             =cut
96              
97 1     1   372 use Bio::Seq;
  1         2  
  1         28  
98 1     1   4 use Bio::Annotation::Collection;
  1         1  
  1         17  
99 1     1   241 use Bio::Annotation::Comment;
  1         2  
  1         201  
100              
101             sub next_seq {
102 5     5 1 902 my ($self) = @_;
103              
104 5         4 my $state = 0;
105 5         7 my @comment;
106             my @sequence;
107              
108 5         11 while (my $line = $self->_readline) {
109 38 100       45 $state = 1 if $state == 0;
110 38         33 chomp $line;
111 38 100       69 next if $line =~ m/^\s*$/; # skip blank lines
112              
113 34 100       58 if ($line eq '^^') { # end of a comment or sequence
    100          
    50          
114 5         3 $state++;
115 5 100       10 last if $state > 2; # we have comment and sequence so exit
116             }
117             elsif ($state == 1) { # another piece of comment
118 19         36 push @comment, $line;
119             }
120             elsif ($state == 2) { # another piece of sequence
121 10         18 push @sequence, $line
122             }
123             else {
124 0         0 $self->throw("unreachable state reached, probable bug!");
125             }
126             }
127              
128             # return quietly if there was nothing in the file
129 5 100       14 return if $state == 0;
130              
131             # ensure we read some comment and some sequence
132 4 100       5 if ($state < 2) {
133 1         6 $self->throw("unexpected end of file");
134             }
135              
136 3         7 my $sequence = join('', @sequence);
137             # print STDERR "SEQ=[[$sequence]]\n";
138 3 50       5 $sequence or $self->throw("empty sequence in lasergene file");
139 3         13 my $seq = Bio::Seq->new(-seq => $sequence);
140              
141 3         7 my $comment = join('; ', @comment);
142             # print STDERR "COM=[[$comment]]\n";
143 3         10 my $anno = Bio::Annotation::Collection->new;
144 3         11 $anno->add_Annotation('comment', Bio::Annotation::Comment->new(-text => $comment) );
145 3         8 $seq->annotation($anno);
146              
147 3         12 return $seq;
148             }
149              
150             =head2 write_seq (NOT IMPLEMENTED)
151              
152             Title : write_seq
153             Usage : $stream->write_seq($seq)
154             Function: writes the $seq object into the stream
155             Returns : 1 for success and 0 for error
156             Args : Array of Bio::PrimarySeqI objects
157              
158             =cut
159              
160             sub write_seq {
161 0     0 1   my ($self, @seq) = @_;
162 0           $self->throw("write_seq() is not implemented for the lasergene format.");
163             }
164              
165              
166             1;
167