This is a test version of Biostars. For the public version, visit https://www.biostars.org.
problem use htseq-count in bash script

Hi I write an bash script to automate my workflow. but the count section not work and throw this error. I can not figure it out why exact same command run from console is ok but has error in script

CMD="${PYTHON_EXE} -m HTSeq.scripts.count -i gene_name -r name ${1}_sort.sam ${ANNOT_PATH} >${COUNT_PATH}${1}.count"

echo Running $CMD

if  $CMD ; then
    echo "${GREEN}Counting done${NC}"
else
    echo "${RED}Counting failed; see htseq-count error message${NC}"
fi

it generate the command like:

/usr/bin/python3 -m HTSeq.scripts.count -i gene_name -r name /home/user/bin/SRR5122422_sort.sam /home/user/bin/GRCh37.87.gtf >/mnt/disk2/Count_Files/SRR5122422.count

and the error is:

file does not contain alignment data
  [Exception type: ValueError, raised in libcalignmentfile.pyx:947]

use "htseq-count" or "/usr/bin/python3 -m HTSeq.scripts.count" generate same error. the path for sam and gtf file is ok.

htseq-count script

I guess there is something with your SAM file, check if the format is correct

if I copy and past the generated command in console it run without any error. so I think file is ok

in your bash script, how the path for the SAM file is being generated? I see /home/user/bin/ but you are using just ${1} which I guess is just SRR5122422

I pass SRR5122422 as argument to script

./myscript.sh SRR5122422

1 answer

ok . it work after I edit like this

CMD="${PYTHON_EXE} -m HTSeq.scripts.count -i gene_name -r name ${1}_sort.sam ${ANNOT_PATH} "

echo Running $CMD

if  $CMD >${COUNT_PATH}${1}.count; then
    echo "${GREEN}Counting done${NC}"
else
    echo "${RED}Counting failed; see htseq-count error message${NC}"
fi

so, it was the path ;)

Log in to answer this question.