0

I want to give a numerical value as input argument for a bash script which is as below

#!/bin/bash

while getopts ":hl:q:s:e:k:g:v" opt; do
  case $opt in
    l)
      lincRNAfasta=$OPTARG
    ;;
    q)
      query_species=$OPTARG
      ;;
    s)
      subject_species=$OPTARG
      ;;
    e)
      subject_gff=$OPTARG
      ;;
    g)
      subject_genome=$OPTARG
      ;;
    k)
      known_lincRNAs=$OPTARG
      ;;
    v)
      evalue=$OPTARG
      ;;  
    h)
    usage  
     exit 1
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done

echo "Starting on $subject_species"

# Formatting the genome
makeblastdb -logfile stderr.out -in $subject_genome -dbtype nucl -out BLAST_DB/$subject_genome.blast.out

# Blasting the lincRNA transcripts against the genome to find out the location on the genome And identify if there are any paralogs in the query genome.
blastn -logfile stderr.out -query $lincRNAfasta -db BLAST_DB/$subject_genome.blast.out -num_threads 4 -penalty -2 -reward 1 -gapopen 5 -gapextend 2 -dust no -word_size 8 -evalue $evalue -outfmt "6 qseqid sseqid pident length qlen qstart qend sstart send evalue bitscore" -out Homology_Search/$subject_species.out

When i run the above script like this:

sh test.sh -l sample.data/Hsap_lincRNAs.fasta -q Hsap -s Hsap -e sample.data/Hsap_genes.gff -g sample.data/Hsap_genome.fasta -k sample.data/Hsap_lincRNAs -v 1e-20

I get this following error.

Error: Cannot convert string '=' to double (m_Pos = 0)
Error: Argument "evalue". Argument cannot be converted:  `='
Error:  (CArgException::eConvert) Argument "evalue". Argument cannot be converted:  `='

I have never run a numeric value as argument with the getopts module in bash and so i am not sure what am i doing wrong here. Any help is much appreciated.

Thanks Upendra

upendra
  • 2,141
  • 9
  • 39
  • 64
  • 2
    I don't think this is a shell error -- I tried it, and I don't see any "=" being passed to either `makeblastdb` or `blastn`. You can verify this by adding `et -x` between the `echo` and `makeblastdb`. Might there be something wrong with a data file? BTW, you shouldn't run bash scripts with `sh` -- that might be `bash`, or might be some other shell. The best way is to make the scriot executable (`chmod +x test.sh`), then run it with `./test.sh ...`. – Gordon Davisson Jul 27 '16 at 23:49
  • Thanks for the `et -x` tip, it helped me a lot. I figured out what the error is. I forgot the colon after v in here `while getopts ":hl:q:s:e:k:g:v" opt; do`. It shoudl be `while getopts ":hl:q:s:e:k:g:v:" opt; do` Stupid of me. Wasted 2 hours on this – upendra Jul 28 '16 at 00:06

0 Answers0