By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,662 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,662 IT Pros & Developers. It's quick & easy.

forkmanager takes too long when I set children

P: 1
Hi all,

I've made the script below to calculate the coverage per position of small pieces of strings. It works fine but when I tried to speed thing up for large files using forkmanager the script takes an awful lot of time when I set 2 parallel forks. Setting it to 0 works fine. Does anybody have an idea what is going wrong?

Kind Regards
Jaap


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl -w
  2. use Parallel::ForkManager;
  3. use strict;
  4.  
  5. if(scalar(@ARGV) != 3){
  6.     print "Please use the correct parameters\nUsage: bowtie2wiggle.pl -infile -outfile- -processes-\n";
  7.     exit();
  8. }
  9.  
  10. my $pm = new Parallel::ForkManager($ARGV[2]); 
  11. my %hash=();
  12. open (IN, $ARGV[0]);
  13. while (<IN>){
  14.     $pm->start and next;
  15.     $_ =~ s/\n|\r//;
  16.     my @element=split(/\t/,$_);
  17.     $element[2] =~ s/T//;
  18.     for (my $i=1;$i<=length($element[4]);$i++){
  19.         $hash{$element[2]}{($element[3]+$i)}{coverage}++;
  20.     }
  21.     $pm->finish;
  22. }
  23. $pm->wait_all_children;
  24. close IN;
  25.  
  26. open (OUT, ">$ARGV[1]");
  27. print OUT 'track type=wiggle_0 name="'.$ARGV[0].'" description="theoretical coverage from '.$ARGV[0].'" visibility=full autoScale=on color=50,150,255'."\n";
  28.  
  29. my $old="";
  30. foreach my $chromosome (sort keys %hash){
  31.     print OUT "variableStep chrom=chr$chromosome span=1\n";
  32.     foreach my $position (sort {$a<=>$b} keys %{$hash{$chromosome}}){
  33.         if ($old ne "" && $old != ($position-1)){
  34.             print OUT "variableStep chrom=chr$chromosome span=1\n";
  35.         }
  36.         print OUT "$position $hash{$chromosome}{$position}{coverage}\n";
  37.         $old=$position;
  38.     }
  39. }
  40. close OUT;
Sep 23 '10 #1
Share this Question
Share on Google+
1 Reply


numberwhun
Expert Mod 2.5K+
P: 3,503
I would help you if I had experience with forkmanager, but I have not used it. Hopefully someone will be able to help you.
Oct 8 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.