in reply to Running executables with perl using system command
First, your inner loop reads the ODIR directory all the way through, so there's nothing to read in the second iteration of the outer loop. Second, since you've opened the directory and are putting files in it while you have it open, I don't know that there's any guarantee that you won't miss a file. You could fix both problems by opening ODIR just before the start of the second loop. Alternatively, you could use a glob to find the matching filenames, rather than scanning through all of them.
However, there's a better way: Since you already know the name of the file, there's no reason to scan through the directory for it. Instead, just open your file. Since you pass in $sample on the command line, there's no reason to use the opendir / readdir and regular expression.
my $cmd1 = "java -Xmx2G -jar $rootdir/celConverter/CelFileConverter.ja +r -m $rootdir/celConverter/Snp6FeatureMappings.csv -c $rootdir/cdf/Ge +nomeWideSNP_6.fromDB.cdf -s $celdir/ -t $rootdir/outdir/raw"; system($cmd1); my $dir = "$rootdir/outdir/output2/$sample" . "_feature.TXT"; opendir(DIR, "$rootdir/outdir/raw") || "Cannot open the directory $!\n +"; foreach my $file (readdir(DIR)){ if($file =~ /feature_intensity$/){ #my $cmd = "sh run_preprocessing.sh $rootdir/Matlab_Compilet_Runti +me/v710/ $file $rootdir/info/ $rootdir/outdir/raw/ $rootdir/outdir/ou +tput/ $rootdir/outdir/ PRIMARY 0.5"; #warn "Running $cmd... \n"; #system($cmd); #outputs ploidy_3456_feature.TXT.csv #output from the previous system cmd. $file2 = "ploidy_" . $sample . "_feature.TXT.csv"; open FILE, "<", $dir/$file2" or "Cannot open the file $file2 $!\n"; while(<FILE>){ chomp; my ($in_pi,$in_ploidy,$in_alpha) = split(/,/); my $cmd2 = "sh run_HMM.sh $rootdir/Matlab_Compilet_Runtime/v710/ + $file $rootdir/info/ $rootdir/outdir/output/ $rootdir/outdir/ 10 $in +_pi $in_ploidy $in_alpha"; warn "Running $cmd2\n"; system($cmd2); } close FILE; } }
I've cleaned up your indentation a little to make the code easier to follow, and used the three-argument form of open, as a reminder that it's generally accepted as the better form to use.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Running executables with perl using system command
by Anonymous Monk on Jan 26, 2011 at 13:50 UTC |