This object can transform
Bio::SimpleAlign objects to and from
fasta flat file databases. This is for the fasta sequence format NOT
FastA analysis program. To process the pairwise alignments from a
FastA (FastX, FastN, FastP, tFastA, etc) use the Bio::SearchIO module.
sub next_aln
{ my $self = shift;
my $entry;
my ($start,$end,$name,$seqname,$seq,$seqchar,$tempname,%align);
my $aln = Bio::SimpleAlign->new();
while(defined ($entry = $self->_readline)) {
if($entry =~ /^>(\S+)/ ) {
$tempname = $1;
if( defined $name ) {
if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
$seqname = $1;
$start = $2;
$end = $3;
} else {
$seqname=$name;
$start = 1;
$end = length($seqchar); }
$seq = new Bio::LocatableSeq('-seq'=>$seqchar,
'-id'=>$seqname,
'-start'=>$start,
'-end'=>$end,
);
$aln->add_seq($seq);
}
$name = $tempname;
$seqchar = "";
next;
}
$entry =~ s/[^A-Za-z\.\-]//g;
$seqchar .= $entry;
}
if (!defined $name) {$name="";}
if (!defined $seqchar) {$seqchar="";}
if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
$seqname = $1;
$start = $2;
$end = $3;
} else {
$seqname=$name;
$start = 1;
$end = length($seqchar);
}
if ($end <= 0) { undef $aln; return $aln;}
if( length($seqchar) == 0 && length($seqname) == 0 ) {
} else {
$seq = new Bio::LocatableSeq('-seq'=>$seqchar,
'-id'=>$seqname,
'-start'=>$start,
'-end'=>$end,
);
$aln->add_seq($seq);
}
return $aln; } |
sub write_aln
{ my ($self,@aln) = @_;
my ($seq,$rseq,$name,$count,$length,$seqsub);
foreach my $aln (@aln) {
if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) {
$self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
next;
}
foreach $rseq ( $aln->each_seq() ) {
$name = $aln->displayname($rseq->get_nse());
$seq = $rseq->seq();
$self->_print (">$name\n") or return ;
$count =0;
$length = length($seq);
while( ($count * 60 ) < $length ) {
$seqsub = substr($seq,$count*60,60);
$self->_print ("$seqsub\n") or return ;
$count++;
}
}
}
$self->flush if $self->_flush_on_write && defined $self->_fh;
return 1;
}
1; } |
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/