2

Beginner here trying to get a pipeline working in bash. If somebody can see why when I run the following I get:

-bash: `$i': not a valid identifier,

that would be really helpful. Also if there are other mistakes please let me know

for $i in /home/regionstextfile; do tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt; done

The idea is for each line in regionstextfile (which contains genome coordinates) run a program called tabix in the vcf.bz file, then with the output run vcftools with the specified options, then put all the outputs into the genomesregions.txt file.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user964689
  • 812
  • 7
  • 20
  • 40

2 Answers2

8

That must be so:

for i in `</home/regionstextfile`
do 
  tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done

When you use a variable (e.g. assign value to it or export it, or do anything but with the variable itself) you write its name without $; when you use a value of a variable you write $.

EDIT:

When region names contains spaces but each region is in a separate line, you need while:

cat /home/regionstextfile | while read i
do 
  tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
1

The same thing without cat :

while read i
do
  tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done < /home/regionstextfile

Remark <file.txt could not work unless IFS=''

OLDIFS="$IFS"
IFS=''
for i in `</home/regionstextfile`
do
  tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
IFS="$OLDIFS"
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36