Bash troubleshooting: Not a valid identifier
Solution 1
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
Solution 2
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"
user964689
Updated on June 05, 2022Comments
-
user964689 almost 2 years
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 thevcf.bz
file, then with the output runvcftools
with the specified options, then put all the outputs into thegenomesregions.txt
file. -
jedwards almost 12 yearsAs long as the lines in the textfile doesn't contain whitespace, this should work.
-
user964689 almost 12 yearsThanks for the fast reply, testing it now