| 1 | # -*-CPerl-*- | ||||||||||||||||||||||||||||
| 2 | # Last changed Time-stamp: <2017-06-10 19:12:00 michl> | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Bio::ViennaNGS::Util; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Bio::ViennaNGS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Basename qw(fileparse basename); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IPC::Cmd qw(can_run run); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Path::Class qw(dir file); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Path qw(make_path remove_tree); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Math::Round; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Env qw(HOME); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 21 | 1 | our @EXPORT = (); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our @EXPORT_OK = qw ( bed_or_bam2bw sortbed bed2bigBed unique_array | |||||||||||||||||||||||||||
| 24 | kmer_enrichment fetch_chrom_sizes mkdircheck rmdircheck); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 28 | #^^^^^^^^^^ Variables ^^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 29 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | my %unique = (); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 34 | #^^^^^^^^^^^ Subroutines ^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 35 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub bed_or_bam2bw { | ||||||||||||||||||||||||||
|
Subroutine
bed_or_bam2bw: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($type,$infile,$chromsizes,$strand,$dest,$want_norm,$size,$scale,$log) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | my ($fn_bg_tmp,$fn_bg,$fn_bw,$fn,$bn,$path,$ext,$cmd); | |||||||||||||||||||||||||||
| 40 | 0 | my @processed_files = (); | |||||||||||||||||||||||||||
| 41 | 0 | my $factor = 1.; | |||||||||||||||||||||||||||
| 42 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | croak "ERROR [$this_function] \$type is '$type', however it is expected to be either 'bam' or 'bed'\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "bam" or $type eq "bed"
MC/DC0%0/2
$type eq "bam" or $type eq "bed"
$type eq "bam"
$type eq "bed"
Truth table0%0/3
A or B
A= $type eq "bam"B= $type eq "bed"
| |||||||||||||||||||||||||||||
| 45 | unless ($type eq "bam") || ($type eq "bed"); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $genomeCoverageBed = can_run('genomeCoverageBed') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | croak "ERROR [$this_function] genomeCoverageBed utility not found"; | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $bedGraphToBigWig = can_run('bedGraphToBigWig') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | croak "ERROR [$this_function] bedGraphToBigWig utility not found"; | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $awk = can_run('awk') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | croak "ERROR [$this_function] awk utility not found"; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if(defined $log){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | open(LOG, ">>", $log) or croak $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | print LOG "LOG [$this_function] \$infile: $infile\n"; | |||||||||||||||||||||||||||
| 57 | 0 | print LOG "LOG [$this_function] \$dest: $dest\n"; | |||||||||||||||||||||||||||
| 58 | 0 | print LOG "LOG [$this_function] \$chromsizes: $chromsizes\n"; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak "ERROR [$this_function] Cannot find $infile\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | unless (-e $infile); | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | unless (-d $dest); | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | croak "ERROR [$this_function] Cannot find $chromsizes\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | unless (-e $chromsizes); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($want_norm == 1){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $factor = $scale/$size; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | print LOG "LOG [$this_function] normalization: $factor = ($scale/$size)\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | if(defined $log); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($type eq "bam"){$ext = ".bam";} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | else{$ext = ".bed";} | |||||||||||||||||||||||||||
| 76 | 0 | $bn = basename($infile,$ext); | |||||||||||||||||||||||||||
| 77 | 0 | $fn = fileparse($infile); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $fn_bg_tmp = file($dest,$fn.".tmp.bg"); | |||||||||||||||||||||||||||
| 80 | 0 | $fn_bg = file($dest,$bn.".bg"); | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if($strand eq "+"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $fn_bw = file($dest,$bn.".pos.bw"); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||
| 85 | 0 | $fn_bw = file($dest,$bn.".neg.bw"); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $cmd = "$genomeCoverageBed -bg -scale $factor -split "; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($type eq "bed"){ $cmd .= "-i $infile -g $chromsizes"; } # chrom.sizes only required for processing BED | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | else { $cmd .= "-ibam $infile "; } | |||||||||||||||||||||||||||
| 91 | 0 | $cmd .= " > $fn_bg_tmp"; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if($strand eq "-"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $cmd .= " && cat $fn_bg_tmp | $awk \'{ \$4 = - \$4 ; print \$0 }\' > $fn_bg"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | else{ | ||||||||||||||||||||||||||||
| 97 | 0 | $fn_bg = $fn_bg_tmp; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | $cmd .= " && $bedGraphToBigWig $fn_bg $chromsizes $fn_bw"; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (defined $log){ print LOG "LOG [$this_function] $cmd\n";} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||
| 104 | run( command => $cmd, verbose => 0 ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if( !$success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | print STDERR "ERROR [$this_function] External command call unsuccessful\n"; | |||||||||||||||||||||||||||
| 108 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||||||||||||||||
| 109 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||
| 110 | 0 | croak $!; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if (defined $log){ close(LOG); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | unlink ($fn_bg_tmp); | |||||||||||||||||||||||||||
| 115 | 0 | unlink ($fn_bg); | |||||||||||||||||||||||||||
| 116 | 0 | return $fn_bw; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub bed2bigBed { | ||||||||||||||||||||||||||
|
Subroutine
bed2bigBed: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 0 | my ($infile,$chromsizes,$dest,$log) = @_; | |||||||||||||||||||||||||||
| 121 | 0 | my ($bn,$path,$ext,$cmd,$outfile); | |||||||||||||||||||||||||||
| 122 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | my $bed2bigBed = can_run('bedToBigBed') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | croak "ERROR [$this_function] bedToBigBed utility not found"; | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (defined $log){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | open(LOG, ">>", $log) or croak $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | print LOG "LOG [$this_function] \$infile: $infile -- \$chromsizes: $chromsizes --\$dest: $dest\n"; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | croak "ERROR [$this_function] Cannot find $infile" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | unless (-e $infile); | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | croak "ERROR [$this_function] Cannot find $chromsizes" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | unless (-e $chromsizes); | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | unless (-d $dest); | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # .bed6 .bed12 extensions are replaced by .bb | ||||||||||||||||||||||||||||
| 139 | 0 | ($bn,$path,$ext) = fileparse($infile, qr /\.bed[126]?/); | |||||||||||||||||||||||||||
| 140 | 0 | $outfile = file($dest, "$bn.bb"); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | $cmd = "$bed2bigBed $infile -extraIndex=name -tab $chromsizes $outfile"; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (defined $log){ print LOG "LOG [$this_function] $cmd\n"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||
| 145 | run( command => $cmd, verbose => 0 ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if( !$success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | print STDERR "ERROR [$this_function] Call to $bed2bigBed unsuccessful\n"; | |||||||||||||||||||||||||||
| 149 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||||||||||||||||
| 150 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||
| 151 | 0 | croak $!; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if (defined $log){ close(LOG); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | return $outfile; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub sortbed { | ||||||||||||||||||||||||||
|
Subroutine
sortbed: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 0 | my ($infile,$dest,$outfile,$rm_orig,$log) = @_; | |||||||||||||||||||||||||||
| 161 | 0 | my ($cmd,$out); | |||||||||||||||||||||||||||
| 162 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $bedtools = can_run('bedtools') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | croak "ERROR [$this_function] bedtools utility not found"; | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | croak "ERROR [$this_function] Cannot find $infile" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | unless (-e $infile); | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | unless (-d $dest); | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if (defined $log){open(LOG, ">>", $log) or croak $!;} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | $out = file($dest,$outfile); | |||||||||||||||||||||||||||
| 173 | 0 | $cmd = "$bedtools sort -i $infile > $out"; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (defined $log){ print LOG "LOG [$this_function] $cmd\n"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||
| 176 | run( command => $cmd, verbose => 0 ); | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if( !$success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | print STDERR "ERROR [$this_function] Call to $bedtools unsuccessful\n"; | |||||||||||||||||||||||||||
| 179 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||||||||||||||||
| 180 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||
| 181 | 0 | croak $!; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if($rm_orig){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | unlink($infile) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | carp "WARN [$this_function] Could not unlink $infile"; | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (defined $log){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | print LOG "[$this_function] removed $infile $!\n"; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if (defined $log){ close(LOG); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub unique_array{ | ||||||||||||||||||||||||||
|
Subroutine
unique_array: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | my $arrayref = shift; | |||||||||||||||||||||||||||
| 198 | 0 | my @array = @{$arrayref}; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | foreach my $item (@array) | |||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||
| 202 | 0 | $unique{$item} ++; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | 0 | my @arrayuid = sort {$a cmp $b} keys %unique; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | return(\@arrayuid); | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub kmer_enrichment{ | ||||||||||||||||||||||||||
|
Subroutine
kmer_enrichment: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my @seqs = @{$_[0]}; | |||||||||||||||||||||||||||
| 212 | 0 | my $klen = $_[1]; | |||||||||||||||||||||||||||
| 213 | # my @seq = split( //, $read_tmp ); | ||||||||||||||||||||||||||||
| 214 | 0 | my $kstring =''; | |||||||||||||||||||||||||||
| 215 | #return variables | ||||||||||||||||||||||||||||
| 216 | 0 | my %km; | |||||||||||||||||||||||||||
| 217 | 0 | foreach my $sequences (@seqs){ | |||||||||||||||||||||||||||
| 218 | # print STDERR $sequences,"\n"; | ||||||||||||||||||||||||||||
| 219 | 0 | my @seq = split( //, $sequences ); | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | for ( my $seq_pos = 0; $seq_pos <= $#seq-$klen ; $seq_pos++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | for (my $i=$seq_pos;$i<=$seq_pos+($klen-1);$i++){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | $kstring .= $seq[$i]; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 0 | $km{$kstring}++; | |||||||||||||||||||||||||||
| 225 | 0 | $kstring = ""; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 0 | return( \%km ); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub fetch_chrom_sizes{ | ||||||||||||||||||||||||||
|
Subroutine
fetch_chrom_sizes: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | 0 | my $species = shift; | |||||||||||||||||||||||||||
| 233 | 0 | my %sizes; | |||||||||||||||||||||||||||
| 234 | my @chromsize; | ||||||||||||||||||||||||||||
| 235 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my $test_fetchChromSizes = can_run('fetchChromSizes') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | croak "ERROR [$this_function] fetchChromSizes utility not found"; | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | my $cmd = "fetchChromSizes $species"; | |||||||||||||||||||||||||||
| 241 | 0 | my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||
| 242 | run(command => $cmd, verbose => 0); | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($success){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | @chromsize = @{$stdout_buf}; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | else{ | ||||||||||||||||||||||||||||
| 247 | 0 | carp "WARN [$this_function] Using UCSCs fetchChromSizes failed, trying alternative mysql fetch!\n"; | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $test_fetchChromSizes = can_run('mysql') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | croak "ERROR [$this_function] mysql utility not found"; | ||||||||||||||||||||||||||||
| 250 | 0 | $cmd = "mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \"select chrom, size from $species.chromInfo\""; ### Alternative to UCSC fetchChromSizes, has mysql dependency | |||||||||||||||||||||||||||
| 251 | 0 | my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||
| 252 | run(command => $cmd, verbose => 0); | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($success){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | @chromsize = @{$stdout_buf}; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | else{ | ||||||||||||||||||||||||||||
| 257 | 0 | carp "ERROR [$this_function] External command call unsuccessful\n"; | |||||||||||||||||||||||||||
| 258 | 0 | carp "ERROR [$this_function] this is what the command printed:\n"; | |||||||||||||||||||||||||||
| 259 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||
| 260 | 0 | confess "Fetching of chromosome sizes failed, please either download fetchChromSizes from the UCSC script collection, or install mysql!\n"; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | foreach (@chromsize){ | |||||||||||||||||||||||||||
| 265 | 0 | chomp($_); | |||||||||||||||||||||||||||
| 266 | 0 | foreach (split(/\n/,$_)){ | |||||||||||||||||||||||||||
| 267 | 0 | my ($chr,$size)=split (/\t/,$_); | |||||||||||||||||||||||||||
| 268 | 0 | $sizes{$chr}=$size; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | return(\%sizes); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 0 | ▶ | sub mkdircheck { | ||||||||||||||||||||||||||
|
Subroutine
mkdircheck: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 276 | 0 | my @dirstocreate=(); | |||||||||||||||||||||||||||
| 277 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 278 | 0 | ▶ | while(@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | push @dirstocreate, shift(@_); | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | 0 | foreach (@dirstocreate){ | |||||||||||||||||||||||||||
| 282 | 0 | my @total = split(/[\/\\]/,$_); | |||||||||||||||||||||||||||
| 283 | 0 | ▶ | if ($total[0] eq '~'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 0 | $total[0]=$HOME; | |||||||||||||||||||||||||||
| 285 | 0 | carp "WARNING [$this_function] replacing \'~\' in path with \'$HOME\'"; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 0 | my $dir; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | while(@total){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | $dir = dir(shift(@total)) unless (defined $dir); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | $dir = dir($dir,shift(@total)); | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | 0 | my $check = $dir->stringify(); | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | return if (-d $check); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | make_path($dir,{ verbose => 0 }) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | croak "ERROR [$this_function] Cannot create directory $check"; | ||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub rmdircheck { | ||||||||||||||||||||||||||
|
Subroutine
rmdircheck: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 300 | 0 | my @dirstorm=(); | |||||||||||||||||||||||||||
| 301 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||
| 302 | 0 | ▶ | while(@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 0 | push @dirstorm, shift(@_); | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | 0 | foreach (@dirstorm){ | |||||||||||||||||||||||||||
| 306 | 0 | my @total = split(/[\/\\]/,$_); | |||||||||||||||||||||||||||
| 307 | 0 | my $dir; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | while(@total){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $dir = dir(shift(@total)) unless (defined $dir); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | $dir = dir($dir,shift(@total)); | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | 0 | my $check = $dir->stringify(); | |||||||||||||||||||||||||||
| 313 | 0 | ▶ | return if (!-d $check); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | 0 | ▶ | remove_tree($dir,{ verbose => 0 }) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | croak "ERROR [$this_function] Cannot remove directory $check"; | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 1 | 1; | |||||||||||||||||||||||||||
| 320 | __END__ | ||||||||||||||||||||||||||||