<commit_before>#!/usr/bin/perl

# The MIT License (MIT)
# 
# Copyright (c) 2013 <NAME> (<EMAIL>)
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Basename qw(basename);
use Bio::SearchIO;
use Statistics::R;
use threads;

my $thread_max = 4; #default to running four threads
my $help = 0;
my $miSeq = 0;
my $fromK = 19; #default starting Kmer value is 19
my $toK = 201; #default ending emer value is 201
my $config;

#Print out command used to run script:
print "perl " . $0 . " ";foreach my $Argy (@ARGV) {print $Argy . " ";}print "\n\n\n";

GetOptions  ("config=s"         => \$config,
             "from=i"           => \$fromK,
             "to=i"             => \$toK,
             "threads=i"        => \$thread_max,
             "miseq"            => \$miSeq,
             "help|man"         => \$help,) || pod2usage(2);

pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1) if $help;

if ((!$fromK) or (!$toK) or (!$config)) {
    pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1);
}
if (($fromK % 2 != 1) or ($toK % 2 != 1)) {
    print "\n***Kmer value bounds (--from and --to) must both be odd integers.***\n\n";
    pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1);
}

# Generate commands to run
my (@R1s, @R2s, @names, @adapterFiles, @probesFiles);
open(my $configFH,"<",$config) or die "couldn't open $config for reading.\n";
while (my $line = <$configFH>) {
    next if ($line =~/^#/ or $line =~/^$/); #Don't use comments of blank lines
    chomp $line;
    my ($R1file, $R2file, $name, $adapterFile, $probesFile) = split ("\t", $line);
    push (@R1s, $R1file);
    push (@R2s, $R2file);
    push (@names, $name);
    push (@adapterFiles, $adapterFile);
    push (@probesFiles, $probesFile);
}
print "********** Parameters: **********\n";
foreach my $i (0..31) {
    print "perl velvetTarget.pl --R1 $R1s[$i] --R2 $R2s[$i] --name $names[$i] --adapters $adapterFiles[$i] --probes $probesFiles[$i] --from $fromK --to $toK\n";
}
print "********** End Parameters **********\n";

print "********** Ensuring all files in config file exist: **********\n\n";
foreach my $i (0..(scalar(@R1s)-1)) {
    print "Testing group $i from config file";
    unless (-e $R1s[$i] and -e $R2s[$i] and -e $adapterFiles[$i] and -e $probesFiles[$i]) {
        die "Stopping because one of the following files does not exist: $R1s[$i] $R2s[$i] $adapterFiles[$i] $probesFiles[$i]\n";
    }
}
print "********** Finished ensuring all files in config file exist: **********\n\n";

for (my $count = 0; $count <= (scalar(@R1s)-1); $count++) {
    my $pid = fork();
    if ($pid) {
        print "pid is $pid, parent $$\n";
    }
    
    
    
}




###################<commit_msg>Implemented forking via Parallel::ForkManager.<commit_after>#!/usr/bin/perl

# The MIT License (MIT)
# 
# Copyright (c) 2013 <NAME> (<EMAIL>)
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Basename qw(basename);
use Bio::SearchIO;
use Statistics::R;
use Parallel::ForkManager;

my $thread_max = 4; #default to running four threads
my $help = 0;
my $miSeq = 0;
my $fromK = 19; #default starting Kmer value is 19
my $toK = 201; #default ending emer value is 201
my $config;



#Print out command used to run script:
print "perl " . $0 . " ";foreach my $Argy (@ARGV) {print $Argy . " ";}print "\n\n\n";

GetOptions  ("config=s"         => \$config,
             "from=i"           => \$fromK,
             "to=i"             => \$toK,
             "threads=i"        => \$thread_max,
             "miseq"            => \$miSeq,
             "help|man"         => \$help,) || pod2usage(2);

pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1) if $help;

if ((!$fromK) or (!$toK) or (!$config)) {
    pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1);
}
if (($fromK % 2 != 1) or ($toK % 2 != 1)) {
    print "\n***Kmer value bounds (--from and --to) must both be odd integers.***\n\n";
    pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1);
}

# Generate commands to run
my (@R1s, @R2s, @names, @adapterFiles, @probesFiles);
open(my $configFH,"<",$config) or die "couldn't open $config for reading.\n";
while (my $line = <$configFH>) {
    next if ($line =~/^#/ or $line =~/^$/); #Don't use comments of blank lines
    chomp $line;
    my ($R1file, $R2file, $name, $adapterFile, $probesFile) = split ("\t", $line);
    push (@R1s, $R1file);
    push (@R2s, $R2file);
    push (@names, $name);
    push (@adapterFiles, $adapterFile);
    push (@probesFiles, $probesFile);
}
print "********** Parameters: **********\n";
foreach my $i (0..31) {
    print "perl velvetTarget.pl --R1 $R1s[$i] --R2 $R2s[$i] --name $names[$i] --adapters $adapterFiles[$i] --probes $probesFiles[$i] --from $fromK --to $toK\n";
}
print "********** End Parameters **********\n";

print "********** Ensuring all files in config file exist: **********\n\n";
foreach my $i (0..(scalar(@R1s)-1)) {
    print "Testing group $i from config file";
    unless (-e $R1s[$i] and -e $R2s[$i] and -e $adapterFiles[$i] and -e $probesFiles[$i]) {
        die "Stopping because one of the following files does not exist: $R1s[$i] $R2s[$i] $adapterFiles[$i] $probesFiles[$i]\n";
    }
}
print "********** Finished ensuring all files in config file exist: **********\n\n";


# Run assembly, blasting, and blast report processing using forks
print "Starting to run fork assembly jobs.\n\n";
my $forkManager = new Parallel::ForkManger($thread_max);

foreach my $forky (0..(scalar(@R1s)-1)) {
    $forkManager->start and next;
    ASSEMBLE($forky);
    $forkManager->finish;
}
$forkManager->wait_all_children;
print "Finished with all assemblies!\n\n";



###################
{'fraction_non_alphanumeric': 0.17267941969444087, 'fraction_numerical': 0.01566311464886378, 'mean_word_length': 3.4925028835063436, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7285313', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2519, 'n_words': 948}