Reputation: 142
So I realize others have asked similar questions in the past, but when I tried their solutions (using dos2unix, and checking vim for extraneous symbols), they didn't work at all.
#!/bin/bash
#-----------------------------------------------------------------------------
mainDir=/mnt/data1/sam
#-----------------------------------------------------------------------------
----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
cd $fastqDir
for i in `ls *R1_001.fastq.gz`
do
#----------------------------------
filename="${i%_R1_001.fastq.gz}"
#----------------------------------
#adapter-trim
#----------------------------------
echo "Alignment started for $filename" >> ${qcDir}/${filename}_report.txt
filename="${i%_R1_001.fastq.gz}"
echo $filename
echo "Alignment started for $filename" >> ${qcDir}/${filename}_report.txt
sed '/chrM/d;/chrY/d;/random/d;/chrUn/d' < Aligned.out.sam | samtools view -bS -F 4 -q 30 -u - | samtools sort - > ${bamDir}/${filename}.bam
rm Aligned.out.sam
mv Log.final.out ${qcDir}/${filename}_STARLogFinal.txt
echo "Picard started for $filename" >> ${qcDir}/${filename}_report.txt
mv ${bamDir}/${filename}_dedup.bam ${bamDir}/${filename}.bam
samtools index ${bamDir}/${filename}.bam
echo "Picard insert size histogram for $filename" >> ${qcDir}/${filename}_report.txt
INSERT_TXT_FILE="${qcDir}/${filename}.insertSizes.txt"
INSERT_HISTO_FILE="${qcDir}/${filename}.insertSizes.pdf"
echo "Making bigwig for $filename"
lines=$(samtools view -c ${bamDir}/${filename}.bam);\
bedtools genomecov -ibam ${bamDir}/${filename}.bam -bg -scale $(echo "1000000 / ${lines} " | bc -l) -g ${RefDir}/${genome}.chrom.sizes | \
wigToBigWig -clip stdin ${RefDir}/${genome}.chrom.sizes ${bwDir}/${filename}.bw 2> $tmpDir/${filename}_log
echo "macs2 for $filename"
done
I keep getting error
Syntax error: word unexpected (expecting "do")
Sorry if this question is kind of silly, I'm completely new to shell scripting.
Upvotes: 0
Views: 965
Reputation: 142
It turned out to be extraneous characters after all. I ran the following command and the script started working afterwards. Sorry for the confusion, and thanks for the help everyone!
tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file
Upvotes: 1