BioPerl
view release on metacpan or search on metacpan
Bio/AlignIO/maf.pm view on Meta::CPAN
unless $line =~ /^##maf/;
$self->{seen_header} = 1;
# keep in case we parse this later
$self->_pushback($line);
}
my $aln = Bio::SimpleAlign->new(-source => 'maf');
my($aline, @slines, $seen_aline);
while(my $line = $self->_readline()){
if ($line =~ /^a\s/xms) {
# next block?
if ($seen_aline) {
$self->_pushback($line);
last;
}
$aline = $line;
$seen_aline++;
} elsif ($line =~ /^s\s/xms) {
push @slines, $line;
} else {
# missed lines
$self->debug($line);
}
}
# all MAF starts with 'a' line
return unless $aline;
my($kvs) = $aline =~ /^a\s+(.+)$/;
my @kvs = split /\s+/, $kvs if $kvs;
my %kv;
foreach my $kv (@kvs){
my($k,$v) = $kv =~ /(.+)=(.+)/;
$kv{$k} = $v;
}
$aln->score($kv{score});
foreach my $sline (@slines){
my($s,$src,$start,$size,$strand,$srcsize,$text) =
split /\s+/, $sline;
# adjust coordinates to be one-based inclusive
$start = $start + 1;
$strand = $strand eq '+' ? 1 : $strand eq '-' ? -1 : 0;
my $seq = Bio::LocatableSeq->new('-seq' => $text,
'-display_id' => $src,
'-start' => $strand > 0 ? $start : ($srcsize-($start+$size-2)),
'-end' => $strand > 0 ? ($start + $size - 1) : ($srcsize-($start-1)) ,
'-strand' => $strand,
'-alphabet' => $self->alphabet,
);
$aln->add_seq($seq);
}
return $aln if $aln->num_sequences;
return;
}
sub write_aln {
shift->throw_not_implemented
}
1;
( run in 0.519 second using v1.01-cache-2.11-cpan-39bf76dae61 )