0

I am new to writing of bash scripts. I am making a pipeline for bioinformatic data-analysis. I am running several program fx Porechop, where I want to set a variable in the output name. So I want to be able to set a name of the sample, I am running and this name should then appear in the output files from every program.

So fare I have this script, but instead of outputting the name I gave, it tries to output the save path folder:

NAME=${1?Error: manlger directory til Nanopore fil(er)}
NAME2=${1?Error: ingen output fil angivet}
Now="$(date)"

#Porechop
$'/home/user/miniconda3/envs/pomoxis/bin/porechop' -i $NAME --threads 4 --check_reads 100 --discard_middle -o /media/user/new/porechop/trimmed_"$NAME2"_"$Now".fastq 

The error is:

enter FileNotFoundError: [Errno 2] No such file or directory: '/media/user/new/porechop/trimmed_echo /media/user/new/b.frag/_Tue Feb 18 11:36:17 CET 2020.fastq'

I hope someone can help me to find a script to make this variable

-Sabine

2
  • Please provide an example of the expected input/output & how the script is to be used.
    – user1139593
    Feb 18, 2020 at 13:33
  • It looks $NAME2 expands to echo /media/user/new/b.frag/. It comes from $1. How do you call the script? Feb 19, 2020 at 7:02

1 Answer 1

1

Unsure what is required at this stage, but try:

printf '%s\t%s\n' 'Input is:' "${1:?Please specify an input}" >&2
if [ -e "$1" ]; then
    case "$1" in
        */*) input=$1 ;;
        *) input=./$1 ;;
    esac
else
    echo "Specified input doesn't exist, exiting" >&2
    exit 1
fi
output="${input%/*}/porechop/trimmed_${input##*/}_$(date '+%F_%H-%M-%S-%Z').fastq"
printf '%s\t%s\n' 'Output will be:' "$output" >&2

#mkdir "${output%/*}"
#/home/user/miniconda3/envs/pomoxis/bin/porechop -i "$input" --threads 4 --check_reads 100 --discard_middle -o "$output"
  • Example usage:
./script /media/user/new/b.frag

which should print the following:

Input is:       /media/user/new/b.frag
Output will be: /media/user/new/porechop/trimmed_b.frag_2020-02-18_11-36-17-CET.fastq

If the above is correct for your use, uncomment the last two lines (remove the #).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .