#!/usr/bin/perl use strict; use File::Find; use Parallel::ForkManager; my @toParse; # array of chip files foreach(@toParse){ my $encryptKey = $_; #Encrypted for patients my @name = split /\//, $fileManifest{$encryptKey}; #hash contains the directories my $id = pop(@name); # @name is an array of the directory, last element is the sample ID my $perlOut = join "\/",@name; # directory for perl commands my @safeID = split / /, $id; my $safeDirect = $perlOut."/".$safeID[0]; # hipaa compliant next if($safeID[0 ] =~ /cgo/ig); #----------------------------------------------------------------- # Prepare the commands for conversion #----------------------------------------------------------------- my $cychpCommand = $fileManifest{$encryptKey}; #directory of the cychp file $cychpCommand =~ s/\//\\/g; # Format the directory for windows and for the affy program $cychpCommand = "\"".$cychpCommand."\""; my $cychpTxtOut = join "\\", @name; #CYCHP TXT OUTPUT DIRECTORY $cychpTxtOut ="\"".$cychpTxtOut."\""; my $affyCommand = "apt-chp-to-txt -o ".$cychpTxtOut." ".$cychpCommand; unless(exists($cychpLog{$encryptKey})) { my $rmCom = $perlOut."/apt-chp-to-txt.log"; push @toConvert1, $affyCommand; # To send commands for conversion push @toConvert2, $rmCom; # To remove the log files $cychpLog{$encryptKey}++; $timestamp = localtime(time); open LOG, ">>".$logFileName; print LOG "$encryptKey\t$safeID[0]\t$safeDirect\t-\t-\t$timestamp\n"; close(LOG); } } #----------------------------------------------------------------- # Begin forking #----------------------------------------------------------------- my $maxProcs = scalar(@toConvert1); my $pm = new Parallel::ForkManager($maxProcs); foreach(@toConvert1){ my $pid = $pm-> start and next; # FORK Begin system($_); # CONVERSION COMMAND $pm->finish; # End of FORK } $pm->wait_all_children; # Blocks until all children are finished foreach(@toConvert2){ unlink $_; #Delete log files made by the conversion program } foreach(@toParse){ my $txtFile = $_.".txt"; open IN, $txtFile or die "Cannot open [$txtFile]\n";   while(){ parsing happens here } }