I am running 325 vcftools commands to generate Fst values, which obviously needs to be automated.
An example:
vcftools --vcf big.vcf --weir-fst-pop pop_lists/pop1.txt --weir-fst-pop pop_lists/pop2.txt --out weir_fst_results/pop1_vs_pop2
and when I run this job, it works fine when I run it one by one by the command line, i.e. there are two files:
pop1_vs_pop2.log
and
pop1_vs_pop2.weir.fst
I need to get the Fst values from the log file.
The problem is that the log files are not generated when I run from my perl script, even though the commands executed are identical.
This sounds so trivial, but if it’s not producing the log file, I’m wasting my time.
How can I get vcftools to produce the log file when executing from a script? why isn’t vcftools producing the log file?
Perhaps there is a way of calculating this that doesn’t involve using vcftools?
the script to run them:
sub execute {
my $command = shift;
print "Executing: $commandn";
if (system($command) != 0) {
say "$command failed.";
die
}
}
my @pop = list_regex_files('^[A-Y]{3}.txt$', 'ethnicity_lists');
my $outdir="weir_fst_results";
if (not -d $outdir) {
mkdir $outdir
}
my $vcf="big.vcf";
if (not -e $vcf) {
say "$vcf doesn't exist.";
die
}
foreach my $pop1 (0..$#pop) {
my $label1;
if ($pop[$pop1] =~ m/^ethnicity_lists/([A-Y]{3}).txt$/) {
$label1 = $1
} else {
say "$pop[$pop1] failed regex.";
die;
}
foreach my $pop2 (($pop1+1)..$#pop) {
my $label2;
if ($pop[$pop2] =~ m/^ethnicity_lists/([A-Y]{3}).txt$/) {
$label2 = $1
} else {
say "$pop[$pop2] failed regex.";
die;
}
my $out_prefix = "weir_fst_results/$label1" . "_vs_$label2";
my $cmd = "vcftools --vcf $vcf ";
$cmd .= "--weir-fst-pop $pop[$pop1] --weir-fst-pop $pop[$pop2] ";
$cmd .= " --out $out_prefix > $out_prefix.out";
execute($cmd);
}
}
If I try to execute each comparison in a separate directory, with a separate nohup
command, unfortunately all command output is still routed to the source nohup.out
, and then the log file is empty, which defeats the purpose of running this.
Read more here: Source link