简体   繁体   中英

How to remove Parallel::Forkmanager from my Perl script?

I have been out of the coding game for a couple of years and I do not have experience with Perl. I have a Perl script that I am trying to get through, but part of it is based on Parallel::Forkmanager .

At the moment I do not need this, but I do not know the language of Perl well enough to transform this part of my code into something where it does not rely on Parallel::Forkmanager , even though the answer is probably very simple.

PS: I could leave it in, but somehow I cannot get Parallel::Forkmanager installed correctly either, even with the advice given by many of you on different threads of this forum and other fora... But that would be another question. For now I am just trying to understand basic Perl.


use strict;
use warnings;
use Parallel::ForkManager;    <- so this is what I do not want


#From Dummyset:
my @samples = ("F1_A_S383_L007", "F1_B_S384_L007");

print "Processing " . scalar(@samples) . " samples\n";


### Trim adapters
unless (-d "skewer") {
    mkdir "skewer";
}

my @skewerCommands;
foreach my $sample (@samples) {
    my $R1 = "reads/" . $sample . "_R1_001.fastq.gz";
    my $R2 = "reads/" . $sample . "_R2_001.fastq.gz";

    my $adapterFile = "universal.adapters";

    # Make sure the adapter file exists
    unless (-e $adapterFile) {die "$adapterFile not present!\n";}

    my $skewerBaseName = "skewer/" . $sample;

    push(@skewerCommands, "<right_path_to>/skewer-0.2.2/skewer --quiet -x $adapterFile -m pe $R1 $R2 -L 150 -e -z -o $skewerBaseName");
}
#print "Running all skewer commands\n";
my $skewerFM = Parallel::ForkManager->new(46);    #this is where I do not know a solution
foreach my $skewerCommand(@skewerCommands) {
    $skewerFM->start and next;
#    print "Running the following command: \n$skewerCommand\n";
 #   system($skewerCommand);
    $skewerFM->finish;
}
$skewerFM->wait_all_children();
#print "Finished running all skewer commands\n";  ```


Parallel::Forkmanager is a parallelism option. It was probably put in to significantly accelerate this code's running, and by taking it out again - you might regret it.

However - the core part that's running in parallel is here:

my $skewerFM = Parallel::ForkManager->new(46);    #this is where I do not know a solution
foreach my $skewerCommand(@skewerCommands) {
    $skewerFM->start and next;
#    print "Running the following command: \n$skewerCommand\n";
 #   system($skewerCommand);
    $skewerFM->finish;
}
$skewerFM->wait_all_children();

You instantiate a forkmanager. You run code between 'start' and 'finish'. And then you wait for everything to finish.

Between start and finish - you don't actually do anything, because it's commented out.

So just delete that whole block, and the use Parallel::ForkManager; line, and you'll be fine.

Although, you might want to figure out what $skewerCommand is for, why it was running before, and why it isn't running now.

Because without that, you've basically made your entire code redundant.

If however, that's not meant to be commented, you can just excise these lines:

my $skewerFM = Parallel::ForkManager->new(46);    #this is where I do not know a solution
    $skewerFM->start and next;
    $skewerFM->finish;
$skewerFM->wait_all_children();

(And the initial use line).

Then your code will iterate each row in @skewerCommands and run the system command on each of them - but will do it serially, rather than 46 ways in parallel. (So you can expect it to be WAY slower).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM