Exemplo n.º 1
0
    def __init__(self):
        # Try to avoid problems when the OS is in another language
        os.environ['LANG'] = 'C'

        phyml_exe = None
        exename = "PhyML-3.1_win32.exe" if sys.platform == "win32" else "phyml"
        from Bio._py3k import getoutput
        try:
            output = getoutput(exename + " --version")
            if "not found" not in output and "20" in output:
                phyml_exe = exename
        except OSError:
            # Python 2.6 or 2.7 on Windows XP:
            # WindowsError: [Error 2] The system cannot find the file specified
            # Python 3.3 or 3.4 on Windows XP:
            # FileNotFoundError: [WinError 2] The system cannot find the file
            # specified
            pass

        if not phyml_exe:
            raise MissingExternalDependencyError(
                "Install PhyML 3.0 if you want to use the \
                Bio.Phylo.Applications wrapper.")

        # Example Phylip file with 13 aligned protein sequences
        EX_PHYLIP = 'HTR1E_aligned.phy'
        self.EX_PHYLIP = EX_PHYLIP
Exemplo n.º 2
0
def raxml(sequences,
          starting_tree="pars",
          model="JC",
          bootstrap=False,
          fixed_tree=False,
          bstrees=100,
          log=True):
    raxml_exe = None
    try:
        from Bio._py3k import getoutput
        output = getoutput("raxml-ng -v")
        if "not found" not in output and "RAxML-NG" in output:
            raxml_exe = "raxml-ng"
    except OSError:
        pass

    if not raxml_exe:
        raise MissingExternalDependencyError(
            "Install RAxML (binary raxml-ng) if you want to test the Bio.Phylo.Applications wrapper."
        )

    if not fixed_tree:
        if bootstrap:
            cmd = RaxmlCommandline(raxml_exe,
                                   bootstrap=None,
                                   sequences=sequences,
                                   model=model,
                                   starting_tree=starting_tree,
                                   bstrees=bstrees)
        else:
            cmd = RaxmlCommandline(raxml_exe,
                                   sequences=sequences,
                                   model=model,
                                   starting_tree=starting_tree)
    else:
        cmd = RaxmlCommandline(raxml_exe,
                               fixtree=None,
                               sequences=sequences,
                               model=model,
                               starting_tree=starting_tree)

    out, err = cmd()
    if log:
        print out
Exemplo n.º 3
0
# license. Please see the LICENSE file that should have been included
# as part of this package.

"""Unit tests for Bio.Phylo.Applications wrappers."""

import os
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import RaxmlCommandline
from Bio import MissingExternalDependencyError

raxml_exe = None
try:
    from Bio._py3k import getoutput
    output = getoutput("raxmlHPC -v")
    if "not found" not in output and "This is RAxML" in output:
        raxml_exe = "raxmlHPC"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not raxml_exe:
    raise MissingExternalDependencyError(
        "Install RAxML (binary raxmlHPC) if you want to test the Bio.Phylo.Applications wrapper.")

# Example Phylip file with 4 aligned protein sequences
EX_PHYLIP = "Phylip/interlaced2.phy"


class AppTests(unittest.TestCase):
Exemplo n.º 4
0
import os
import unittest
from Bio import SeqIO
from Bio import AlignIO
from Bio.Align.Applications import ClustalOmegaCommandline
from Bio.Application import ApplicationError

#################################################################

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

clustalo_exe = None
from Bio._py3k import getoutput
try:
    output = getoutput("clustalo --help")
    if output.startswith("Clustal Omega"):
        clustalo_exe = "clustalo"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not clustalo_exe:
    raise MissingExternalDependencyError(
        "Install clustalo if you want to use Clustal Omega from Biopython.")


class ClustalOmegaTestCase(unittest.TestCase):

    def setUp(self):
        self.files_to_clean = set()
Exemplo n.º 5
0
import sys
import os
import unittest
from Bio import MissingExternalDependencyError
from Bio.Align.Applications import DialignCommandline

# Try to avoid problems when the OS is in another language
os.environ["LANG"] = "C"

dialign_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError("DIALIGN2-2 not available on Windows")
else:
    from Bio._py3k import getoutput
    output = getoutput("dialign2-2")
    if "not found" not in output and "dialign2-2" in output.lower():
        dialign_exe = "dialign2-2"
        if "DIALIGN2_DIR" not in os.environ:
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR for DIALIGN2-2 missing.")
        if not os.path.isdir(os.environ["DIALIGN2_DIR"]):
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR for DIALIGN2-2 is not a valid directory.")
        if not os.path.isfile(os.path.join(os.environ["DIALIGN2_DIR"], "BLOSUM")):
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR directory missing BLOSUM file.")
        # TODO - check for tp400_dna, tp400_prot and tp400_trans too?

if not dialign_exe:
    raise MissingExternalDependencyError(
Exemplo n.º 6
0
                   prog_files,
                   os.path.join(prog_files,"Muscle3.6"),
                   os.path.join(prog_files,"Muscle3.7"),
                   os.path.join(prog_files,"Muscle3.8"),
                   os.path.join(prog_files,"Muscle3.9"),
                   os.path.join(prog_files,"Muscle")] + sys.path
    for folder in likely_dirs:
        if os.path.isdir(folder):
            if os.path.isfile(os.path.join(folder, "muscle.exe")):
                muscle_exe = os.path.join(folder, "muscle.exe")
                break
        if muscle_exe:
            break
else:
    from Bio._py3k import getoutput
    output = getoutput("muscle -version")
    #Since "not found" may be in another language, try and be sure this is
    #really the MUSCLE tool's output
    if "not found" not in output and "MUSCLE" in output \
    and "Edgar" in output:
        muscle_exe = "muscle"

if not muscle_exe:
    raise MissingExternalDependencyError(
        "Install MUSCLE if you want to use the Bio.Align.Applications wrapper.")

#################################################################


class MuscleApplication(unittest.TestCase):
Exemplo n.º 7
0
        prog_files = os.environ["PROGRAMFILES"]
    except KeyError:
        prog_files = r"C:\Program Files"
    likely_dirs = ["bwa", "bwa-0.6.2", ""]
    likely_exes = ["bwa"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    bwa_exe = os.path.join(prog_files, folder, filename)
                    break
            if bwa_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("bwa")

    # Since "not found" may be in another language, try and be sure this is
    # really the bwa tool's output
    bwa_found = False
    if "not found" not in output and "bwa" in output \
            and "alignment via Burrows-Wheeler transformation" in output:
        bwa_exe = "bwa"
    skip_aln_tests = False
    aln_output = getoutput("bwa aln")
    if "unrecognized" in aln_output:
        skip_aln_tests = True
        print("'bwa aln' is unrecognized, skipping aln/samse/sampe tests")

if not bwa_exe:
    raise MissingExternalDependencyError("Install bwa and correctly set"
Exemplo n.º 8
0
import sys
import os
import unittest
from Bio import AlignIO, SeqIO, MissingExternalDependencyError
from Bio.Align.Applications import TCoffeeCommandline

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

t_coffee_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError(
        "Testing TCOFFEE on Windows not supported yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("t_coffee -version")
    if "not found" not in output \
    and ("t_coffee" in output.lower() or "t-coffee" in output.lower()):
        t_coffee_exe = "t_coffee"

if not t_coffee_exe:
    raise MissingExternalDependencyError(
        "Install TCOFFEE if you want to use the Bio.Align.Applications wrapper.")


class TCoffeeApplication(unittest.TestCase):

    def setUp(self):
        self.infile1 = "Fasta/fa01"
        self.outfile1 = "fa01.aln"
        self.outfile2 = "fa01.html"  # Written by default when no output set
    # fasttree is located on their systems

    likely_dirs = ["Fasttree", "fasttree", "FastTree"]
    likely_exes = ["Fasttree.exe", "fasttree.exe", "FastTree.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    fasttree_exe = os.path.join(prog_files, folder, filename)
                    break
            if fasttree_exe:
                break
else:
    from Bio._py3k import getoutput
    # Checking the -help argument
    output = getoutput("fasttree -help")
    # Since "is not recognized" may be in another language, try and be sure this
    # is really the fasttree tool's output
    fasttree_found = False
    if "is not recognized" not in output and "protein_alignment" in output \
    and "nucleotide_alignment" in output:
        fasttree_exe = "fasttree"

if not fasttree_exe:
    raise MissingExternalDependencyError(
        "Install fasttree and correctly set the file path to the program "
        "if you want to use it from Biopython.")

#################################################################

print("Checking error conditions")
Exemplo n.º 10
0
#!/usr/bin/env python

# Copyright 2004 by Michael Hoffman.  All rights reserved.  This code is
# part of the Biopython distribution and governed by its license.
# Please see the LICENSE file that should have been included as part
# of this package.

from Bio import MissingExternalDependencyError
import sys
if sys.platform=="win32":
    # Someone needs to find out if dnal works nicely on windows,
    # and if so where it is typically installed.
    raise MissingExternalDependencyError(
        "Don't know how to find the Wise2 tool dnal on Windows.")

from Bio._py3k import getoutput
not_found_types = ["command not found", "dnal: not found", "not recognized"]
dnal_output = getoutput("dnal")

for not_found in not_found_types:
    if not_found in dnal_output:
        #raise MissingExternalDependencyError(dnal_output)
        raise MissingExternalDependencyError(
            "Install Wise2 (dnal) if you want to use Bio.Wise.")
Exemplo n.º 11
0
# This file is part of the Biopython distribution and governed by your
# choice of the "Biopython License Agreement" or the "BSD 3-Clause License".
# Please see the LICENSE file that should have been included as part of this
# package.
"""Unit tests for the Bio.PDB.ResidueDepth module."""

import unittest
import warnings
from Bio.PDB import PDBParser, ResidueDepth
from Bio import MissingExternalDependencyError
from Bio.PDB.PDBExceptions import PDBConstructionWarning

from Bio._py3k import getoutput
msms_exe = None
try:
    output = getoutput("msms -h")
    if output.startswith("Usage : msms parameters"):
        msms_exe = "msms"
except OSError:
    pass

if not msms_exe:
    raise MissingExternalDependencyError(
        "Install MSMS if you want to use it in Biopython.")


class ResidueDepthTests(unittest.TestCase):
    """Test ResidueDepth module."""

    def check_msms(self, prot_file, first_100_residues):
        p = PDBParser()
Exemplo n.º 12
0
#!/usr/bin/env python

# Copyright 2004 by Michael Hoffman.  All rights reserved.  This code is
# part of the Biopython distribution and governed by its license.
# Please see the LICENSE file that should have been included as part
# of this package.

from Bio import MissingExternalDependencyError
import sys
if sys.platform == "win32":
    # Someone needs to find out if dnal works nicely on windows,
    # and if so where it is typically installed.
    raise MissingExternalDependencyError(
        "Don't know how to find the Wise2 tool dnal on Windows.")

from Bio._py3k import getoutput
not_found_types = ["command not found", "dnal: not found", "not recognized"]
dnal_output = getoutput("dnal")

for not_found in not_found_types:
    if not_found in dnal_output:
        raise MissingExternalDependencyError(
            "Install Wise2 (dnal) if you want to use Bio.Wise.")
Exemplo n.º 13
0
import sys
import os
import unittest
from Bio._py3k import StringIO
from Bio import AlignIO, SeqIO, MissingExternalDependencyError
from Bio.Align.Applications import ProbconsCommandline

#Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

probcons_exe = None
if sys.platform=="win32":
    raise MissingExternalDependencyError("PROBCONS not available on Windows")
else:
    from Bio._py3k import getoutput
    output = getoutput("probcons")
    if "not found" not in output and "probcons" in output.lower():
        probcons_exe = "probcons"

if not probcons_exe:
    raise MissingExternalDependencyError(
        "Install PROBCONS if you want to use the Bio.Align.Applications wrapper.")


class ProbconsApplication(unittest.TestCase):

    def setUp(self):
        self.infile1 = "Fasta/fa01"
        self.annotation_outfile = "Fasta/probcons_annot.out"

    def tearDown(self):
Exemplo n.º 14
0
    # fasttree is located on their systems

    likely_dirs = ["Fasttree", "fasttree", "FastTree"]
    likely_exes = ["Fasttree.exe", "fasttree.exe", "FastTree.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    fasttree_exe = os.path.join(prog_files, folder, filename)
                    break
            if fasttree_exe:
                break
else:
    from Bio._py3k import getoutput
    # Checking the -help argument
    output = getoutput("fasttree -help")
    # Since "is not recognized" may be in another language, try and be sure this
    # is really the fasttree tool's output
    fasttree_found = False
    if "is not recognized" not in output and "protein_alignment" in output \
    and "nucleotide_alignment" in output:
        fasttree_exe = "fasttree"

if not fasttree_exe:
    raise MissingExternalDependencyError(
        "Install fasttree and correctly set the file path to the program "
        "if you want to use it from Biopython.")

#################################################################

print("Checking error conditions")
Exemplo n.º 15
0
        prog_files = r"C:\Program Files"
    # By default tries C:\Program Files\samtools\samtools.exe
    # or  C:\Program Files\samtools.exe was chosen
    likely_dirs = ["samtools", ""]
    likely_exes = ["samtools.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    samtools_exe = os.path.join(prog_files, folder, filename)
                    break
            if samtools_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("samtools")

    # Since "not found" may be in another language, try and be sure this is
    # really the samtools tool's output
    if ("not found" not in output
            and "samtools (Tools for alignments in the SAM format)" in output):
        samtools_exe = "samtools"

if not samtools_exe:
    raise MissingExternalDependencyError(
        """Install samtools and correctly set the file path to the program
        if you want to use it from Biopython""")


class SamtoolsTestCase(unittest.TestCase):
    """Class for implementing Samtools test cases."""
Exemplo n.º 16
0
import sys
import os
import unittest
from Bio import MissingExternalDependencyError
from Bio.Align.Applications import DialignCommandline

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

dialign_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError("DIALIGN2-2 not available on Windows")
else:
    from Bio._py3k import getoutput
    output = getoutput("dialign2-2")
    if "not found" not in output and "dialign2-2" in output.lower():
        dialign_exe = "dialign2-2"
        if "DIALIGN2_DIR" not in os.environ:
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR for DIALIGN2-2 missing.")
        if not os.path.isdir(os.environ["DIALIGN2_DIR"]):
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR for DIALIGN2-2 is not a valid directory.")
        if not os.path.isfile(os.path.join(os.environ["DIALIGN2_DIR"], "BLOSUM")):
            raise MissingExternalDependencyError(
                "Environment variable DIALIGN2_DIR directory missing BLOSUM file.")
        # TODO - check for tp400_dna, tp400_prot and tp400_trans too?

if not dialign_exe:
    raise MissingExternalDependencyError(
Exemplo n.º 17
0
    #A default path of C:\Program Files\bwa.exe was chosen
    #but this path can be edited depending on where bwa is located

    likely_dirs = ["bwa", "BWA", "Bwa", "bwa-0.6.2"]
    likely_exes = ["bwa.exe", "BWA.exe", "Bwa.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    bwa_exe = os.path.join(prog_files, folder, filename)
                    break
            if bwa_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("bwa")

    #Since "not found" may be in another language, try and be sure this is
    #really the bwa tool's output
    bwa_found = False
    if "not found" not in output and "bwa" in output \
    and "alignment via Burrows-Wheeler transformation" in output:
        bwa_exe = "bwa"

if not bwa_exe:
    raise MissingExternalDependencyError(\
        "Install bwa and correctly set the file path to the program if you want to use it from Biopython")


class BwaTestCase(unittest.TestCase):
    """Class for implementing BWA test cases"""
Exemplo n.º 18
0
    # EMBOSS also sets an environment variable which we will check for.
    path = os.environ["EMBOSS_ROOT"]
    if os.path.isdir(path):
        for name in exes_wanted:
            if os.path.isfile(os.path.join(path, name + ".exe")):
                exes[name] = os.path.join(path, name + ".exe")
        del name
    else:
        raise MissingExternalDependencyError(
                  "$EMBOSS_ROOT=%r which does not exist!" % path)
    del path
if sys.platform != "win32":
    from Bio._py3k import getoutput
    for name in exes_wanted:
        # This will "just work" if installed on the path as normal on Unix
        output = getoutput("%s -help" % name)
        if "not found" not in output and "not recognized" not in output:
            exes[name] = name
        del output
    del name

if len(exes) < len(exes_wanted):
    raise MissingExternalDependencyError(
        "Install EMBOSS if you want to use Bio.Emboss.")


def get_emboss_version():
    """Returns a tuple of three ints, e.g. (6,1,0)"""
    # Windows and Unix versions of EMBOSS seem to differ in
    # which lines go to stdout and stderr - so merge them.
    child = subprocess.Popen(_escape_filename(exes["embossversion"]),
Exemplo n.º 19
0
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import PhymlCommandline
from Bio import MissingExternalDependencyError

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

phyml_exe = None
if sys.platform=="win32":
    raise MissingExternalDependencyError(
        "Testing PhyML on Windows not supported yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("phyml --version")
    if "not found" not in output and "20" in output:
        phyml_exe = "phyml"

if not phyml_exe:
    raise MissingExternalDependencyError(
        "Install PhyML 3.0 if you want to use the Bio.Phylo.Applications wrapper.")


# Example Phylip file with 4 aligned protein sequences
EX_PHYLIP = 'Phylip/interlaced2.phy'


class AppTests(unittest.TestCase):
    """Tests for application wrappers."""
Exemplo n.º 20
0
import sys
import os
import unittest
from Bio import AlignIO, SeqIO, MissingExternalDependencyError
from Bio.Align.Applications import TCoffeeCommandline

# Try to avoid problems when the OS is in another language
os.environ["LANG"] = "C"

t_coffee_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError(
        "Testing TCOFFEE on Windows not supported yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("t_coffee -version")
    if "not found" not in output \
       and ("t_coffee" in output.lower()
            or "t-coffee" in output.lower()):
        t_coffee_exe = "t_coffee"

if not t_coffee_exe:
    raise MissingExternalDependencyError(
        "Install TCOFFEE if you want to use the Bio.Align.Applications wrapper."
    )


class TCoffeeApplication(unittest.TestCase):
    def setUp(self):
        self.infile1 = "Fasta/fa01"
        # TODO: Use a temp dir for the output files:
Exemplo n.º 21
0
# This file is part of the Biopython distribution and governed by your
# choice of the "Biopython License Agreement" or the "BSD 3-Clause License".
# Please see the LICENSE file that should have been included as part of this
# package.
"""Unit tests for the Bio.PDB.ResidueDepth module."""

import unittest
import warnings
from Bio.PDB import PDBParser, ResidueDepth
from Bio import MissingExternalDependencyError
from Bio.PDB.PDBExceptions import PDBConstructionWarning

from Bio._py3k import getoutput
msms_exe = None
try:
    output = getoutput("msms -h")
    if output.startswith("Usage : msms parameters"):
        msms_exe = "msms"
except OSError:
    pass

if not msms_exe:
    raise MissingExternalDependencyError(
        "Install MSMS if you want to use it in Biopython.")


class ResidueDepthTests(unittest.TestCase):
    """Test ResidueDepth module."""
    def check_msms(self, prot_file, first_100_residues):
        p = PDBParser()
        with warnings.catch_warnings():
Exemplo n.º 22
0
import unittest
from Bio import AlignIO
from Bio import MissingExternalDependencyError
from Bio import SeqIO
from Bio.Align.Applications import MSAProbsCommandline
from Bio.Application import ApplicationError
from Bio._py3k import getoutput

#################################################################

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

msaprobs_exe = None
try:
    output = getoutput("msaprobs -version")
    if output.startswith("MSAPROBS version"):
        msaprobs_exe = "msaprobs"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not msaprobs_exe:
    raise MissingExternalDependencyError(
        "Install msaprobs if you want to use MSAProbs from Biopython.")


class MSAProbsTestCase(unittest.TestCase):

    def setUp(self):
        self.files_to_clean = set()
Exemplo n.º 23
0
import unittest
from Bio import AlignIO
from Bio import MissingExternalDependencyError
from Bio import SeqIO
from Bio.Align.Applications import MSAProbsCommandline
from Bio.Application import ApplicationError
from Bio._py3k import getoutput

#################################################################

# Try to avoid problems when the OS is in another language
os.environ["LANG"] = "C"

msaprobs_exe = None
try:
    output = getoutput("msaprobs -version")
    if output.startswith("MSAPROBS version"):
        msaprobs_exe = "msaprobs"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not msaprobs_exe:
    raise MissingExternalDependencyError(
        "Install msaprobs if you want to use MSAProbs from Biopython.")


class MSAProbsTestCase(unittest.TestCase):
    def setUp(self):
        self.files_to_clean = set()
Exemplo n.º 24
0
from Bio import MissingExternalDependencyError
from Bio import SeqIO
from Bio.Application import ApplicationError
from Bio.Motif.Applications import XXmotifCommandline

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

xxmotif_exe = None
if sys.platform == "win32":
    # TODO
    raise MissingExternalDependencyError(
        "Testing this on Windows is not implemented yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("XXmotif")
    if output.find("== XXmotif version") != -1:
        xxmotif_exe = "XXmotif"

if not xxmotif_exe:
    raise MissingExternalDependencyError(
        "Install XXmotif if you want to use XXmotif from Biopython.")


class XXmotifTestCase(unittest.TestCase):
    def setUp(self):
        self.out_dir = "xxmotif-temp"
        self.files_to_clean = set()

    def tearDown(self):
        for filename in self.files_to_clean:
Exemplo n.º 25
0
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import PhymlCommandline
from Bio import MissingExternalDependencyError

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

phyml_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError(
        "Testing PhyML on Windows not supported yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("phyml --version")
    if "not found" not in output and "20" in output:
        phyml_exe = "phyml"

if not phyml_exe:
    raise MissingExternalDependencyError(
        "Install PhyML 3.0 if you want to use the Bio.Phylo.Applications wrapper."
    )

# Example Phylip file with 4 aligned protein sequences
EX_PHYLIP = 'Phylip/interlaced2.phy'


class AppTests(unittest.TestCase):
    """Tests for application wrappers."""
    def test_phyml(self):
Exemplo n.º 26
0
        prog_files = os.environ["PROGRAMFILES"]
    except KeyError:
        prog_files = r"C:\Program Files"
    likely_dirs = ["bwa", "bwa-0.6.2", ""]
    likely_exes = ["bwa"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    bwa_exe = os.path.join(prog_files, folder, filename)
                    break
            if bwa_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("bwa")

    # Since "not found" may be in another language, try and be sure this is
    # really the bwa tool's output
    bwa_found = False
    if "not found" not in output and "bwa" in output \
            and "alignment via Burrows-Wheeler transformation" in output:
        bwa_exe = "bwa"
    skip_aln_tests = False
    aln_output = getoutput("bwa aln")
    if "unrecognized" in aln_output:
        skip_aln_tests = True
        print("'bwa aln' is unrecognized, skipping aln/samse/sampe tests")

if not bwa_exe:
    raise MissingExternalDependencyError("Install bwa and correctly set"
Exemplo n.º 27
0
        os.path.join(prog_files, "Muscle3.6"),
        os.path.join(prog_files, "Muscle3.7"),
        os.path.join(prog_files, "Muscle3.8"),
        os.path.join(prog_files, "Muscle3.9"),
        os.path.join(prog_files, "Muscle")
    ] + sys.path
    for folder in likely_dirs:
        if os.path.isdir(folder):
            if os.path.isfile(os.path.join(folder, "muscle.exe")):
                muscle_exe = os.path.join(folder, "muscle.exe")
                break
        if muscle_exe:
            break
else:
    from Bio._py3k import getoutput
    output = getoutput("muscle -version")
    # Since "not found" may be in another language, try and be sure this is
    # really the MUSCLE tool's output
    if "not found" not in output and "MUSCLE" in output \
       and "Edgar" in output:
        muscle_exe = "muscle"

if not muscle_exe:
    raise MissingExternalDependencyError(
        "Install MUSCLE if you want to use the Bio.Align.Applications wrapper."
    )

#################################################################


class MuscleApplication(unittest.TestCase):
Exemplo n.º 28
0
"""Unit tests for Bio.Phylo.Applications wrappers."""

import sys
import os
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import RaxmlCommandline
from Bio import MissingExternalDependencyError

raxml_exe = None
try:
    from Bio._py3k import getoutput

    output = getoutput("raxmlHPC -v")
    if "not found" not in output and "This is RAxML" in output:
        raxml_exe = "raxmlHPC"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not raxml_exe:
    raise MissingExternalDependencyError(
        "Install RAxML (binary raxmlHPC) if you want to test the Bio.Phylo.Applications wrapper."
    )

# Example Phylip file with 4 aligned protein sequences
EX_PHYLIP = "Phylip/interlaced2.phy"

Exemplo n.º 29
0
from Bio import MissingExternalDependencyError
from Bio import SeqIO
from Bio.Application import ApplicationError
from Bio.Motif.Applications import XXmotifCommandline


# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

xxmotif_exe = None
if sys.platform == "win32":
    # TODO
    raise MissingExternalDependencyError("Testing this on Windows is not implemented yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("XXmotif")
    if output.find("== XXmotif version") != -1:
        xxmotif_exe = "XXmotif"

if not xxmotif_exe:
    raise MissingExternalDependencyError(
        "Install XXmotif if you want to use XXmotif from Biopython.")


class XXmotifTestCase(unittest.TestCase):

    def setUp(self):
        self.out_dir = "xxmotif-temp"
        self.files_to_clean = set()

    def tearDown(self):
Exemplo n.º 30
0
    likely_exes = ["clustalw2.exe",
                   "clustalw.exe", "clustalw1.83.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    clustalw_exe = os.path.join(prog_files, folder, filename)
                    break
            if clustalw_exe:
                break
else:
    from Bio._py3k import getoutput
    # Note that clustalw 1.83 and clustalw 2.1 don't obey the --version
    # command, but this does cause them to quit cleanly.  Otherwise they prompt
    # the user for input (causing a lock up).
    output = getoutput("clustalw2 --version")
    # Since "not found" may be in another language, try and be sure this is
    # really the clustalw tool's output
    if "not found" not in output and "CLUSTAL" in output \
    and "Multiple Sequence Alignments" in output:
        clustalw_exe = "clustalw2"
    if not clustalw_exe:
        output = getoutput("clustalw --version")
        if "not found" not in output and "CLUSTAL" in output \
        and "Multiple Sequence Alignments" in output:
            clustalw_exe = "clustalw"

if not clustalw_exe:
    raise MissingExternalDependencyError(
        "Install clustalw or clustalw2 if you want to use it from Biopython.")
Exemplo n.º 31
0
        prog_files = os.environ["PROGRAMFILES"]
    except KeyError:
        prog_files = r"C:\Program Files"
    likely_dirs = ["bwa", "bwa-0.6.2", ""]
    likely_exes = ["bwa"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    bwa_exe = os.path.join(prog_files, folder, filename)
                    break
            if bwa_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("bwa")

    #Since "not found" may be in another language, try and be sure this is
    #really the bwa tool's output
    bwa_found = False
    if "not found" not in output and "bwa" in output \
            and "alignment via Burrows-Wheeler transformation" in output:
        bwa_exe = "bwa"

if not bwa_exe:
    raise MissingExternalDependencyError("Install bwa and correctly set"
                                         " the file path to the program if"
                                         " you want to use it from Biopython")


class BwaTestCase(unittest.TestCase):
Exemplo n.º 32
0
import sys
import os
import unittest
import subprocess
from Bio import MissingExternalDependencyError
from Bio.Align.Applications import MafftCommandline

#Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

mafft_exe = None
if sys.platform=="win32":
    raise MissingExternalDependencyError("Testing with MAFFT not implemented on Windows yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("mafft -help")
    if "not found" not in output and "MAFFT" in output:
        mafft_exe = "mafft"
if not mafft_exe:
    raise MissingExternalDependencyError(
        "Install MAFFT if you want to use the Bio.Align.Applications wrapper.")


def check_mafft_version(mafft_exe):
    child = subprocess.Popen("%s --help" % mafft_exe,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             universal_newlines=True,
                             shell=(sys.platform!="win32"))
    stdoutdata, stderrdata = child.communicate()
    output = stdoutdata + "\n" + stderrdata
Exemplo n.º 33
0
        prog_files = r"C:\Program Files"
    # By default tries C:\Program Files\samtools\samtools.exe
    # or  C:\Program Files\samtools.exe was chosen
    likely_dirs = ["samtools", ""]
    likely_exes = ["samtools.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    samtools_exe = os.path.join(prog_files, folder, filename)
                    break
            if samtools_exe:
                break
else:
    from Bio._py3k import getoutput
    output = getoutput("samtools")

    #Since "not found" may be in another language, try and be sure this is
    #really the samtools tool's output
    if ("not found" not in output and
       "samtools (Tools for alignments in the SAM format)" in output):
        samtools_exe = "samtools"

if not samtools_exe:
    raise MissingExternalDependencyError(
        """Install samtools and correctly set the file path to the program
        if you want to use it from Biopython""")


class SamtoolsTestCase(unittest.TestCase):
    """Class for implementing Samtools test cases."""
Exemplo n.º 34
0
    # For Windows, PRANK just comes as a zip file which contains the
    # prank.exe file which the user could put anywhere.  We'll try a few
    # sensible locations under Program Files... and then the full path.
    likely_dirs = ["",  # Current dir
                   prog_files,
                   os.path.join(prog_files, "Prank")] + sys.path
    for folder in likely_dirs:
        if os.path.isdir(folder):
            if os.path.isfile(os.path.join(folder, "prank.exe")):
                prank_exe = os.path.join(folder, "prank.exe")
                break
        if prank_exe:
            break
else:
    from Bio._py3k import getoutput
    output = getoutput("prank")
    if "not found" not in output and "prank" in output.lower():
        prank_exe = "prank"
if not prank_exe:
    raise MissingExternalDependencyError(
        "Install PRANK if you want to use the Bio.Align.Applications wrapper.")


class PrankApplication(unittest.TestCase):

    def setUp(self):
        self.infile1 = "Fasta/fa01"

    def tearDown(self):
        """
        output.1.dnd  output.1.fas  output.1.xml  output.2.dnd  output.2.fas  output.2.xml
Exemplo n.º 35
0
import sys
import os
import unittest
from Bio._py3k import StringIO
from Bio import AlignIO, SeqIO, MissingExternalDependencyError
from Bio.Align.Applications import ProbconsCommandline

# Try to avoid problems when the OS is in another language
os.environ["LANG"] = "C"

probcons_exe = None
if sys.platform == "win32":
    raise MissingExternalDependencyError("PROBCONS not available on Windows")
else:
    from Bio._py3k import getoutput
    output = getoutput("probcons")
    if "not found" not in output and "probcons" in output.lower():
        probcons_exe = "probcons"

if not probcons_exe:
    raise MissingExternalDependencyError(
        "Install PROBCONS if you want to use the Bio.Align.Applications wrapper."
    )


class ProbconsApplication(unittest.TestCase):
    def setUp(self):
        self.infile1 = "Fasta/fa01"
        self.annotation_outfile = "Fasta/probcons_annot.out"

    def tearDown(self):
Exemplo n.º 36
0
import sys
import os
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import PhymlCommandline
from Bio import MissingExternalDependencyError

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

phyml_exe = None
exe_name = "PhyML-3.1_win32.exe" if sys.platform == "win32" else "phyml"
from Bio._py3k import getoutput
try:
    output = getoutput(exe_name + " --version")
    if "not found" not in output and "20" in output:
        phyml_exe = exe_name
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    # Python 2.6 or 2.7 on Windows XP:
    # WindowsError: [Error 2] The system cannot find the file specified
    # Python 3.3 or 3.4 on Windows XP:
    # FileNotFoundError: [WinError 2] The system cannot find the file specified
    pass

if not phyml_exe:
    raise MissingExternalDependencyError(
        "Install PhyML 3.0 if you want to use the Bio.Phylo.Applications wrapper.")

Exemplo n.º 37
0
    likely_exes = ["FastTree.exe"]
    for folder in likely_dirs:
        if os.path.isdir(os.path.join(prog_files, folder)):
            for filename in likely_exes:
                if os.path.isfile(os.path.join(prog_files, folder, filename)):
                    fasttree_exe = os.path.join(prog_files, folder, filename)
                    break
            if fasttree_exe:
                break
else:
    from Bio._py3k import getoutput
    # Website uses 'FastTree', Nate's system had 'fasttree'
    likely_exes = ["FastTree", "fasttree"]
    for filename in likely_exes:
        # Checking the -help argument
        output = getoutput("%s -help" % filename)
        # Since "is not recognized" may be in another language, try and be sure this
        # is really the fasttree tool's output
        if "is not recognized" not in output and "protein_alignment" in output \
        and "nucleotide_alignment" in output:
            fasttree_exe = filename
            break

if not fasttree_exe:
    raise MissingExternalDependencyError(
        "Install FastTree and correctly set the file path to the program "
        "if you want to use it from Biopython.")

#################################################################

print("Checking error conditions")
Exemplo n.º 38
0
from Bio import AlignIO
from Bio.Align.Applications import ClustalOmegaCommandline
from Bio.Application import ApplicationError

#################################################################

# Try to avoid problems when the OS is in another language
os.environ['LANG'] = 'C'

clustalo_exe = None
if sys.platform=="win32":
    # TODO
    raise MissingExternalDependencyError("Testing this on Windows not implemented yet")
else:
    from Bio._py3k import getoutput
    output = getoutput("clustalo --help")
    if output.startswith("Clustal Omega"):
        clustalo_exe = "clustalo"

if not clustalo_exe:
    raise MissingExternalDependencyError(
        "Install clustalo if you want to use Clustal Omega from Biopython.")


class ClustalOmegaTestCase(unittest.TestCase):

    def setUp(self):
        self.files_to_clean = set()

    def tearDown(self):
        for filename in self.files_to_clean:
Exemplo n.º 39
0
    #sensible locations under Program Files... and then the full path.
    likely_dirs = [
        "",  # Current dir
        prog_files,
        os.path.join(prog_files, "Prank")
    ] + sys.path
    for folder in likely_dirs:
        if os.path.isdir(folder):
            if os.path.isfile(os.path.join(folder, "prank.exe")):
                prank_exe = os.path.join(folder, "prank.exe")
                break
        if prank_exe:
            break
else:
    from Bio._py3k import getoutput
    output = getoutput("prank")
    if "not found" not in output and "prank" in output.lower():
        prank_exe = "prank"
if not prank_exe:
    raise MissingExternalDependencyError(
        "Install PRANK if you want to use the Bio.Align.Applications wrapper.")


class PrankApplication(unittest.TestCase):
    def setUp(self):
        self.infile1 = "Fasta/fa01"

    def tearDown(self):
        """
        output.1.dnd  output.1.fas  output.1.xml  output.2.dnd  output.2.fas  output.2.xml
        """