view release on metacpan or search on metacpan
lib/FAST/Bio/SeqFeature/Gene/GeneStructure.pm view on Meta::CPAN
# Let the code begin...
package FAST::Bio::SeqFeature::Gene::GeneStructure;
use vars qw($WeakRefs);
use strict;
BEGIN {
eval "use Scalar::Util qw(weaken);";
if ($@) {
$FAST::Bio::SeqFeature::Gene::GeneStructure::WeakRefs = 0;
} else { $FAST::Bio::SeqFeature::Gene::GeneStructure::WeakRefs = 1; }
}
use base qw(FAST::Bio::SeqFeature::Generic FAST::Bio::SeqFeature::Gene::GeneStructureI);
sub new {
lib/FAST/Bio/SeqFeature/Gene/GeneStructure.pm view on Meta::CPAN
my ($self, $fea) = @_;
if(!$fea || ! $fea->isa('FAST::Bio::SeqFeature::Gene::TranscriptI') ) {
$self->throw("$fea does not implement FAST::Bio::SeqFeature::Gene::TranscriptI");
}
unless( exists $self->{'_transcripts'} ) {
$self->{'_transcripts'} = [];
}
$self->_expand_region($fea);
if( $FAST::Bio::SeqFeature::Gene::GeneStructure::WeakRefs ) {
$fea->parent(weaken $self);
} else {
$fea->parent($self);
}
push(@{$self->{'_transcripts'}}, $fea);
}
=head2 flush_transcripts
Title : flush_transcripts()
Usage : $gene->flush_transcripts();
lib/FAST/Bio/Species.pm view on Meta::CPAN
sub new {
my($class, @args) = @_;
my $self = $class->SUPER::new(@args);
# FAST::Bio::Species is now just a proxy object that just observes the NodeI
# interface methods but delegates them to the proper classes (FAST::Bio::Taxon and
# FAST::Bio::Tree::Tree). This will be surplanted by the much simpler
# FAST::Bio::Taxon/FAST::Bio::DB::Taxonomy modules in the future.
# Using a proxy allows proper GC w/o using weaken(). This just wraps the
# older instances, which have no reciprocal refs (thus no circular refs).
# This can then run proper cleanup
$self->taxon(FAST::Bio::Taxon->new(@args));
my ($org, $sp, $var, $classification) =
$self->_rearrange([qw(ORGANELLE
SUB_SPECIES
VARIANT
CLASSIFICATION)], @args);
lib/FAST/Bio/Species.pm view on Meta::CPAN
sub sub_species {
my ($self, $sub) = @_;
# TODO: instead of caching the raw name, cache the actual node instance.
if (!defined $self->{'_sub_species'}) {
my $ss_taxon = $self->tree->find_node(-rank => 'subspecies');
if ($ss_taxon) {
if ($sub) {
$ss_taxon->scientific_name($sub);
# *** weakening ref to our root node in species() to solve a
# memory leak means that we have a subspecies taxon to set
# during the first call to species(), but it has vanished by
# the time a user subsequently calls sub_species() to get the
# value. So we 'cheat' and just store the subspecies name in
# our self hash, instead of the tree. Is this a problem for
# a Species object? Can't decide --sendu
# This can now be changed to deal with this information on the
# fly. For now, the caching remains, but maybe we should just
# let these things deal with mutable data as needed? -- cjfields
lib/FAST/List/Gen.pm view on Meta::CPAN
package FAST::List::Gen;
use warnings;
use strict;
use Carp;
use Symbol qw/delete_package/;
use Scalar::Util qw/reftype weaken openhandle blessed/;
our @list_util;
use List::Util
@list_util = qw/first max maxstr min minstr reduce shuffle sum/;
our @EXPORT = qw/mapn by every range gen cap filter cache apply
zip min max reduce glob iterate list/;
our %EXPORT_TAGS = (
base => \@EXPORT,
'List::Util' => \@list_util,
map {s/==//g; s/#.*//g;
/:(\w+)\s+(.+)/s ? ($1 => [split /\s+/ => $2]) : ()
lib/FAST/List/Gen.pm view on Meta::CPAN
}
sub DESTROY {}
}
{
my %code_ok = map {ref, 1} sub {}, qr {};
my $croak_msg = 'not supported in dwim generator code dereference';
sub _new {
package FAST::List::Gen;
my ($class, $gen) = @_;
my $src = tied @$gen;
weaken $gen;
my ($fetch, $fsize) = $src->closures;
my $index = ($src->can('index') or sub {0})->();
my $size = $fsize->();
my $mutable = $src->mutable;
if($mutable) {
$src->tail_size($size)
}
my $dwim_code_strings = $DWIM_CODE_STRINGS;
my $overload = sub {
if (@_ == 0) {
lib/FAST/List/Gen.pm view on Meta::CPAN
$$_ = $size for @tails;
$iter += $_[1];
},
_when_done => sub :lvalue {$when_done},
from => sub {
croak "can not call ->from on started iterator"
if @list or $from++;
push @list, @_ > 1 ? \@_[1..$#_] : \FAST::List::Gen::Iterate::Default->new;
},
tail_size => sub {
push @tails, \$_[1]; weaken $tails[-1];
},
} => $class
},
purge => sub {Carp::croak 'can not purge iterative generator'},
load => sub {push @{$_[0]->cached}, \@_[1..$#_]},
PUSH => sub {
my $self = shift;
$self->_resize(0+@_);
push @{$self->cached}, \(@_)
},
lib/FAST/List/Gen.pm view on Meta::CPAN
$when_done->();
},
_when_done => sub :lvalue {$when_done},
from => sub {
croak "can not call ->from on started iterator"
if @last or $from;
push @last, @_ > 1 ? \@_[1..$#_] : \FAST::List::Gen::Iterate::Default->new;
$from = $last[-1];
},
tail_size => sub {
push @tails, \$_[1]; weaken $tails[-1];
},
} => $class
},
purge => sub {Carp::croak 'can not purge iterative generator'};
=item gather C< {CODE} [LIMIT] >
C< gather > returns a generator that is created iteratively. rather than
returning a value, you call C< take($return_value) > within the C< CODE >
lib/FAST/List/Gen.pm view on Meta::CPAN
my $say = $self =~ /(?:\b|^)say(?:\b|$)/
? "use feature 'say';"
: '';
my $fetch;
$self = (eval $say.$self
or Carp::croak "iterate error: $@\n$say$self\n");
return $self->from(@$pre) if $from and $pre;
$self->load(@$pre) if $pre and @$pre;
$fetch = tied(@$self)->can('FETCH');
weaken $fetch;
$self
}}
=item FAST::List::Gen C< ... >
the subroutine C< Gen > in the package C< List:: > is a dwimmy function that
produces a generator from a variety of sources. since C< FAST::List::Gen > is a fully
qualified name, it is available from all packages without the need to import it.
lib/FAST/List/Gen.pm view on Meta::CPAN
}
}
$size = $pos < $src_size
? @list + ($src_size - $pos)
: @list;
$$_ = $size for @tails;
${ $list[$i] }
},
fsize => sub {$size},
tail_size => sub {push @tails, \$_[1]; weaken $tails[-1]},
source => sub {$source},
_when_done => sub :lvalue {$when_done},
} => $class
};
sub filter_ (&;$$$) {
local $LOOKAHEAD;
&filter
}
lib/FAST/List/Gen.pm view on Meta::CPAN
$index = $idx;
for ($src_size - $pos + $idx) {
if ($size > $_) {
$size = $_;
$$_ = $size for @tails;
}
}
defined $ret ? $ret : ()
},
fsize => sub {$size},
tail_size => sub {push @tails, \$_[1]; &weaken($tails[-1])},
_when_done => sub :lvalue {$when_done},
rewind => $rewind,
index => sub {\$index},
} => $class;
};
=item While C<< {CODE} GENERATOR >>
=item Until C<< {CODE} GENERATOR >>
lib/FAST/List/Gen.pm view on Meta::CPAN
$done->($i + 1)
}
}
return $_
}
else {
$done->($src_size)
}
},
fsize => sub {$size},
tail_size => sub {push @tails, \$_[1]; weaken $tails[-1]},
source => sub {$source},
_when_done => sub :lvalue {$when_done},
} => $class
};
=item mutable C< GENERATOR >
=item C<< $gen->mutable >>
lib/FAST/List/Gen/Haskell.pm view on Meta::CPAN
package FAST::List::Gen::Haskell;
use strict;
use warnings;
use lib '../../';
use FAST::List::Gen::Lazy '*';
use Scalar::Util 'weaken';
sub DEBUG () {0}
our @EXPORT = qw (lazy L lazyx Lx fn now seq map_ unzip unzipn x_xs);
our @EXPORT_OK;
my $setup_export = sub {
@EXPORT_OK = keys %{{map {$_ => 1} @EXPORT, @FAST::List::Gen::EXPORT_OK}}
};
our %EXPORT_TAGS = (base => \@EXPORT, all => \@EXPORT_OK);
BEGIN {
no strict 'refs';
*import = *FAST::List::Gen::import;
lib/FAST/List/Gen/Lazy.pm view on Meta::CPAN
ref eq 'FAST::List::Gen::Thunk' ? $$_->() : $_
} $thunk->());
undef $thunk;
}
$$data[$n]
} => 'FAST::List::Gen::Thunk'
} 1 .. $returns
}
}
});
Scalar::Util::weaken($self);
if ($returns > 1) {
$will_return{$ret} = $returns;
}
$ret
}
}
{package
FAST::List::Gen::Function;
use overload fallback => 1,