| 1 | package Bio::Gonzales::Var::Util; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our $VERSION = 0.01_01; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | our %EXPORT_TAGS = ( 'all' => [qw/geno2haplo renumber_genotypes merge_alleles only_geno/ ] ); | |||||||||||||||||||
| 14 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub geno2haplo { | ||||||||||||||||||||
| 17 | 0 | ▶ | my $genotypes = shift; | ||||||||||||||||||
|
Subroutine
geno2haplo: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | # check if also coverage, etc. is part of the genotype then | ||||||||||||||||||||
| 19 | # split the genotypes into haplotypes | ||||||||||||||||||||
| 20 | 0 | my @haplotypes; | |||||||||||||||||||
| 21 | 0 | my $phased = 1; | |||||||||||||||||||
| 22 | 0 | for my $g_raw (@$genotypes) { | |||||||||||||||||||
| 23 | 0 | ▶ | my $g = index( $g_raw, ':' ) >= 0 ? substr( $g_raw, 0, index( $g_raw, ':' ) ) : $g_raw; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | # we need to find only one genotype of x/y to set phased to false | ||||||||||||||||||||
| 25 | 0 | ▶ | $phased &&= not index( $g, '|' ) < 0; | ||||||||||||||||||
|
Condition0%0/3
$phased &&= !index($g, "|") == -1
MC/DC0%0/2
$phased &&= !index($g, "|") == -1
$phased
!index($g, "|") == -1
Truth table0%0/3
A &&= not(B)
A= $phasedB= !index($g, "|") == -1
| |||||||||||||||||||||
| 26 | 0 | push @haplotypes, split /[|\/]/, $g; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 0 | return ( \@haplotypes, $phased ); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | sub only_geno { | ||||||||||||||||||||
| 32 | 0 | ▶ | my $genotypes = shift; | ||||||||||||||||||
|
Subroutine
only_geno: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 33 | 0 | ▶ | my @res = map { index( $_, ':' ) >= 0 ? substr( $_, 0, index( $_, ':' ) ) : $_ } @$genotypes; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub renumber_genotypes { | ||||||||||||||||||||
| 37 | 1 | ▶ | my ( $map , $genotypes, ) = @_; | ||||||||||||||||||
|
Subroutine
renumber_genotypes: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||
| 38 | 1 | my @renumbered; | |||||||||||||||||||
| 39 | 1 | for my $g_raw (@$genotypes) { | |||||||||||||||||||
| 40 | 3 | my $idx = index( $g_raw, ':' ); | |||||||||||||||||||
| 41 | 3 | ▶ | my $g = $idx >= 0 ? substr( $g_raw, 0, $idx ) : $g_raw; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 3 | my @g_split = split /([|\/])/, $g; | |||||||||||||||||||
| 43 | 3 | ▶ | for ( my $i = 0; $i < @g_split; $i += 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 6 | ▶ | $g_split[$i] = $map->[ $g_split[$i] ] if($g_split[$i] ne '.'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 3 | ▶ | if($idx < 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | $g_raw = join '', @g_split; | |||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||
| 49 | 3 | substr( $g_raw, 0, $idx, join( '', @g_split)); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 1 | return $genotypes; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | sub merge_alleles { | ||||||||||||||||||||
| 56 | 0 | ▶ | my ( $ref_alleles, $alleles ) = @_; | ||||||||||||||||||
|
Subroutine
merge_alleles: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | my $i = 0; | |||||||||||||||||||
| 59 | 0 | my %ra = map { $_ => $i++ } @$ref_alleles; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | my @map; | |||||||||||||||||||
| 62 | 0 | my @merged_alleles = @$ref_alleles; | |||||||||||||||||||
| 63 | 0 | my $allele_idx = @$ref_alleles; | |||||||||||||||||||
| 64 | 0 | ▶ | for ( my $idx = 0; $idx < @$alleles; $idx++ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | ▶ | if ( defined $ra{ $alleles->[$idx] } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | $map[$idx] = $ra{ $alleles->[$idx] }; | |||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||
| 68 | 0 | $map[$idx] = $allele_idx++; | |||||||||||||||||||
| 69 | 0 | push @merged_alleles, $alleles->[$idx]; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | 0 | return ( \@merged_alleles, \@map ); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||