This is a test version of Biostars. For the public version, visit https://www.biostars.org.
problem in creating an object for a list of fasta files

Hello,

I am trying to make an object for a list of fasta files to use for downstream analysis:

INPUT_DIR=/path/input
INPUT_FILE=$(ls -1 input/*.fasta)
SAMPLE=$(basename "${INPUT_FILE}" .fasta)
in=${INPUT_DIR}/${SAMPLE}.fasta

However in shows only the first file in the list instead of all the fasta files. Thank you for the help!

basename

INPUT_FILE=$(ls -1 input/*.fasta)

When assigning multiple strings (files) separated with space in shell, only the first value is assigned.

You would use for or while loop , find --exec, parallel, or xargs to process every file separately.

If this is bash script, this is unnecessarily complex. Let us say you have all the fasta files in test directory, want to use ls for listing files and store the file information along with directory (test here). You can create an array and use the array elements as you like.

$ a=($(ls test/*.fasta))

$ echo ${a[@]}  

test/seq1_1.fasta test/seq1_2.fasta test/seq2_1.fasta test/seq2_2.fasta

$ printf "%s\n" ${a[@]}  

test/seq1_1.fasta
test/seq1_2.fasta
test/seq2_1.fasta
test/seq2_2.fasta

you can also loop through array:

$ for i in ${a[@]}; do echo $i ;done

test/seq1_1.fasta
test/seq1_2.fasta
test/seq2_1.fasta
test/seq2_2.fasta

All string manipulations work on arrays and list items. works with bash on ubuntu.

0 answers

No answers yet.

Log in to answer this question.