t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / SeqIO / lasergene.pm
blobbc2513b1ba350c1bec846ef9f7704c9aa0cf8dc1
1 #-----------------------------------------5~------------------------------------
2 # PACKAGE : Bio::SeqIO::lasergene
3 # AUTHOR : Malcolm Cook <mec@stowers-institute.org>
4 # CREATED : Feb 16 1999
6 # _History_
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
12 # Cleaned up by Torsten Seemann June 2006
14 # POD documentation - main docs before the code
16 =head1 NAME
18 Bio::SeqIO::lasergene - Lasergene sequence file input/output stream
20 =head1 SYNOPSIS
22 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
24 =head1 DESCRIPTION
26 This object can product Bio::Seq::RichSeq objects from Lasergene sequence files.
28 IT DOES NOT PARSE ANY ATTRIBUTE VALUE PAIRS IN THE HEADER OF THE LASERGENE FORMATTED FILE.
30 IT DOES NOT WRITE THESE FILES EITHER.
32 =head1 REFERENCES
34 https://www.dnastar.com/products/lasergene.php
36 =head1 FEEDBACK
38 =head2 Mailing Lists
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.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
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.
58 =head2 Reporting Bugs
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:
64 https://github.com/bioperl/bioperl-live/issues
66 =head1 AUTHORS
68 Torsten Seemann - torsten.seemann AT infotech.monash.edu.au
69 Malcolm Cook - mec AT stowers-institute.org
71 =head1 APPENDIX
73 The rest of the documentation details each of the object methods.
74 Internal methods are usually preceded with a _
76 =cut
79 # Let the code begin...
81 package Bio::SeqIO::lasergene;
83 use strict;
85 use base qw(Bio::SeqIO);
87 =head2 next_seq
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
95 =cut
97 use Bio::Seq;
98 use Bio::Annotation::Collection;
99 use Bio::Annotation::Comment;
101 sub next_seq {
102 my ($self) = @_;
104 my $state = 0;
105 my @comment;
106 my @sequence;
108 while (my $line = $self->_readline) {
109 $state = 1 if $state == 0;
110 chomp $line;
111 next if $line =~ m/^\s*$/; # skip blank lines
113 if ($line eq '^^') { # end of a comment or sequence
114 $state++;
115 last if $state > 2; # we have comment and sequence so exit
117 elsif ($state == 1) { # another piece of comment
118 push @comment, $line;
120 elsif ($state == 2) { # another piece of sequence
121 push @sequence, $line
123 else {
124 $self->throw("unreachable state reached, probable bug!");
128 # return quietly if there was nothing in the file
129 return if $state == 0;
131 # ensure we read some comment and some sequence
132 if ($state < 2) {
133 $self->throw("unexpected end of file");
136 my $sequence = join('', @sequence);
137 # print STDERR "SEQ=[[$sequence]]\n";
138 $sequence or $self->throw("empty sequence in lasergene file");
139 my $seq = Bio::Seq->new(-seq => $sequence);
141 my $comment = join('; ', @comment);
142 # print STDERR "COM=[[$comment]]\n";
143 my $anno = Bio::Annotation::Collection->new;
144 $anno->add_Annotation('comment', Bio::Annotation::Comment->new(-text => $comment) );
145 $seq->annotation($anno);
147 return $seq;
150 =head2 write_seq (NOT IMPLEMENTED)
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
158 =cut
160 sub write_seq {
161 my ($self, @seq) = @_;
162 $self->throw("write_seq() is not implemented for the lasergene format.");