0

I need to create a loop to make 2 variables (numerical) increase, one according to the other and all related to a job I have to send to a cluster.

Basically I have to create various groups, and these groups are defined by these 2 variables; for instance 1st group goes from 1 to 10 (1 would be the 1st variable, 10 the 2nd), the 2nd group 11-20 and so on...

I'm creating 169 groups because I have 1690 individuals, and I'm running a script for Chromopainter 169 times (one per each of these groups).

I want to tell my script:

given the initial variables 1 and 10, do the script, increment of 10 for each of the variable and do again the script (loop). I know that to increment the variables I can do this:

for i in {0..159..10}
for j in {10..169..10}

But I can't manage to apply it to the entire thing. This is what I wrote so far:

for count in {1..169}
do
    sbatch -J estimate.chr1 -o estimate.chr1.out -e estimate.chr1.error --wrap="module load ChromoPainter/2;
ChromoPainterv2 -g filename.chr1.phase -r fil.recombfile -t IDFILE_FORMAT.txt -o filename.chr1._ChPestimate.$count -a $i $j -i 15 -in -iM"
done

If I want to send the script singularly, for the first group it would work like this:

ChromoPainterv2 -g filename.chr1.phase -r fil.recombfile -t IDFILE_FORMAT.txt -o filename.chr1._ChPestimate.$count -a 1 10 -i 15 -in -iM

Any idea? Thank you in advance

Gf.Ena
  • 17
  • 6
  • `1st group goes from 1 to 10 (1 would be the 1st variable, 10 the 2nd), the 2nd group 21-30` What happens for 11 to 20? I do not understand. Could you _post_ the number _pairs_ you want to generate? You want to have pairs `(1,1),(1,2),(1,3),...(1,10),(2,11)(2,12)....(2,20),(3,21)...(3,30) etc.`? – KamilCuk Nov 16 '21 at 12:52
  • Yes sorry, it was an error of distraction. 2nd group would be 11 to 20 – Gf.Ena Nov 16 '21 at 13:40

2 Answers2

0

loop to make 2 variables (numerical) increase, one according to the other

1 to 10 (1 would be the 1st variable, 10 the 2nd),

So just divide by 10, the relation is a linear relation.

for count in {1..169}; do
   i=$count
   j=$(( 1 + (i - 1) / 10 ))
   printf "%d %d\n" "$i" "$j"
done
KamilCuk
  • 96,430
  • 6
  • 33
  • 74
  • Thank you very much, I am running the version posted above right now (it will take some hours) then I will verify the logs. Your version also looks useful – Gf.Ena Nov 16 '21 at 14:15
0

I think you are overengineering the issue. Use your $count as the main source for the other numbers you need. And basing it on zero simplifies the calculus:

for count in {0..168}
do
    i=$((count*10+1))
    j=$(((count+1)*10))
    
    sbatch -J estimate.chr1 -o estimate.chr1.out -e estimate.chr1.error --wrap="module load ChromoPainter/2; ChromoPainterv2 -g filename.chr1.phase -r fil.recombfile -t IDFILE_FORMAT.txt -o filename.chr1._ChPestimate.$((count+1)) -a $i $j -i 15 -in -iM"
done
Poshi
  • 4,817
  • 3
  • 13
  • 28
  • Thank you very much, I am running it right now (it will take some hours) then I will see the logs to verify how it worked. So far it looks like it's running correctly – Gf.Ena Nov 16 '21 at 14:14