basename: missing operand
0
0
Entering edit mode
21 months ago
evelyn ▴ 140

I am trying to run samtools to create vcf files for a list of sorted bam files using:

INPUT_DIR=DIR_NAME
INPUT_FILE_ONE=$(ls -1 DIR_NAME/*.sorted.bam | sed -n ${RUN}p)
SAMPLE=$(basename ${INPUT_FILE_ONE} | sed 's/.sorted.bam//')

OUT_DIR=vcf

echo "bcftools mpileup -Ov -f $REF_DIR/ref.fa ${INPUT_DIR}/${SAMPLE}.sorted.bam | bcftools call -mv -o ${OUT_DIR}/${SAMPLE}.vcf"

But I am getting error: basename: missing operand

snp • 3.9k views
ADD COMMENT
2
Entering edit mode

Check echo ${INPUT_FILE_ONE}, if that's what you expected the pipe to sed is not needed and .sorted.bam can be second argument to basename

ADD REPLY
0
Entering edit mode

echo ${INPUT_FILE_ONE} gives what I need. Can you please provide the SAMPLE line then. I still got an error.

ADD REPLY
0
Entering edit mode
basename --help
SAMPLE=$(basename ${INPUT_FILE_ONE} .sorted.bam)

And you'll get some unsolicited advice on top: In case you'll be doing stuff like this more often and you're stuck with troubleshooting this line after the help you got, I strongly recommend you look into some introduction to bash. When asking and re-asking very basic things, you might get rather rude answers depending on the person and their mood (and I'm not excluding myself).

Please do not take offense in this - you'll save the time you invest very soon!

ADD REPLY
1
Entering edit mode

basename can take a second argument for an extension to strip so you can do away with your sed command altogether.

ADD REPLY

Login before adding your answer.

Traffic: 2426 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6