Read file from user input with a list of prefixes, then call file with prefixes in while loops
1
vote
1
answer
419
views
I am trying to direct user input file into while loop, but kept on failing when ran the script.
The user input file
genelist
contained a list of numbers where I have been using as prefixes of my other files. Eg. 012.laln, 012.model.
genelist:
012
013
025
039
109
.
.
.
This is the script I have been testing on.
#!/usr/bin/env bash
read -pr "genefile: " genelist
read -pr "treefile: " trees
read -pr "workers: " workers
while read -r i; do
while read -r j; do
raxml-ng --sitelh --msa "$i".laln --model "$j".model --tree "${trees}" --workers "${workers}" --prefix "$i"-rT;
done < "$genelist".model;
done < "$genelist"
In order to execute raxml-ng tool, I need to input files for --msa, --model, --tree, --workers and --prefix for output file name. I need to repeat the process with multiple files, each 012.laln need to match with 012.model and generate output file named 012-rT. The input files for tree and workers are the same for all the files.
I kept on getting error:
line 2: read: `genefile: ': not a valid identifier
line 3: read: `treefile: ': not a valid identifier
line 4: read: `workers: ': not a valid identifier
Modifying the way I call the user input file "genelist" in a few ways but with no avail.
while read -r "${genelist}" ...
while read -r "${genelist{@}}" ...
while read -r "{genelist}" ...
Before this, I have been using for loops, i.e., the one-liner below. It worked well.
I would like to try on while loops if possible.
for i in $(cat genelist); do for j in $(cat $i.model); do raxml-ng --sitelh --msa $i.laln.trgc38_1l --model $j --tree trees --workers 4 --prefix $i-rT; done; done
Questions:
What is the correct and neat way to call the user input file genelist
into the while loops?
There are some example I found in here but those are using numbers/number sequences in the loops. The answers suggested using C in for/while loops to solve the issue. But that doesn't seemed to be relevant for my case.
Meanwhile, any better alternative for for/while loops in this case is also welcome!
Asked by web
(193 rep)
Nov 16, 2021, 03:33 PM
Last activity: Nov 17, 2021, 09:37 AM
Last activity: Nov 17, 2021, 09:37 AM