how to run STRUCTURE command n times for each K value?
3
1
Entering edit mode
7.3 years ago
Ana ▴ 200

I am running some STRUCTURE analysis and set k = {1..10} by using this command (only 1 run for each K):

for k in seq10
do
python /home/ubuntu/bin/fastStructure/structure.py -K $k --input=../file.snps --output=snpl525D --format=str
done

Instead of 1 run for each K, now I want to get 15 runs for each K, could you please help me to modify the code above to do this job! thanks

STRUCTURE bash • 4.3k views
ADD COMMENT
0
Entering edit mode

It seems to me you are overwriting the output at each loop iteration.

ADD REPLY
2
Entering edit mode
7.3 years ago

Nest a per-k for loop inside a parent for loop:

$ for k in `seq 1 10`; do for eachK in `seq 1 15`; do echo "$k : $eachK"; done; done
1 : 1
1 : 2
1 : 3
1 : 4
1 : 5
...
10 : 13
10 : 14
10 : 15

As a comment notes, you may be overwriting output on each iteration. You can use the values of k and eachK to uniquely name the result.

ADD COMMENT
1
Entering edit mode
7.3 years ago

Since perl is still cool. Here's the gist,

perl -e 'print join "\n", (0..10)' | xargs -I {} -P 10 admixture -K {} -o {}.something

Edited:

   perl -e 'print join "\n", ((0..10) x 15)' | xargs -I {} -P 10 admixture -K {} -o {}.something
ADD COMMENT
0
Entering edit mode

I think, but am not certain, that the question is asking how to run 15 trials on each of ten values, not necessarily how to run ten jobs in parallel.

ADD REPLY
0
Entering edit mode

Alex Reynolds No problem, see edited answer. I love how fast and sleazy perl is.

ADD REPLY
0
Entering edit mode
7.3 years ago
ole.tange ★ 4.5k
doit() {
  k="$1"
  n="$2"
  python /home/ubuntu/bin/fastStructure/structure.py -K "$k" --input=../file.snps --output=snpl525D-"$k"-"$n" --format=str
}
export -f doit
parallel doit ::: {1..10} ::: {1..15}
ADD COMMENT

Login before adding your answer.

Traffic: 2375 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6