I am trying to automate running a python command with arguments using multiple files (one at a time) and writing the output in output directories with the same name of the input file but without the extension.
The files are fasta files containing the proteins from bacterial genomes. The python routine is designed to extract those proteins with certain properties and printing various outputs in the directory /myruns/test
. If I run it with one genome, the name of test
would be replaced.
Example:
fast file XYZ.faa
will be taken as input and the output files will be placed in /myruns/XYZ
.
Manually it works very well, but I want to use it in batch with multiple *.faa
files and create directories with their corresponding names, otherwise the last file processed will erase the content of the previous one.
So far I have built made the following script:
#!/bin/sh for filename in *.faa ; do python predict_genome.py \ --fasta_path /Users/mvalvano/DeepSecE/myruns/${filename} \ --model_location /Users/mvalvano/DeepSecE/model/checkpoint.pt \ --data_dir data \ --out_dir myruns/test --save_attn --no_cuda done exit 0
This script works, and the output files are saved in a test directory that is specified in the --out_dir
argument. My question is how can I replace test
in the --out_dir
argument with a function that would name the directory with the same name as the input file. I have tried a few options but they do not seem to work.
Thanks Mike
/bin/sh
while the question is taggedbash
. Do you need a script strictly compatible with /bin/sh?myruns/test
withmyruns/$(basename -s .faa filename)
do what you need? Are whitespace or special characters possible in the file names? As others have said, without knowing exactly what you want & tried and an example of the input and desired output, we're guessing here./myruns/test
would be an absolute directory, but in your script you wrotemyruns/test
which is relative to the current working directory which is not necessarily the same as the location of your script and not necessarily/Users/mvalvano/DeepSecE/myruns
. I suggest to add an example that makes your directory structure and location of all files and scripts clear.