1

I'm a beginner in bash scripting, can someone please help me here?

  • In a directory (pamlfiles/), I had list of files (*.fa)
    OG0018053.fa
    OG0018054.fa
    OG0018055.fa
    
  • The files look like this:
    head -n 2 ../pamlfiles/*
    ==> ../pamlfiles/OG0018053.fa <==
    >C.rhe
    ATGAGG------------GTCCTCCTGCTTCTCGGATTGGTGGCTTTTGGCCTGGCTGAC
    
    ==> ../pamlfiles/OG0018054.fa <==
    >L.fab
    atg---------------------acggacgagatatctctggcgtgtggcatgtcagga
    
    ==> ../pamlfiles/OG0018055.fa <==
    >A.ven
    ATGAACACTGCCACTCCCACCGAGTTTGACTTCTCTTTCTTGGAAGAGGGCTTCTCCGCC
    
  • I process them with the following script (forloop.sh):
    #!/bin/bash
    for file in ../pamlfiles/*.fa
    do
        filename=$(basename -- "$file")
        gene_name="${filename%%.*}"
        cp codeml_0_opt1_templ.ctl codeml_0.ctl
        sed -i -e "s/GENE/$gene_name/g" codeml_0.ctl
        codeml codeml_0.ctl
    done
    

However, when I execute the forloop.sh, I get the error

Sequence file ../pamlfiles/OG0018055 not found!

The codem1_0_opt1_templ.ctl looks like this:

head codeml_0_opt1_templ.ctl 
seqfile = ../pamlfiles/GENE
outfile = results/GENE_M0.txt
treefile = OG0018055.fa.m.fa.mt.py.nex.treefile
 
noisy = 9
verbose = 0 

runmode = 0
seqtype = 1  
CodonFreq = 2

Where am I going wrong?

0

1 Answer 1

2

If you look at the output of your codem1 process (whatever that may be), it states that it doesn't find the file OG0018055 - and this is only logical because the file is actually called OG0018055.fa.

In your script, you remove the .fa extension from your filename in the line

gene_name="${filename%%.*}"

to get the gene name. Then, you use sed to replace all occurences of the pattern GENE with that gene name in the file template. However, that means in your updated codeml_0.ctl file, the seqfile line looks as follows:

seqfile = ../pamlfiles/OG0018055

so the .fa extension is missing here.

So, just modify your template file to read

seqfile = ../pamlfiles/GENE.fa

so that the .fa filename extension doesn't get lost.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .