This is a test version of Biostars. For the public version, visit https://www.biostars.org.
[solved] BioPython: CodeML FileNotFoundError: [WinError 2]

I have been trying to run a basic codeML wraper, that I got from the Biopython cookbook, but it doesn't seem to be working. I have been getting the error FileNotFoundError: [WinError 2].

This is what the piece of code looks like:

def codeML(outfile):
    cml = codeml.Codeml()
    cml.alignment = "C:\\Users\\User\\Documents\\project\\codonal.fasta"
    cml.tree = "C:\\Users\\User\\Documents\\project\\newtree.nwk"
    cml.out_file = outfile
    cml.working_dir = "C:\\Users\\User\\Documents\\project"
    cml.set_options(seqtype=1,
            verbose=0,
            noisy=0,
            RateAncestor=0,
            model=0,
            NSsites=[0, 1, 2],
            CodonFreq=2,
            cleandata=1,
            fix_alpha=1,
            kappa=4.54006)
    results = cml.run()
    ns_sites = results.get("NSsites")
    m0 = ns_sites.get(0)
    m0_params = m0.get("parameters")
    print(m0_params.get("omega"))

And this is what the error looks like:

Traceback (most recent call last):
  File "C:\Python34\elgrando.py", line 155, in <module>
    codeML("rezultati.out")
  File "C:\Python34\elgrando.py", line 143, in codeML
    results = cml.run()
  File "C:\Python34\lib\site-packages\Bio\Phylo\PAML\codeml.py", line 186, in run
    Paml.run(self, ctl_file, verbose, command)
  File "C:\Python34\lib\site-packages\Bio\Phylo\PAML\_paml.py", line 143, in run
    stdout=subprocess.PIPE)
  File "C:\Python34\lib\subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Python34\lib\subprocess.py", line 858, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2]

Python usually gives this error when there is a problem with pathing, but I have checked it twice now and it works if I independently run CodeML. Could it be that python doesn't recognise Paml on my computer or it doesn't have access to it?

python winerror codeml biopython paml

May be its not in the path i.e not added to Environmental variables?

Can you check the input files and ensure they have no access/security problems? Files downloaded from the internet may need to be "unblocked".

It could be the Environmental variables, but it would be strange since other biopython tools work.

I have been using these files with other Biopython tools, they are probably not the cause of the problem.

I have been able to reduce the errors to only one:

File "C:/Python34/standalone.py", line 2, in codeML
    cml = codeml.Codeml()
NameError: name 'codeml' is not defined

Still don't know what the problem is.

What does your import statement for codeML look like?

from Bio.Phylo.PAML import codeml

Well all the old errors are back, it had a random flash previously

Try reinstalling the CodeML package.

It has been deleted...

1 answer

I think I have found the problem...

This is the control file that CodeML produces:

seqfile = kodonskaporavnava.fasta
outfile = results.out
treefile = novodrevo1.nwk
kappa = 4.54006
cleandata = 1
RateAncestor = 0
seqtype = 1
model = 0
noisy = 0
verbose = 0
fix_alpha = 1
NSsites = 0 1 2
CodonFreq = 2

There are not paths, only file names. If I look up the same file when produced by stand-alone CodeML it has full paths. CodeML apparently works, but it does not recognise the file paths... I have no idea why, because if I copy/paste them to a different biopython module, they work as intended.

*Sorry for the different file names, they are just in a different language.

Were you able to sort this out after finding out the issue? I have similar issue with the control file producing just the file names without adding the paths.

Log in to answer this question.