| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::nexus | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright Heikki Lehvaslaiho | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | Bio::AlignIO::nexus - NEXUS format sequence input/output stream | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | Do not use this module directly. Use it via the L<Bio::AlignIO> class. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | use Bio::AlignIO; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | my $in = Bio::AlignIO->new(-format => 'nexus', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | -file => 'aln.nexus'); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | while( my $aln = $in->next_aln ) { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # do something with the alignment | ||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | This object can transform L<Bio::Align::AlignI> objects to and from NEXUS | ||||||||||||||||||||||||||||||||||||||||||
| 26 | data blocks. See method documentation for supported NEXUS features. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | Will Fisher has written an excellent standalone NEXUS format parser in | ||||||||||||||||||||||||||||||||||||||||||
| 31 | Perl, readnexus. A number of tricks were adapted from it. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||
| 42 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||
| 43 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||
| 44 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||
| 49 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||||||||||||||
| 50 | web: | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | =head1 AUTHORS - Heikki Lehvaslaiho | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | Email: heikki-at-bioperl-dot-org | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||||||||||||||||
| 61 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | package Bio::AlignIO::nexus; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | $Bio::AlignIO::nexus::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | use vars qw(%valid_type); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | %valid_type = map {$_, 1} qw( dna rna protein standard ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | # standard throws error: inherited from Bio::PrimarySeq | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | Title : new | ||||||||||||||||||||||||||||||||||||||||||
| 84 | Usage : $alignio = Bio::AlignIO->new(-format => 'nexus', -file => 'filename'); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Function: returns a new Bio::AlignIO object to handle clustalw files | ||||||||||||||||||||||||||||||||||||||||||
| 86 | Returns : Bio::AlignIO::clustalw object | ||||||||||||||||||||||||||||||||||||||||||
| 87 | Args : -verbose => verbosity setting (-1,0,1,2) | ||||||||||||||||||||||||||||||||||||||||||
| 88 | -file => name of file to read in or with ">" - writeout | ||||||||||||||||||||||||||||||||||||||||||
| 89 | -fh => alternative to -file param - provide a filehandle | ||||||||||||||||||||||||||||||||||||||||||
| 90 | to read from/write to | ||||||||||||||||||||||||||||||||||||||||||
| 91 | -format => type of Alignment Format to process or produce | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | Customization of nexus flavor output | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | -show_symbols => print the symbols="ATGC" in the data definition | ||||||||||||||||||||||||||||||||||||||||||
| 96 | (MrBayes does not like this) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | boolean [default is 1] | ||||||||||||||||||||||||||||||||||||||||||
| 98 | -show_endblock => print an 'endblock;' at the end of the data | ||||||||||||||||||||||||||||||||||||||||||
| 99 | (MyBayes does not like this) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | boolean [default is 1] | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 36 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 36 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 36 | $self->SUPER::_initialize(@args); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 36 | my ($show_symbols, $endblock) = | |||||||||||||||||||||||||||||||||||||||||
| 108 | $self->_rearrange([qw(SHOW_SYMBOLS SHOW_ENDBLOCK)], @args); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 36 | my @names = qw(symbols endblock); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 36 | for my $v ( $show_symbols, $endblock ) { | |||||||||||||||||||||||||||||||||||||||||
| 111 | 72 | ▶ | $v = 1 unless defined $v; # default value is 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 72 | my $n = shift @names; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 72 | $self->flag($n, $v); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =head2 next_aln | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | Title : next_aln | ||||||||||||||||||||||||||||||||||||||||||
| 121 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||||||||||||||||
| 122 | Function: Returns the next alignment in the stream. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | Supports the following NEXUS format features: | ||||||||||||||||||||||||||||||||||||||||||
| 125 | - The file has to start with '#NEXUS' | ||||||||||||||||||||||||||||||||||||||||||
| 126 | - Reads in the name of the alignment from a comment | ||||||||||||||||||||||||||||||||||||||||||
| 127 | (anything after 'TITLE: ') . | ||||||||||||||||||||||||||||||||||||||||||
| 128 | - Sequence names can be given in a taxa block, too. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | - If matchchar notation is used, converts | ||||||||||||||||||||||||||||||||||||||||||
| 130 | them back to sequence characters. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | - Does character conversions specified in the | ||||||||||||||||||||||||||||||||||||||||||
| 132 | NEXUS equate command. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | - Sequence names of type 'Homo sapiens' and | ||||||||||||||||||||||||||||||||||||||||||
| 134 | Homo_sapiens are treated identically. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | Returns : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||||||||||||||||
| 137 | Args : | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 33 | ▶ | sub next_aln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=72 SCAR=45.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 33 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 33 | my $entry; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 33 | my ($aln_name, $seqcount, $residuecount, %hash, $alphabet, | |||||||||||||||||||||||||||||||||||||||||
| 147 | $match, $gap, $missing, $equate, $interleave, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | $name,$str,@names,$seqname,$start,$end,$count,$seq); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 33 | local $Bio::LocatableSeq::OTHER_SYMBOLS = '\*\?\.'; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 33 | local $Bio::LocatableSeq::GAP_SYMBOLS = '\-'; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 33 | my $aln = Bio::SimpleAlign->new(-source => 'nexus'); | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # file starts with '#NEXUS' but we allow white space only lines before it | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 33 | $entry = $self->_readline; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 33 | ▶ | $entry = $self->_readline while defined $entry && $entry =~ /^\s+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $entry and $entry =~ /^\s+$/
MC/DC0%0/2
defined $entry and $entry =~ /^\s+$/
defined $entry
$entry =~ /^\s+$/
Truth table33%1/3
A and B
A= defined $entryB= $entry =~ /^\s+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 33 | ▶ | return unless $entry; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 33 | ▶ | $self->throw("Not a valid interleaved NEXUS file! [#NEXUS] not starting the file\n$entry") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$entry and $entry =~ /^#NEXUS/i
MC/DC0%0/2
$entry and $entry =~ /^#NEXUS/i
$entry
$entry =~ /^#NEXUS/i
Truth table33%1/3
A and B
A= $entryB= $entry =~ /^#NEXUS/i
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | unless ($entry && $entry =~ /^#NEXUS/i); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | # skip anything before either the taxa or data block | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # but read in the optional title in a comment | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 33 | ▶ | while (defined($entry = $self->_readline)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 97 | local ($_) = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 97 | ▶ | /\[TITLE. *([^\]]+)]\s+/i and $aln_name = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 97 | ▶ | last if /^begin +data/i || /^begin +taxa/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^begin +data/i or /^begin +taxa/i
MC/DC100%2/2
/^begin +data/i or /^begin +taxa/i
/^begin +data/i
/^begin +taxa/i
Truth table100%3/3
A or B
A= /^begin +data/iB= /^begin +taxa/i
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 33 | ▶ | $aln_name =~ s/\s/_/g and $aln->id($aln_name) if $aln_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$aln_name && ($aln_name =~ s/\s/_/g && $aln->id($aln_name))
$aln_name =~ s/\s/_/g and $aln->id($aln_name)
MC/DC0%0/3
$aln_name && ($aln_name =~ s/\s/_/g && $aln->id($aln_name))
$aln_name
$aln_name =~ s/\s/_/g
$aln->id($aln_name)
Truth table0%0/4
A && B and C
A= $aln_nameB= $aln_name =~ s/\s/_/gC= $aln->id($aln_name)
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # data and taxa blocks | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 33 | my $incomment; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 33 | ▶ | while (defined ($entry = $self->_readline)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 446 | local ($_) = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 446 | ▶ | next if s/\[[^\]]+\]//g; # remove comments | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 264 | ▶ | if( s/\[[^\]]+$// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | $incomment = 1; | |||||||||||||||||||||||||||||||||||||||||
| 177 | # skip line if it is now empty or contains only whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } elsif($incomment) { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 39 | ▶ | if( s/^[^\]]*\]// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | $incomment = 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 33 | next; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } elsif( /taxlabels/i ) { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # doesn't deal with taxlabels adequately and can mess things up! | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # @names = $self->_read_taxlabels; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 206 | ▶ | /ntax\s*=\s*(\d+)/i and $seqcount = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 206 | ▶ | /nchar\s*=\s*(\d+)/i and $residuecount = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 206 | ▶ | /matchchar\s*=\s*(.)/i and $match = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 206 | ▶ | /gap\s*=\s*(.)/i and $gap = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 206 | ▶ | /missing\s*=\s*(.)/i and $missing = $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 206 | ▶ | /equate\s*=\s*\"([^\"]+)/i and $equate = $1; # "e.g. equate="T=C G=A"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 206 | ▶ | /datatype\s*=\s*(\w+)/i and $alphabet = lc $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 206 | ▶ | /interleave/i and $interleave = 1 ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 206 | ▶ | last if /matrix/io; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 33 | ▶ | $self->throw("Not a valid NEXUS sequence file. Datatype not specified.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | unless $alphabet; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | $self->throw("Not a valid NEXUS sequence file. Datatype should not be [$alphabet]") | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 33 | ▶ | unless $valid_type{$alphabet}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 33 | ▶ | $self->throw("\"$gap\" is not a valid gap character. For compatability, gap char can not be one of: ()[]{}/\,;:=*'`\"<>^") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$gap and $gap =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
MC/DC0%0/2
$gap and $gap =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
$gap
$gap =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
Truth table33%1/3
A and B
A= $gapB= $gap =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | if $gap && $gap =~ /[\(\)\[\]\{\}\/\\\,\;\:\=\*\'\`\<\>\^]/; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 33 | ▶ | $self->throw("\"$missing\" is not a valid missing character. For compatability, missing char can not be one of: ()[]{}/\,;:=*'`\"<>^") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$missing and $missing =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
MC/DC0%0/2
$missing and $missing =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
$missing
$missing =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
Truth table66%2/3
A and B
A= $missingB= $missing =~ m"[\(\)\[\]\{\}/\\\,\;\:\=\*\'\`\<\>\^]"
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | if $missing && $missing =~ /[\(\)\[\]\{\}\/\\\,\;\:\=\*\'\`\<\>\^]/; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 33 | $aln->gap_char($gap); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 33 | $aln->missing_char($missing); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # if data is not right after the matrix line | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # read the empty lines out | ||||||||||||||||||||||||||||||||||||||||||
| 216 | # | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 33 | ▶ | while ($entry = $self->_readline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 36 | ▶ | unless ($entry =~ /^\s+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 33 | $self->_pushback($entry); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 33 | last; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # matrix command | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # first alignment section | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 33 | ▶ | if (@names == 0) { # taxa block did not exist | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 33 | ▶ | while ($entry = $self->_readline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 522 | local ($_) = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 522 | ▶ | if( s/\[[^\]]+\]//g ) { #] remove comments | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 205 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | # skip line if it is now empty or contains only whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 514 | ▶ | if ($interleave && defined$count && ($count <= $seqcount)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$interleave and defined $count and $count <= $seqcount
$interleave and defined $count
MC/DC66%2/3
$interleave and defined $count and $count <= $seqcount
$interleave
defined $count
$count <= $seqcount
Truth table75%3/4
A and B and C
A= $interleaveB= defined $countC= $count <= $seqcount
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 122 | ▶ | /^\s+$/ and last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 392 | ▶ | /^\s+$/ and next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 492 | ▶ | /^\s*;/ and last; # stop if colon at end of matrix is on it's own line | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | #/^\s*;\s*$/ and last; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 486 | ▶ | if ( /^\s*([\"\'](.+?)[\"\']|(\S+))\s+(.*)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | # get single and double quoted names, or all the first | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # nonwhite word as the name, and remained is seq | ||||||||||||||||||||||||||||||||||||||||||
| 245 | #if (/^\s*('([^']*?)'|([^']\S*))\s+(.*)$/) { #' | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 486 | ▶ | $name = ($2 || $3); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$2 || $3
MC/DC0%0/2
$2 || $3
$2
$3
Truth table66%2/3
A || B
A= $2B= $3
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 486 | ▶ | if ($4) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | # seq is on same line as name | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # this is the usual NEXUS format | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 476 | $str = $4; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | # otherwise get seq from following lines. No comments allowed | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # a less common matrix format, usually used for very long seqs | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 10 | $str=''; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | ▶ | while (local ($_) = $self->_readline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 1860 | my $str_tmp = $_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 1860 | $str_tmp =~ s/[\s;]//g; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 1860 | $str .= $str_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 1860 | ▶ | last if length$str == $residuecount; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 486 | $name =~ s/ /_/g; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 486 | push @names, $name; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 486 | $str =~ s/[\s;]//g; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 486 | $count = @names; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 486 | $hash{$count} = $str; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 486 | ▶ | $self->throw("Not a valid interleaved NEXUS file! seqcount [$count] > predeclared [$seqcount] in the first section") if $count > $seqcount; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 486 | ▶ | /;/ and last; # stop if colon at end of matrix is on the same line as the last seq | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | # interleaved sections | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 33 | $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 33 | ▶ | if ( $interleave ) { # only read next section if file is interleaved | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 18 | ▶ | while( $entry = $self->_readline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 1058 | local ($_) = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1058 | ▶ | if( s/\[[^\]]+\]//g ) { #] remove comments | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 826 | ▶ | next if /^\s*$/; # skip line if it is now empty or contains only whitespace | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 1000 | ▶ | /^\s*;/ and last; # stop if colon at end of matrix is on it's own line | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 983 | ▶ | $count = 0, next if $entry =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 916 | ▶ | if (/^\s*(\'([^\']*?)\'|([^\']\S*))\s+(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 916 | $str = $4; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 916 | $str =~ s/[\s;]//g; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 916 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 916 | $hash{$count} .= $str; | |||||||||||||||||||||||||||||||||||||||||
| 289 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 916 | ▶ | $self->throw("Not a valid interleaved NEXUS file! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | seqcount [$count] > predeclared [$seqcount] ") if $count > $seqcount; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 916 | ▶ | /;/ and last; # stop if colon at end of matrix is on the same line as the last seq | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 33 | ▶ | return if @names < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # sequence creation | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 33 | $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 33 | foreach $name ( @names ) { | |||||||||||||||||||||||||||||||||||||||||
| 301 | 486 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 486 | ▶ | if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ($seqname,$start,$end) = ($1,$2,$3); | |||||||||||||||||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 486 | ($seqname,$start,$str) = ($name,1,$hash{$count}); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 486 | $str =~ s/[$Bio::LocatableSeq::GAP_SYMBOLS]//g; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 486 | $end = length($str); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # consistency test | ||||||||||||||||||||||||||||||||||||||||||
| 311 | $self->throw("Length of sequence [$seqname] is not [$residuecount]; got".CORE::length($hash{$count})) | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 486 | ▶ | unless CORE::length($hash{$count}) == $residuecount; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 486 | $seq = Bio::LocatableSeq->new('-seq' => $hash{$count}, | |||||||||||||||||||||||||||||||||||||||||
| 315 | '-display_id' => $seqname, | ||||||||||||||||||||||||||||||||||||||||||
| 316 | '-start' => $start, | ||||||||||||||||||||||||||||||||||||||||||
| 317 | '-end' => $end, | ||||||||||||||||||||||||||||||||||||||||||
| 318 | '-alphabet' => $alphabet | ||||||||||||||||||||||||||||||||||||||||||
| 319 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 486 | $aln->add_seq($seq); | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # if matchchar is used | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 33 | ▶ | $aln->unmatch($match) if $match; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | # if equate ( e.g. equate="T=C G=A") is used | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 33 | ▶ | if ($equate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | $aln->map_chars($1, $2) while $equate =~ /(\S)=(\S)/g; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 33 | ▶ | while (defined $entry && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $entry and not $entry =~ /endblock/i
MC/DC100%2/2
defined $entry and not $entry =~ /endblock/i
defined $entry
not $entry =~ /endblock/i
Truth table100%3/3
A and not(B)
A= defined $entryB= not $entry =~ /endblock/i
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | $entry !~ /endblock/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 475 | $entry = $self->_readline; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 33 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub _read_taxlabels { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_taxlabels: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my ($name, @names); | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | while (my $entry = $self->_readline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | last if $entry =~ m/^\s*(END)?;/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if( $entry =~ m/\s*(\S+)\s+/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ($name) = ($1); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $name =~ s/\[[^\[]+\]//g; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $name =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | push @names, $name; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | =head2 write_aln | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | Title : write_aln | ||||||||||||||||||||||||||||||||||||||||||
| 358 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||||||||||||||||
| 359 | Function: Writes the $aln object into the stream in interleaved NEXUS | ||||||||||||||||||||||||||||||||||||||||||
| 360 | format. Everything is written into a data block. | ||||||||||||||||||||||||||||||||||||||||||
| 361 | SimpleAlign methods match_char, missing_char and gap_char must be set | ||||||||||||||||||||||||||||||||||||||||||
| 362 | if you want to see them in the output. | ||||||||||||||||||||||||||||||||||||||||||
| 363 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||||||||||||||||
| 364 | Args : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | ▶ | sub write_aln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=20 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | my ($self,@aln) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | my $wrapped = 0; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | my $maxname; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | my ($length,$date,$name,$seq,$miss,$pad,%hash,@arr,$tempcount,$index ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | my ($match, $missing, $gap,$symbols) = ('', '', '',''); | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | foreach my $aln (@aln) { | |||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | ▶ | if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$aln and $aln->isa("Bio::Align::AlignI")
MC/DC0%0/2
$aln and $aln->isa("Bio::Align::AlignI")
$aln
$aln->isa("Bio::Align::AlignI")
Truth table33%1/3
A and B
A= $alnB= $aln->isa("Bio::Align::AlignI")
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln"); | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | $self->throw("All sequences in the alignment must be the same length") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | unless $aln->is_flush($self->verbose); | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | $length = $aln->length(); | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | $self->_print (sprintf("#NEXUS\n[TITLE: %s]\n\nbegin data;\ndimensions ntax=%s nchar=%s;\n", | |||||||||||||||||||||||||||||||||||||||||
| 387 | $aln->id, $aln->num_sequences, $length)); | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | $match = "match=". $aln->match_char if $aln->match_char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | ▶ | $missing = "missing=". $aln->missing_char if $aln->missing_char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | ▶ | $gap = "gap=". $aln->gap_char if $aln->gap_char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | $symbols = 'symbols="'.join('',$aln->symbol_chars). '"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->flag("symbols") and $aln->symbol_chars
MC/DC0%0/2
$self->flag("symbols") and $aln->symbol_chars
$self->flag("symbols")
$aln->symbol_chars
Truth table33%1/3
A and B
A= $self->flag("symbols")B= $aln->symbol_chars
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | if( $self->flag('symbols') && $aln->symbol_chars); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | $self->_print | |||||||||||||||||||||||||||||||||||||||||
| 395 | (sprintf("format interleave datatype=%s %s %s %s %s;\n\nmatrix\n", | ||||||||||||||||||||||||||||||||||||||||||
| 396 | $aln->get_seq_by_pos(1)->alphabet, $match, | ||||||||||||||||||||||||||||||||||||||||||
| 397 | $missing, $gap, $symbols)); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | # account for single quotes round names | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | my $indent = $aln->maxdisplayname_length+2; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | $aln->set_displayname_flat(); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 2 | foreach $seq ( $aln->each_seq() ) { | |||||||||||||||||||||||||||||||||||||||||
| 404 | 10 | my $nmid = $aln->displayname($seq->get_nse()); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | ▶ | if( $nmid =~ /[^\w\d\.]/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | # put name in single quotes incase it contains any of | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # the following chars: ()[]{}/\,;:=*'"`+-<> that are not | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # allowed in PAUP* and possible other software | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | $name = sprintf("%-${indent}s", "\'" . $nmid . "\'"); | |||||||||||||||||||||||||||||||||||||||||
| 411 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 9 | $name = sprintf("%-${indent}s", $nmid); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 10 | $hash{$name} = $seq->seq; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 10 | push(@arr,$name); | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 2 | ▶ | while( $count < $length ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | # there is another block to go! | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 10 | foreach $name ( @arr ) { | |||||||||||||||||||||||||||||||||||||||||
| 421 | 58 | my $dispname = $name; | |||||||||||||||||||||||||||||||||||||||||
| 422 | # $dispname = '' if $wrapped; | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 58 | $self->_print (sprintf("%${indent}s ",$dispname)); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 58 | $tempcount = $count; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 58 | $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 58 | ▶ | while( ($tempcount + 10 < $length) && ($index < 5) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tempcount + 10 < $length and $index < 5
MC/DC100%2/2
$tempcount + 10 < $length and $index < 5
$tempcount + 10 < $length
$index < 5
Truth table100%3/3
A and B
A= $tempcount + 10 < $lengthB= $index < 5
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 268 | $self->_print (sprintf("%s ",substr($hash{$name},$tempcount,10))); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 268 | $tempcount += 10; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 268 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # last | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 58 | ▶ | if( $index < 5) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | # space to print! | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 10 | $self->_print (sprintf("%s ",substr($hash{$name},$tempcount))); | |||||||||||||||||||||||||||||||||||||||||
| 435 | 10 | $tempcount += 10; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 58 | $self->_print ("\n"); | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 10 | $self->_print ("\n\n"); | |||||||||||||||||||||||||||||||||||||||||
| 440 | 10 | $count = $tempcount; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 10 | $wrapped = 1; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 2 | ▶ | if( $self->flag('endblock') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | $self->_print (";\n\nendblock;\n"); | |||||||||||||||||||||||||||||||||||||||||
| 445 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $self->_print (";\n\nend;\n"); | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | ▶ | $self->flush if $self->_flush_on_write && defined $self->_fh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write
defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | =head2 flag | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | Title : flag | ||||||||||||||||||||||||||||||||||||||||||
| 456 | Usage : $obj->flag($name,$value) | ||||||||||||||||||||||||||||||||||||||||||
| 457 | Function: Get/Set a flag value | ||||||||||||||||||||||||||||||||||||||||||
| 458 | Returns : value of flag (a scalar) | ||||||||||||||||||||||||||||||||||||||||||
| 459 | Args : on set, new value (a scalar or undef, optional) | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 76 | ▶ | sub flag{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flag: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 76 | my ($self,$name,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 76 | ▶ | return $self->{'flag'}->{$name} = $val if defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | return $self->{'flag'}->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||