merge upstream
[bioperl-live.git] / Bio / AlignIO / mase.pm
blobc81256456b64d35dc8ffc318b7eb1ad7eecb2c7c
2 # BioPerl module for Bio::AlignIO::mase
4 # based on the Bio::SeqIO::mase module
5 # by Ewan Birney <birney@ebi.ac.uk>
6 # and Lincoln Stein <lstein@cshl.org>
8 # and the SimpleAlign.pm module of Ewan Birney
10 # Copyright Peter Schattner
12 # You may distribute this module under the same terms as perl itself
13 # _history
14 # September 5, 2000
15 # POD documentation - main docs before the code
17 =head1 NAME
19 Bio::AlignIO::mase - mase sequence input/output stream
21 =head1 SYNOPSIS
23 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
25 =head1 DESCRIPTION
27 This object can transform L<Bio::Align::AlignI> objects to and from mase flat
28 file databases.
30 =head1 FEEDBACK
32 =head2 Support
34 Please direct usage questions or support issues to the mailing list:
36 I<bioperl-l@bioperl.org>
38 rather than to the module maintainer directly. Many experienced and
39 reponsive experts will be able look at the problem and quickly
40 address it. Please include a thorough description of the problem
41 with code and data examples if at all possible.
43 =head2 Reporting Bugs
45 Report bugs to the Bioperl bug tracking system to help us keep track
46 the bugs and their resolution. Bug reports can be submitted via the
47 web:
49 https://github.com/bioperl/bioperl-live/issues
51 =head1 AUTHORS - Peter Schattner
53 Email: schattner@alum.mit.edu
56 =head1 APPENDIX
58 The rest of the documentation details each of the object
59 methods. Internal methods are usually preceded with a _
61 =cut
63 # Let the code begin...
65 package Bio::AlignIO::mase;
66 use strict;
69 use base qw(Bio::AlignIO);
72 =head2 next_aln
74 Title : next_aln
75 Usage : $aln = $stream->next_aln()
76 Function: returns the next alignment in the stream.
77 Returns : L<Bio::Align::AlignI> object
78 Args : NONE
80 =cut
82 sub next_aln {
83 my $self = shift;
84 my $entry;
85 my $name;
86 my $start;
87 my $end;
88 my $seq;
89 my $add;
90 my $count = 0;
91 my $seq_residues;
93 my $aln = Bio::SimpleAlign->new(-source => 'mase');
96 while( $entry = $self->_readline) {
97 $entry =~ /^;/ && next;
98 if( $entry =~ /^(\S+)\/(\d+)-(\d+)/ ) {
99 $name = $1;
100 $start = $2;
101 $end = $3;
102 } else {
103 $entry =~ s/\s//g;
104 $name = $entry;
105 $end = -1;
108 $seq = "";
110 while( $entry = $self->_readline) {
111 $entry =~ /^;/ && last;
112 $entry =~ s/[^A-Za-z\.\-]//g;
113 $seq .= $entry;
115 if( $end == -1) {
116 $start = 1;
118 $seq_residues = $seq;
119 $seq_residues =~ s/\W//g;
120 $end = length($seq_residues);
123 $add = Bio::LocatableSeq->new('-seq' => $seq,
124 '-display_id' => $name,
125 '-start' => $start,
126 '-end' => $end,
127 '-alphabet' => $self->alphabet,
131 $aln->add_seq($add);
134 # If $end <= 0, we have either reached the end of
135 # file in <> or we have encountered some other error
137 if ($end <= 0) { undef $aln;}
141 return $aln if $aln->num_sequences;
142 return;
147 =head2 write_aln
149 Title : write_aln
150 Usage : $stream->write_aln(@aln)
151 Function: writes the $aln object into the stream in mase format ###Not yet implemented!###
152 Returns : 1 for success and 0 for error
153 Args : L<Bio::Align::AlignI> object
156 =cut
158 sub write_aln {
159 my ($self,@aln) = @_;
160 $self->throw_not_implemented();