Bio-Phylo
view release on metacpan or search on metacpan
lib/Bio/Phylo/Parsers/Cdao.pm view on Meta::CPAN
my ( $self, $predicate ) = @_;
# attempt to split URI in namespace and term
my ( $ns, $term );
# this is for cases where the term is referenced as somewhere inside
# an ontology using an anchor '#', e.g. in CDAO
if ( $predicate =~ m/^(.+#)(.+?)$/ ) {
( $ns, $term ) = ( $1, $2 );
}
# this is for cases where the term is a path fragment inside a namespace,
# i.e. preceded by a '/', as in dublin core
elsif ( $predicate =~ m/^(.+\/)([^\/]+?)$/ ) {
( $ns, $term ) = ( $1, $2 );
}
# this is for cases where the term is relative to a urn:, i.e. preceded
# by a ':', as in the uBio predicates
elsif ( $predicate =~ m/^(.+:)([^:]+?)$/ ) {
( $ns, $term ) = ( $1, $2 );
}
lib/Bio/Phylo/Parsers/Nexus.pm view on Meta::CPAN
=begin comment
Type : Method
Title : _tokenize()
Usage : $nexus->_tokenize($lines);
Function: Tokenizes lines in $lines array ref
Returns : Two dimensional ARRAY
Args : An array ref of lines (e.g. read from an input file);
Comments: This method accepts an array ref holding lines that may contain
single quotes, double quotes or square brackets. Line breaks and
spaces inside these quoted/bracketed fragments are ignored, otherwise
it is split, e.g.:
[
[ '#NEXUS' ],
[ 'BEGIN TAXA; [taxablock comment]' ],
[ 'DIMENSIONS NTAX=3;' ],
[ 'TAXLABELS "Taxon \' A" \'Taxon B\' TAXON[comment]C' ],
...etc...
]
lib/Bio/Phylo/Parsers/Nexus.pm view on Meta::CPAN
']' => '[',
')' => '(',
);
# tokenize
LINE: for my $line ( @{$lines} ) {
$LineCount++;
TOKEN: while ( $line =~ /\S/ ) {
# line in file has no quoting/bracketing characters, and
# is no extension of a quoted/bracketed fragment starting
# on a previous line
if ( $line !~ $QUOTES_OR_BRACKETS && !$INSIDE_QUOTE ) {
if ($continue) {
push @{ $tokens[-1] }, $line;
$continue = 0;
}
else {
push @tokens, [$line];
}
my $logline = join( ' ', @{ $tokens[-1] } );
chomp($logline);
$self->_logger->debug("Tokenized line $LineCount: $logline");
next LINE;
}
# line in file has opening quoting/bracketing characters, and
# is no extension of a quoted/bracketed fragment starting
# on a previous line
elsif ( $line =~ $OPENING_QUOTE_OR_BRACKET && !$INSIDE_QUOTE ) {
my ( $start, $quoted ) = ( $1, $2 );
push @tokens, [$start];
$line = $quoted;
$extract = $quoted;
$INSIDE_QUOTE++;
$continue = 1;
$QuoteContext = substr( $quoted, 0, 1 );
$self->_logger->debug("Line $LineCount contains $QuoteContext");
$QuoteStartLine = $LineCount;
$CONTEXT_QB_AT_START = qr/^(\Q$QuoteContext\E)(.*)$/;
my $context_closer = $CLOSE_CHAR{$QuoteContext};
$CONTEXT_CLOSER = qr/^(.*?)(\Q$context_closer\E)(.*)$/;
next TOKEN;
}
# line in file has no quoting/bracketing characters, and
# is an extension of a quoted/bracketed fragment starting
# on a previous line
elsif ( $line !~ $CONTEXT_CLOSER && $INSIDE_QUOTE ) {
$self->_logger->debug(
"Line $LineCount extends quote or comment");
$extract .= $line;
next LINE;
}
elsif ( $line =~ $CONTEXT_QB_AT_START && $INSIDE_QUOTE ) {
my ( $q, $remainder ) = ( $1, $1 . $2 );
if ( $q eq '"' || $q eq "'" ) {
lib/Bio/Phylo/Parsers/Nexus.pm view on Meta::CPAN
# an exception here means that an opening quote symbol " ' [
# ($QuoteContext) was encountered at input file/string line $QuoteStartLine.
# This can happen if any of these symbols is used in an illegal
# way, e.g. by using double quotes as gap symbols in matrices.
if ($INSIDE_QUOTE) {
throw 'BadArgs' =>
"Unbalanced $QuoteContext starting at line $QuoteStartLine";
}
# final split: non-quoted/bracketed fragments are split on whitespace,
# others are preserved verbatim
$self->_logger->info(
"going to split non-quoted/commented fragments on whitespace");
foreach my $line (@tokens) {
my @line;
foreach my $word (@$line) {
if ( $word !~ $QUOTES_OR_BRACKETS ) {
$word =~ s/(=|;|,)/ $1 /g;
push @line, grep { /\S/ } split /\s+/, $word;
}
else {
push @line, $word;
}
lib/Bio/Phylo/Util/Logger.pm view on Meta::CPAN
Type : Constructor
Title : new
Usage : my $logger = Bio::Phylo::Util::Logger->new;
Function: Instantiates a logger
Returns : a Bio::Phylo::Util::Logger object
Args : -level => Bio::Phylo::Util::Logger::INFO (DEBUG/INFO/WARN/ERROR/FATAL)
-class => a package (or array ref) for which to set verbosity (optional)
-method => a sub name (or array ref) for which to set verbosity (optional)
-file => a file to which to append logging messages
-listeners => array ref of subs that handle logging messages
-prefix => a path fragment to strip from the paths in logging messages
=back
=head2 VERBOSITY LEVELS
=over
=item FATAL
( run in 2.646 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )