Bio::AlignIO arp
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Bio::AlignIO::arp - ARP MSA Sequence input/output stream
Package variables
No package variables defined.
Included modules
Do not use this module directly. Use it via the Bio::AlignIO
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:
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
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
  ($samples) = $aln->annotation->get_Annotations('Samples');
say $samples->display_text;
# or use other relevant TagTree methods to retrieve data
No description
No description
Methods description
next_alncode    nextTop
 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);
    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*$}{};
            # per alignment annotation data (i.e. Sample Blocks) or
# annotation data retained for each alignment?
$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 { # process other data at a later point
} delete $self->{state}->{blockdata}; $self->{state}->{in_curly_block} = 0; last SCAN; } else { # all other data should be in a curly block and have a block title
$self->throw("Data found outside of proper block:\n$data") if !exists($self->{state}->{current_block}) && !$self->{state}->{in_curly_block}; # bypass commented stuff (but we may want to process it at a later
# point, so turn back here)
next if $data =~ m{^\s*\#}xms; if ($self->{state}->{current_block} eq 'Samples') { chomp $data; # we have two possible ways to deal with sample number, either
# clone the LocatableSeq (in which case we need to deal with ID
# duplication), or store as annotation data. I chose the latter
# route using a Bio::Annotation::TagTree. YMMV - cjfields 10-15-08
my ($ls, $samples) = $self->_process_sequence($data); my $id = $ls->id; push @{ $self->{state}->{SampleAnnotation}->{Samples} }, [$id => $samples]; $aln->add_seq($ls); } else { # add elsif's for further processing
#$self->debug('Unmatched data in block '.
# $self->{state}->{current_block}.
# ":\n$data\n");
$self->{state}->{blockdata} .= $data; } } } # alignments only returned if they contain sequences
return $aln if $aln->num_sequences; return;
sub write_aln {
    my ($self,@aln) = @_;

################ PRIVATE SUBS ################ 
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);
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') {
            } elsif ($key eq 'Samples') {
                $coll->add_Annotation($key, $factory->create_object(
                    -value => [$key => $self->{state}->{$anntype}->{$key}]));
            } elsif ($key eq 'SampleName') {
            } 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
Support Top
Please direct usage questions or support issues to the mailing list:
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.
Reporting BugsTop
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
Chris Fields (cjfields)
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _