This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Running hmmsearch against all fasta files in a directory

I'm trying to run hmmsearch against a set of fasta files stored in a directory and save the results individually. I came up with the following python script:

# extract fasta file names for input/output files
Filename = []
for item in os.listdir("mnt/c/Users/username/Desktop/FASTA"):
  if ".fasta" in item:
     Filename.append(item)

__INPUT = Filename
__OUTPUT = mnt/c/Users/username/Desktop/hmmsearch/Filename.hmm

hmmsearch -o $__OUTPUT -T 50 hmmfile.hmm $__INPUT

However I can't even seem to get the Filename parameter out because I'm getting the no such file or directory error. I did manage to run hmmsearch for individual fasta file using the line below though , so I know that the file path does exist.

hmmsearch -o /mnt/c/Users/username/Desktop/hmmsearch/hmmoutput.txt -T 50 hmmfile.hmm /mnt/c/Users/username/Desktop/FASTA/file1.fasta

How can I get around this problem?

hmmsearch

Are you running this from the root (/) directory, which is where I would expect /mnt/.... to be present. Otherwise you appear to be missing a leading / before mnt/c/Users/username/Desktop/hmmsearch/Filename.hmm and in mnt/c/Users/username/Desktop/FASTA .

No I'm not in the root directory, I just added the missing / in the os.listdir command ("/mnt/c/Users/username/Desktop/FASTA") and that solved the issue with Filename not getting extracted correctly! However when I tried adding / to the __OUTPUT file it gives a syntax error (invalid syntax), so I removed that again and left it as is. Now when I run the file, I get a syntax error with the hmmsearch line, saying that $__OUTPUT is an invalid syntax?

By using Filename everywhere you are simply using the entire list as input. You would want to use item to select those names that have .fa in the name? You will also need to do some additional work to remove .fa from name before using the basename.

Hmm, after reading your comment I tried using this for the __INPUT instead, and I'm getting a syntax error at *.fasta. I thought * was supposed to read any characters or numbers though?

__INPUT = mnt/c/Users/username/Desktop/FASTA/*.fasta

This is a horrible implementation but should give you an idea. I am simply reusing your code. You will need to adjust as necessary.

Filename = []
for item in os.listdir("/mnt/c/Users/username/Desktop/FASTA/"):
    if ".fasta" in item:
            Filename.append(item)
            __INPUT = item
            name=(__INPUT.split("."))
            __OUTPUT = str(name[0])+".hmm"
            print(f"hmmsearch -o {__OUTPUT} -T 50 hmmfile.hmm {__INPUT}")

0 answers

No answers yet.

Log in to answer this question.