problem in creating an object for a list of fasta files
0
0
Entering edit mode
3.6 years ago
evafinegan • 0

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 • 887 views
ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

It worked. thank you!

ADD REPLY
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1563 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6