2 # BioPerl module for Bio::AlignIO::maf
9 Bio::AlignIO::maf - Multiple Alignment Format sequence input stream
13 Do not use this module directly. Use it via the Bio::AlignIO class.
17 my $alignio = Bio::AlignIO->new(-fh => \*STDIN, -format => 'maf');
19 while(my $aln = $alignio->next_aln()){
20 my $match_line = $aln->match_line;
24 print $aln->length, "\n";
25 print $aln->num_residues, "\n";
26 print $aln->is_flush, "\n";
27 print $aln->num_sequences, "\n";
29 $aln->splice_by_seq_pos(1);
31 print $aln->consensus_string(60), "\n";
32 print $aln->get_seq_by_pos(1)->seq, "\n";
33 print $aln->match_line(), "\n";
40 This class constructs Bio::SimpleAlign objects from an MAF-format
41 multiple alignment file.
43 Writing in MAF format is currently unimplemented.
45 Spec of MAF format is here:
46 http://genome.ucsc.edu/FAQ/FAQformat
52 Please direct usage questions or support issues to the mailing list:
54 I<bioperl-l@bioperl.org>
56 rather than to the module maintainer directly. Many experienced and
57 reponsive experts will be able look at the problem and quickly
58 address it. Please include a thorough description of the problem
59 with code and data examples if at all possible.
63 Report bugs to the Bioperl bug tracking system to help us keep track
64 the bugs and their resolution. Bug reports can be submitted via the
67 https://github.com/bioperl/bioperl-live/issues
69 =head1 AUTHORS - Allen Day
71 Email: allenday@ucla.edu
75 The rest of the documentation details each of the object
76 methods. Internal methods are usually preceded with a _
80 # Let the code begin...
82 package Bio
::AlignIO
::maf
;
88 use base
qw(Bio::AlignIO);
93 Usage : my $alignio = Bio::AlignIO->new(-format => 'maf'
97 Function: Initialize a new L<Bio::AlignIO::maf> reader
98 Returns : L<Bio::AlignIO> object
104 my($self,@args) = @_;
105 $self->SUPER::_initialize
(@args);
113 Usage : $aln = $stream->next_aln()
114 Function: returns the next alignment in the stream.
115 Throws an exception if trying to read in PHYLIP
117 Returns : L<Bio::SimpleAlign> object
125 # check beginning of file for proper header
126 if(!$self->{seen_header
}){
127 my $line = $self->_readline;
128 $self->throw("This doesn't look like a MAF file. First line should start with ##maf, but it was: ".$line)
129 unless $line =~ /^##maf/;
130 $self->{seen_header
} = 1;
131 # keep in case we parse this later
132 $self->_pushback($line);
135 my $aln = Bio
::SimpleAlign
->new(-source
=> 'maf');
137 my($aline, @slines, $seen_aline);
138 while(my $line = $self->_readline()){
139 if ($line =~ /^a\s/xms) {
142 $self->_pushback($line);
147 } elsif ($line =~ /^s\s/xms) {
155 # all MAF starts with 'a' line
156 return unless $aline;
158 my($kvs) = $aline =~ /^a\s+(.+)$/;
159 my @kvs = split /\s+/, $kvs if $kvs;
161 foreach my $kv (@kvs){
162 my($k,$v) = $kv =~ /(.+)=(.+)/;
166 $aln->score($kv{score
});
168 foreach my $sline (@slines){
169 my($s,$src,$start,$size,$strand,$srcsize,$text) =
171 # adjust coordinates to be one-based inclusive
173 $strand = $strand eq '+' ?
1 : $strand eq '-' ?
-1 : 0;
174 my $seq = Bio
::LocatableSeq
->new('-seq' => $text,
175 '-display_id' => $src,
176 '-start' => $strand > 0 ?
$start : ($srcsize-($start+$size-2)),
177 '-end' => $strand > 0 ?
($start + $size - 1) : ($srcsize-($start-1)) ,
178 '-strand' => $strand,
179 '-alphabet' => $self->alphabet,
184 return $aln if $aln->num_sequences;
189 shift->throw_not_implemented