Entering edit mode
2.8 years ago
Kumar
▴
170
Hi,
I am trying to use the following command running in a for loop with multiple files. Could anyone help me to write a python or bash script to run the command with multiple files.
seqkit grep -n -f Id.txt S10_scaffolds.fasta -o fetch.fasta
I tried following script but not sure if it is correct.
for file in *.fasta
do
seqkit grep -n -f "$file" -o $(basename "$file" .fasta)
done
Thank you,
Try:
This will create output files with
name
appended with rest.Missed 'id.txt' after -f
I had copied the example OP had. Fixed now.
Sorry for the confusion but I am updating the command.
The .txt are also multiple files compatible to its scaffolds files. I have a set of different 70 .txt files and its .scaffolds file.
seqkit grep -n -f Salm_10_scaffolds_uniq_Id.txt S10_scaffolds.fasta -o fetch.fasta
how do you associate text file with fasta file? Your updated command is incorrect if it is updated and original is also incorrect as it didn't use id.txt in the loop.
The single line command (seqkit grep -n -f Salm_10_scaffolds_uniq_Id.txt S10_scaffolds.fasta -o fetch.fasta) works perfect. I have text file and its associated fasta files as follows:
Each text file contains header lines that are present in fasta files, if I run the seqkit command it greps the sequences from the fasta files. However, I am looking to see if it can be done by a script since I have several text files and its associated fasta files.
I hope I explained my query correctly.
Following should work based on what you described above. I am prepending
${name}
to_fetch.fasta
so you get. unique file for each nameRemove the word
echo
when commands look correct and you want to execute them.having same file extension for input and output in a loop could be problematic.
I changed the loop to use the
.txt
files to address this. Hopefully only.txt
files in directory are the ones corresponding to fasta.After checking the output from dry-run, remove
echo
Using parallel:
Remove --dry-run after checking the output from dry-run
Thank you so much for all the suggestions. These are very helpful.