Bio-MUST-Apps-TwoScalp

 view release on metacpan or  search on metacpan

bin/two-scalp.pl  view on Meta::CPAN

#### fam: @ord_fams
##### %seqs_for

FAM:
for my $fam (@ord_fams) {
    ### Check if seqs are aligned from part: $fam

    # TODO: fix this as it is very dangerous to have my depending on if
    # https://metacpan.org/pod/Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations
    ## no critic (ProhibitConditionalDeclarations)
    my $ali = Ali->new( seqs => $seqs_for{$fam}, guessing => 1 )
        if $seqs_for{$fam};
    ## use critic

    unless ($ali) {
        carp "Warning: no sequence found for family: $fam";
        next FAM;
    }

    if ($fam eq 'other') {
        ### Degap seqs from families not specified

bin/two-scalp.pl  view on Meta::CPAN

        = part { $_->is_aligned ? 1 : 0 } $ali->all_seqs;
        #= part { $_->is_aligned ? 1 : 0 } $seqs_for{$fam};

    my $p2;

    # TODO: check how to simplify complex alternatives here

    if ($aligned_seqs) {
        my $aligned = Ali->new(
            seqs => $aligned_seqs,
            guessing => 1,
        );

        if ($unaligned_seqs) {
            my $unaligned = Ali->new(
                seqs => $unaligned_seqs,
                guessing => 1,
            );
            ### Align non aligned seqs on aligned seqs from the same family
            $p2 = align_on_profile($aligned, $unaligned);
        }
        $p2 = $aligned unless $p2;
    }

    elsif ($unaligned_seqs && $master_profile) {
        ### There are only unaligned seqs in this family
        my $unaligned = Ali->new(
            seqs => $unaligned_seqs,
            guessing => 1,
        );
        $p2 = $unaligned;
    }

    if ($master_profile) {
        my $new_master_profile = align_on_profile($master_profile, $p2);
        $master_profile = $new_master_profile;
    }

    # align from scratch only if only unaligned seqs and no other family

bin/two-scalp.pl  view on Meta::CPAN


    return $new_profile;
}


sub align_from_scratch {
    my $seqs = shift;

    my $toalign = Ali->new(
        seqs => $seqs,
        guessing => 1,
    );
    $toalign->degap_seqs;

    unless ($toalign->has_uniq_ids) {
        ### non uniq seq id
        $toalign = uniq_ids($toalign);
    }

    my ($toalign_file, $toalign_mapper) = $toalign->temp_fasta;

bin/two-scalp.pl  view on Meta::CPAN

                &&   $seqs[$i]->is_subseq_of($seqs[$i-1]) ) ) {
                carp "Warning: duplicate ids but different sequences for: $dup";
            }
        }
    }

    my @uniq_ids = uniq @ids;
    my @seq_uniq_ids = map { $ali->get_seq_with_id($_) } @uniq_ids;
    my $ali2 = Ali->new(
        seqs => \@seq_uniq_ids,
        guessing => 1,
    );

    return $ali2;
}


# TODO: check if args are better served with 'repeatable' or '...'

__END__

lib/Bio/MUST/Apps/TwoScalp/AlignAll.pm  view on Meta::CPAN

    required => 1,
    coerce   => 1,
);

has 'ali' => (
    is       => 'ro',
    isa      => 'Bio::MUST::Core::Ali',
    init_arg => undef,
    writer   => '_set_ali',
#   handles  => qr{.*}xms,     # DO NOT WORK... WHY??
    handles  => [ qw( all_seqs all_seq_ids dont_guess restore_ids
        store_fasta temp_fasta count_seqs has_uniq_ids ) ],
);

has 'options' => (
    traits   => ['Hash'],
    is       => 'ro',
    isa      => 'HashRef',
    default  => sub { {} },
);



( run in 0.661 second using v1.01-cache-2.11-cpan-748bfb374f4 )