Hang Lin
Hang Lin

Reputation: 51

Running clustalw on google platform with error in generating .aln file in ubuntu

I was trying to run clustalw from Biopython library of python3 on Google Cloud Platform, then generate a phylogenetic tree from the .dnd file using the Phylo library.

The code was running perfectly with no error on my local system. However, when it runs on the Google Cloud platform it has the following error:

python3 clustal.py
Traceback (most recent call last):
  File "clustal.py", line 9, in <module>
    align = AlignIO.read("opuntia.aln", "clustal")
  File "/home/lhcy3w/.local/lib/python3.5/site-packages/Bio/AlignIO/__init__.py", line 435, in read
    first = next(iterator)
  File "/home/lhcy3w/.local/lib/python3.5/site-packages/Bio/AlignIO/__init__.py", line 357, in parse
    with as_handle(handle, 'rU') as fp:
  File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/home/lhcy3w/.local/lib/python3.5/site-packages/Bio/File.py", line 113, in as_handle
    with open(handleish, mode, **kwargs) as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'opuntia.aln'

If I run sudo python3 clustal.py, the error would be

  File "clustal.py", line 1, in <module>
    from Bio import AlignIO
ImportError: No module named 'Bio'

If I run it as in the interactive form of python, the following happened

Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from Bio.Align.Applications import ClustalwCommandline
>>> in_file = "opuntia.fasta"
>>> clustalw_cline = ClustalwCommandline("/usr/bin/clustalw", infile=in_file)
>>> clustalw_cline()
('\n\n\n CLUSTAL 2.1 Multiple Sequence Alignments\n\n\nSequence format is Pearson\nSequence 1: gi|6273291|gb|AF191665.1|AF191665   902 bp\nSequence 2: gi|6273290|gb
|AF191664.1|AF191664   899 bp\nSequence 3: gi|6273289|gb|AF191663.1|AF191663   899 bp\nSequence 4: gi|6273287|gb|AF191661.1|AF191661   895 bp\nSequence 5: gi|627328
6|gb|AF191660.1|AF191660   893 bp\nSequence 6: gi|6273285|gb|AF191659.1|AF191659   894 bp\nSequence 7: gi|6273284|gb|AF191658.1|AF191658   896 bp\n\n', '\n\nERROR: 
Cannot open output file [opuntia.aln]\n\n\n')

Here is my clustal.py file:

from Bio import AlignIO
from Bio import Phylo
import matplotlib

from Bio.Align.Applications import ClustalwCommandline
in_file = "opuntia.fasta"
clustalw_cline = ClustalwCommandline("/usr/bin/clustalw", infile=in_file)
clustalw_cline()
tree = Phylo.read("opuntia.dnd", "newick")
tree = tree.as_phyloxml()
Phylo.draw(tree)

I just want to know how to create an .aln and a .dnd file on the Google Cloud platform as I can get on my local environment. I guess it is probably because I don't have the permission to create a new file on the server with python. I have tried f = open('test.txt', 'w') on Google Cloud but it couldn't work until I add sudo before the terminal command like sudo python3 text.py. However, as you can see, for clustalw, adding sudo only makes the whole biopython library missing.

Upvotes: 1

Views: 183

Answers (0)

Related Questions