Reputation: 301
I have a script below, I am looping throught GTEx brain tissues and running a program laid out below. How do I in the --output put a unique output file? I am lost on this, still kind of new to bash. BTW, TISSUE files look like this: Brain_Frontal_Cortex_BA9.genes.annot
and Lung.genes.annot
In the GTExV8 folder, I have 48 unique files that TISSUE will loop through. Thus, the output for one example would be Brain_Frontal_Cortex_BA9_emagma
and Lung_emagma
#!/bin/bash
for TISSUE in GTExV8/*;
do
./magma
--bfile g1000_eur
--gene-annot $TISSUE
--pval Summary_Statistics_GWAS_2016/ALSGWAS.txt ncol=Ne
--gene-settings adap-permp=10000
--out LABEL WITH EACH TISSUE LOOPED
done
Upvotes: 0
Views: 299
Reputation: 117258
Using Parameter Expansion you can extract the part of the $TISSUE
variable that you'd like to use in your output filename.
for TISSUE in GTExV8/*;
do
# remove the directory part:
outfile="${TISSUE##*/}"
# remove the file extension:
outfile="${outfile%%.genes.annot}"
# add a filename ending:
outfile="${outfile}_emagma"
# use $outfile:
./magma ... --gene-annot "$TISSUE" --out "$outfile"
done
Upvotes: 2
Reputation: 69198
No sure what you mean, but if your intention is to generate different names for the --out
files based on the $tissue
file name, and assuming BA9
is the variable part and you want to name the output after it, you can do
#!/bin/bash
for tissue in GTExV8/*;
do
IFS='_.' a=( $tissue )
./magma \
--bfile g1000_eur \
--gene-annot $tissue \
--pval Summary_Statistics_GWAS_2016/ALSGWAS.txt ncol=Ne \
--gene-settings adap-permp=10000 \
--out Amygdala_emagma_${a[3]}
done
which is splitting the $tissue
name in an array a
to get ${a[3]}
Upvotes: 0