Bio::AlignIO
arp
Toolbar
Summary
Bio::AlignIO::arp - ARP MSA Sequence input/output stream
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Do not use this module directly. Use it via the
Bio::AlignIO class.
Description
This object can create
Bio::SimpleAlign objects from
ARP flat files. These are typically configuration-like data files
for the program Arlequin. For more information, see:
http://lgb.unige.ch/arlequin/
For the moment, this retains the allele sequence data in the DATA section and
inserts them into SimpleAlign objects. ARP files that contain other data (RFLP,
etc.) are not expected to parse properly. Also, if the DNA data is actually SNP
data, then the LocatableSeq object instantiation will throw an error.
This is now set up as a generic parser (i.e. it parses everything) and
collects as much data as possible into the SimpleAlign object. The following
in a general mapping of where data can be found:
Tag SimpleAlign
Method
----------------------------------------------------------------------
Title description
SampleName id
----------------------------------------------------------------------
Tag Bio::Annotation TagName Bio::Annotation
Class Parameters
----------------------------------------------------------------------
NE SimpleValue pfam_family_accession value
NL SimpleValue sequence_start_stop value
SS SimpleValue sec_structure_source value
BM SimpleValue build_model value
RN Reference reference *
----------------------------------------------------------------------
* RN is generated based on the number of Bio::Annotation::Reference objects
In addition, the number of samples found in the alignment is retained in a
Bio::Annotation::TagTree object in the annotation collection and is accessible
via:
($samples) = $aln->annotation->get_Annotations('Samples');
say $samples->display_text;
# or use other relevant TagTree methods to retrieve data
Methods
Methods description
Title : next_aln Usage : $aln = $stream->next_aln Function: returns the next alignment in the stream. Returns : Bio::Align::AlignI object - returns 0 on end of file or on error Args : -width => optional argument to specify the width sequence will be written (60 chars by default)
See Bio::Align::AlignI |
Title : write_aln Usage : $stream->write_aln(@aln) Function: writes the $aln object into the stream in xmfa format Returns : 1 for success and 0 for error Args : Bio::Align::AlignI object
See Bio::Align::AlignI |
Methods code
sub next_aln
{ my $self = shift;
my $aln = Bio::SimpleAlign->new(-source => 'arp');
my ($data, $cur_block, $cur_type, $cur_data);
SCAN:
while (defined ($data = $self->_readline) ) {
next if $data =~ m{^\s*$}xms;
if ($data =~ m{\[{1,2}(\w+)\]{1,2}}xms) {
$self->{state}->{current_block} = $1;
next SCAN;
}
elsif ($data =~ m{^\s*(\w+)=\s?(\S[^\n]*$)}xms) {
($cur_type, $cur_data) = ($1, $2);
if ($cur_data =~ m{^\s*\{\s*$}) {
$self->throw("Curly block must be embedded in a named Block")
if !exists($self->{state}->{current_block});
$self->{state}->{in_curly_block} = 1;
next SCAN;
}
$cur_data =~ s{[\"\']}{}g;
$cur_data =~ s{\s*$}{};
$self->{state}->{current_block} eq 'Samples' ?
push @{$self->{state}->{SampleAnnotation}->{$cur_type}}, $cur_data :
push @{$self->{state}->{Annotation}->{$cur_type}}, $cur_data;
}
elsif ($data =~ m{^\s*\}\s*$}xms) {
$self->throw("Unmatched bracket in ARP file:\n$data") if
!exists($self->{state}->{in_curly_block});
if ($self->{state}->{current_block} eq 'Samples') {;
my $ac = $self->_process_annotation($aln);
delete $self->{state}->{SampleAnnotation};
} else {
}
delete $self->{state}->{blockdata};
$self->{state}->{in_curly_block} = 0;
last SCAN;
}
else {
$self->throw("Data found outside of proper block:\n$data") if
!exists($self->{state}->{current_block}) && !$self->{state}->{in_curly_block};
next if $data =~ m{^\s*\#}xms;
if ($self->{state}->{current_block} eq 'Samples') {
chomp $data;
my ($ls, $samples) = $self->_process_sequence($data);
my $id = $ls->id;
push @{ $self->{state}->{SampleAnnotation}->{Samples} }, [$id => $samples];
$aln->add_seq($ls);
} else {
$self->{state}->{blockdata} .= $data;
}
}
}
return $aln if $aln->num_sequences;
return;} |
sub write_aln
{ my ($self,@aln) = @_;
$self->throw_not_implemented;
}
} |
sub _process_sequence
{ my ($self, $raw) = @_;
return unless defined $raw;
$raw =~ s{(?:^\s+|\s+$)}{}g;
my ($id, $samples, $seq) = split(' ', $raw);
my $ls = Bio::LocatableSeq->new('-seq' => $seq,
'-start' => 1,
'-display_id' => $id,
'-alphabet' => $self->alphabet);
return($ls, $samples);} |
| _process_annotation | description | prev | next | Top |
sub _process_annotation
{ my ($self, $aln) = @_;
my $coll = Bio::Annotation::Collection->new();
my $factory = Bio::Annotation::AnnotationFactory->new(-type => 'Bio::Annotation::SimpleValue');
for my $anntype (qw(SampleAnnotation Annotation)) {
for my $key (keys %{ $self->{state}->{$anntype} }) {
if ($key eq 'Title') {
$aln->description($self->{state}->{$anntype}->{$key}[0]);
} elsif ($key eq 'Samples') {
$factory->type('Bio::Annotation::TagTree');
$coll->add_Annotation($key, $factory->create_object(
-value => [$key => $self->{state}->{$anntype}->{$key}]));
$factory->type('Bio::Annotation::SimpleValue');
} elsif ($key eq 'SampleName') {
$aln->id($self->{state}->{$anntype}->{$key}[0]);
} else {
$self->throw('Expecting an array reference') unless
ref $self->{state}->{$anntype}->{$key} eq 'ARRAY';
for my $a (@{ $self->{state}->{$anntype}->{$key} }) {
$coll->add_Annotation($key, $factory->create_object(
-value => $a) );
}
}
}
}
$aln->annotation($coll);
}
1;} |
General documentation
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
Chris Fields (cjfields)
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _