Entering edit mode
2.2 years ago
Erika
•
0
Hi!
I have this bash script which is just for one file and I want to use for a multiple files in a folder. I have been trying with the for loop, but my script does not work. THanks in advance!
#!/bin/bash
# USAGE
# sh getSNPs_and_clean.sh vcf output_path
## Note this only works when we use chromosomes with sites to be exchanged
## Note this only works on one chromosome VCF
FILE=$1; # A VCF file multisample or mono sample
OUTPUT_PATH=$2;
file_name=${FILE%.vcf*};
file_name=${file_name##*/};
# SNPs
bcftools view --threads 40 -m2 -M2 -v snps -Oz -o ${OUTPUT_PATH}/${file_name}.snps.vcf.gz ${FILE}
bcftools index --threads 40 ${OUTPUT_PATH}/${file_name}.snps.vcf.gz
bcftools view --threads 40 -e 'POS=80294998' -Oz -o ${OUTPUT_PATH}/${file_name}.snpsTMP.vcf.gz ${OUTPUT_PATH}/${file_name}.snps.vcf.gz # without duplicates
mv -f ${OUTPUT_PATH}/${file_name}.snpsTMP.vcf.gz ${OUTPUT_PATH}/${file_name}.snps.vcf.gz
bcftools index --threads 40 ${OUTPUT_PATH}/${file_name}.snps.vcf.gz
echo "${FILE} completed!"
what is the aim of that script ? finding the di allelic snps NOT at POS=80294998 ?
Its is just a correction
I want to put a for loop inside this script
what does that mean ?
as far as I can understand you don't need such complicated script, you don't need an index, you don't need two steps....
what I am trying to do is something like this (for multiple files):
I'm not really sure what you're trying to do either, but in terms of simply running a loop, the example above has only one element for looping (FILE has only a single value), and you never use "i" in the rest of the code (so the loop appears to have no point). Don't you want something like:
Create the simplest toy example and echo your file names to work out your loop, before inserting the complex command stuff.
information is missing. What "does not work" ? how can we know ?
after
#!/bin/bash
addto see what's happening and stop at errors.
you can also prefix your
bcftools
commands withecho
to see what's happening.