I'm working on the following pipeline (codeshare.io/243VJE):
#!/bin/bash
#SBATCH --nodes=1 --ntasks=1 --cpus-per-task=10
#SBATCH --time=2-00:00:00
#SBATCH --mem=40gb
#
#SBATCH --job-name=pan_pca
#SBATCH --output=pan_pca.out
#SBATCH --array=[1-46]%46
#
#SBATCH --partition=DSS,NBFC
NAMES=$1
d=$(sed -n "$SLURM_ARRAY_TASK_ID"p $NAMES)
ID="$(echo ${d}/*_hap[0-1]_hprc_r2.fa.gz | sed 's#/path/to/temp_pca/[A-Z,0-9,a-z]\+_[0-9,a-z]\+/##' | sed 's#_hap[0-9]_hprc_r2.fa.gz##')"
HAP=( "hap0" "hap1" "hap2")
SEX="$(echo ${d} | sed 's#/path/to/temp_pca/[A-Z,0-9,a-z]\+_##')"
CHR_13=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9"
"chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17"
"chr18" "chr19" "chr20" "chr21" "chr22" "chrX" "chrY" "chrM" )
CHR_38=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9"
"chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17"
"chr18" "chr19" "chr20" "chr21" "chr22" "chrX" "chrY" "chrUn"
"chrM" "chrEBV" )
CHR_P=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9"
"chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17"
"chr18" "chr19" "chr20" "chr21" "chr22" "chrY" "chrUn" )
CHR_M=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9"
"chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17"
"chr18" "chr19" "chr20" "chr21" "chr22" "chrX" "chrUn" "chrM" )
SEQKIT="./tools/seqkit"
BGZIP="./tools/bgzip"
cd ~
#PREPARES THE INPUT
if [ -e $d/select.done ]
then
echo "regions selecion done!"
else
for h in "${HAP[@]}"; do
if [ "$h" == "hap0" ]
then
if [ "$SEX" == "ref" ]
then
for c in "${CHR_38[@]}"; do
###generate chromosome FASTA
${SEQKIT} grep -f $d/${ID}_${c}_${h}_contigs_one.list $d/${ID}_${h}_hprc_r2.fa.gz -j 10 |
${BGZIP} -@10 > $d/${ID}_${c}.fna.gz
done
elif [ "$SEX" == "t2t" ]; then
for c in "${CHR_13[@]}"; do
###generate chromosome FASTA
${SEQKIT} grep -f $d/${ID}_${c}_${h}_contigs_one.list $d/${ID}_${h}_hprc_r2.fa.gz -j 10 |
${BGZIP} -@10 > $d/${ID}_${c}.fna.gz
done
elif [ "$SEX" == "m" ] || [ "$SEX" == "f" ]; then
echo "nothing to be done, running in diploid mode"
fi
fi
else
if [ "$SEX" == "m" ]
then
if [ "$h" == "hap1" ]
then
for c in "${CHR_P[@]}"; do
###generate chromosome FASTA
${SEQKIT} grep -f $d/${ID}_${c}_${h}_contigs_one.list $d/${ID}_${h}_hprc_r2.fa.gz -j 10 |
${BGZIP} -@10 > $d/${ID}_${c}_${h}.fna.gz
done
else
for c in "${CHR_M[@]}"; do
###generate chromosome FASTA
${SEQKIT} grep -f $d/${ID}_${c}_${h}_contigs_one.list $d/${ID}_${h}_hprc_r2.fa.gz -j 10 |
${BGZIP} -@10 > $d/${ID}_${c}_${h}.fna.gz
done
fi
elif [ "$SEX" == "f" ]; then
for c in "${CHR_M[@]}"; do
###generate chromosome FASTA
${SEQKIT} grep -f $d/${ID}_${c}_${h}_contigs_one.list $d/${ID}_${h}_hprc_r2.fa.gz -j 10 |
${BGZIP} -@10 > $d/${ID}_${c}_${h}.fna.gz
done
elif [ "$SEX" == "ref" ] || [ "$SEX" == "t2t" ]; then
echo "nothing to be done, running in haploid mode"
fi
done
touch $d/select.done
fi
and wish to automate all steps; however, for some reason it's throwing this error at an else...
syntax error near unexpected token 'else'
Even pasting it in shellcheck.net doesn't seem to help, or at least I cannot figure out what to do. I'm a bit at a loss, let me know whether there is something I'm missing, thanks!
P. S. removing the first if conditional where I check for "$h" == "hap0" seems to solve the issue, but at that point for two samples I have to run things interactively...
then, and you have a control flow syntax problem, which probably means you have lead yourself astray with whichifs,fis andelses belong together. Throw a code indenter at your script. (or, alternatively, I'm not convinced a shell scripting language is what you'd want to use here: other programming languages have much more expressive ways)if foo; then lots of stuff here; else lots of other stuff; fi, the inner blocks should be functions.