Question: basename: missing operand
0
gravatar for evelyn
12 months ago by
evelyn100
evelyn100 wrote:

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 • 2.3k views
ADD COMMENTlink written 12 months ago by evelyn100
2

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 REPLYlink modified 12 months ago • written 12 months ago by Carambakaracho2.2k

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

ADD REPLYlink written 12 months ago by evelyn100
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 REPLYlink written 12 months ago by Carambakaracho2.2k
1

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

ADD REPLYlink written 12 months ago by Joe17k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1320 users visited in the last hour