This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Run program with different chromosome number every iteration

I'm running the FUSION.assoc_test.R program from the fusion_twas package and I'm trying to write a simple piece of code that will allow me to loop through the program and substitute with a different chromosome number with every iteration.

So far I have:

for i in {1..22..1}
do
   Rscript ./FUSION.assoc_test.R \
    --sumstats PGC2.SCZ.sumstats \
    --weights ./WEIGHTS/GTEx.Whole_Blood.pos \
    --weights_dir ./WEIGHTS/ \
    --ref_ld_chr ./LDREF/1000G.EUR. \
    --chr $i \
    --out "PGZ_"$i".dat"
done

exit 0

When I try this I get an error:

Error in file(file, "rt") : cannot open the connection
Calls: read_plink -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
  cannot open file './LDREF/1000G.EUR..bim': No such file or directory
Execution halted

which I assume arises because there wasn't a chromosome defined.

Any help would be appreciated.

Thanks!

twas software error

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

I assume you checked if the file './LDREF/1000G.EUR..bim' exists?
The .. looks a bit strange, so I guess --ref_ld_chr ./LDREF/1000G.EUR. should be changed to --ref_ld_chr ./LDREF/1000G.EUR

and without the loop ? does it work ?

 Rscript ./FUSION.assoc_test.R \
    --sumstats PGC2.SCZ.sumstats \
    --weights ./WEIGHTS/GTEx.Whole_Blood.pos \
    --weights_dir ./WEIGHTS/ \
    --ref_ld_chr ./LDREF/1000G.EUR. \
    --chr 1 \
    --out "PGZ_1.dat"

Thanks for the tip on readability- It works fine without the loop.

and what is the shell ? it's not bash because {1..2..1} is not a bash syntax.

using 'echo', what is the output of ?

for i in {1..22..1}
do
   echo Rscript ./FUSION.assoc_test.R \
    --sumstats PGC2.SCZ.sumstats \
    --weights ./WEIGHTS/GTEx.Whole_Blood.pos \
    --weights_dir ./WEIGHTS/ \
    --ref_ld_chr ./LDREF/1000G.EUR. \
    --chr $i \
    --out "PGZ_"$i".dat"
done

1 answer

try to use the bash syntax:

for i in $(seq 1 22 )
do
   Rscript ./FUSION.assoc_test.R \
    --sumstats PGC2.SCZ.sumstats \
    --weights ./WEIGHTS/GTEx.Whole_Blood.pos \
    --weights_dir ./WEIGHTS/ \
    --ref_ld_chr ./LDREF/1000G.EUR. \
    --chr $i \
    --out "PGZ_$i.dat"
done

Log in to answer this question.