Skip to content

Commit

Permalink
Merging, 12 changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Aug 17, 2010
2 parents e39b187 + fb94461 commit 4773377
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 49 deletions.
16 changes: 14 additions & 2 deletions Bio/Blast/Applications.py
Expand Up @@ -24,6 +24,11 @@
- NcbirpsblastCommandline - Reverse Position Specific BLAST
- NcbirpstblastnCommandline - Translated Reverse Position Specific BLAST
For further details, see:
Camacho et al. BLAST+: architecture and applications
BMC Bioinformatics 2009, 10:421
doi:10.1186/1471-2105-10-421
"""
from Bio.Application import _Option, AbstractCommandline, _Switch

Expand Down Expand Up @@ -332,7 +337,7 @@ def __init__(self, cmd="rpsblast",**kwargs):


class _NcbiblastCommandline(AbstractCommandline):
"""Base Commandline object for (classic) NCBI BLAST wrappers (PRIVATE).
"""Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
This is provided for subclassing, it deals with shared options
common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
Expand Down Expand Up @@ -475,7 +480,7 @@ def _validate_incompatibilities(self, incompatibles):
% (a,b))

class _Ncbiblast2SeqCommandline(_NcbiblastCommandline):
"""Base Commandline object for (classic) NCBI BLAST wrappers (PRIVATE).
"""Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
This is provided for subclassing, it deals with shared options
common to all the BLAST tools supporting two-sequence BLAST
Expand Down Expand Up @@ -692,6 +697,13 @@ def __init__(self, cmd="blastn", **kwargs):
"Minimum raw gapped score to keep an alignment in the preliminary gapped and traceback stages (integer).", False),
_Switch(["-ungapped", "ungapped"], ["input"],
"Perform ungapped alignment only?"),
_Option(["-off_diagonal_range", "off_diagonal_range"], ["input"], None, 0,
"""Number of off-diagonals to search for the 2nd hit (integer).
Expects a positive integer, or 0 (default) to turn off.
Added in BLAST 2.2.23+
""", False),
]
_Ncbiblast2SeqCommandline.__init__(self, cmd, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion Bio/Blast/NCBIStandalone.py
Expand Up @@ -2041,7 +2041,7 @@ def _safe_int(str):
pass
# If it fails again, maybe it's too long?
# XXX why converting to float?
return int(float(str))
return long(float(str))

def _safe_float(str):
# Thomas Rosleff Soerensen (rosleff@mpiz-koeln.mpg.de) noted that
Expand Down
2 changes: 1 addition & 1 deletion Bio/Phylo/PhyloXML.py
Expand Up @@ -794,7 +794,7 @@ class Point(PhyloElement):
def __init__(self, geodetic_datum, lat, long, alt=None, alt_unit=None):
self.geodetic_datum = geodetic_datum
self.lat = lat
self.long = int
self.long = long
self.alt = alt
self.alt_unit = alt_unit

Expand Down
2 changes: 1 addition & 1 deletion Bio/Prosite/Prodoc.py
Expand Up @@ -315,7 +315,7 @@ def index_file(filename, indexname, rec2key=None):
end = 0
for record in records:
start = end
end = int(handle.tell())
end = long(handle.tell())
length = end - start

if rec2key is not None:
Expand Down
2 changes: 1 addition & 1 deletion Bio/Prosite/__init__.py
Expand Up @@ -730,7 +730,7 @@ def index_file(filename, indexname, rec2key=None):
end = 0
for record in records:
start = end
end = int(handle.tell())
end = long(handle.tell())
length = end - start

if rec2key is not None:
Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/InsdcIO.py
Expand Up @@ -204,7 +204,7 @@ def _write_feature_qualifier(self, key, value=None, quote=None):
#self.handle.write('%s/%s="%s"\n' % (self.QUALIFIER_INDENT_STR, key, value))
if quote is None:
#Try to mimic unwritten rules about when quotes can be left out:
if isinstance(value, int) or isinstance(value, int):
if isinstance(value, int) or isinstance(value, long):
quote = False
else:
quote = True
Expand Down
2 changes: 1 addition & 1 deletion Bio/SwissProt/SProt.py
Expand Up @@ -1211,7 +1211,7 @@ def index_file(filename, indexname, rec2key=None):
end = 0
for record in records:
start = end
end = int(handle.tell())
end = long(handle.tell())
length = end - start

if rec2key is not None:
Expand Down
4 changes: 2 additions & 2 deletions BioSQL/Loader.py
Expand Up @@ -466,7 +466,7 @@ def _get_taxon_id_from_ncbi_lineage(self, taxonomic_lineage):
if len(taxonomic_lineage) > 1:
#Use recursion to find out the taxon id (database key) of the parent.
parent_taxon_id = self._get_taxon_id_from_ncbi_lineage(taxonomic_lineage[:-1])
assert isinstance(parent_taxon_id, int) or isinstance(parent_taxon_id, int), repr(parent_taxon_id)
assert isinstance(parent_taxon_id, int) or isinstance(parent_taxon_id, long), repr(parent_taxon_id)
else:
parent_taxon_id = None

Expand All @@ -476,7 +476,7 @@ def _get_taxon_id_from_ncbi_lineage(self, taxonomic_lineage):
"INSERT INTO taxon(ncbi_taxon_id, parent_taxon_id, node_rank)"\
" VALUES (%s, %s, %s)", (ncbi_taxon_id, parent_taxon_id, rank))
taxon_id = self.adaptor.last_id("taxon")
assert isinstance(taxon_id, int) or isinstance(taxon_id, int), repr(taxon_id)
assert isinstance(taxon_id, int) or isinstance(taxon_id, long), repr(taxon_id)
# ... and its name in taxon_name
scientific_name = taxonomic_lineage[-1].get("ScientificName", None)
if scientific_name:
Expand Down
26 changes: 18 additions & 8 deletions Tests/test_NCBI_BLAST_tools.py
Expand Up @@ -180,14 +180,24 @@ def check(self, exe_name, wrapper) :
if "-use_test_remote_service" in missing :
#Known issue, seems to be present in some builds (Bug 3043)
missing.remove("-use_test_remote_service")

if extra or missing :
raise MissingExternalDependencyError("BLAST+ and Biopython out of sync. "
"Your version of the NCBI BLAST+ tool %s does not match what we "
"are expecting. Please update your copy of Biopython, or report "
"this issue if you are already using the latest version. "
"(Exta args: %s; Missing: %s)" \
% (exe_name, ",".join(sorted(extra)), ",".join(sorted(missing))))
if exe_name == "blastn" and "-off_diagonal_range" in extra:
#Added in BLAST 2.2.23+
extra.remove("-off_diagonal_range")
if exe_name == "tblastx":
#These appear to have been removed in BLAST 2.2.23+
#(which seems a bit odd - TODO - check with NCBI?)
extra = extra.difference(["-gapextend","-gapopen",
"-xdrop_gap","-xdrop_gap_final"])

if extra or missing:
raise MissingExternalDependencyError("BLAST+ and Biopython out "
"of sync. Your version of the NCBI BLAST+ tool %s does not "
"match what we are expecting. Please update your copy of "
"Biopython, or report this issue if you are already using "
"the latest version. (Exta args: %s; Missing: %s)" \
% (exe_name,
",".join(sorted(extra)),
",".join(sorted(missing))))

#An almost trivial example to test any validation
cline = wrapper(exe, query="dummy")
Expand Down
31 changes: 1 addition & 30 deletions Tests/test_PDB.py
Expand Up @@ -15,24 +15,16 @@
from io import StringIO

try:
from numpy.random import random
import numpy
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"Install NumPy if you want to use Bio.PDB.")

try:
from Bio.KDTree import _CKDTree
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"C module in Bio.KDTree not compiled")

from Bio.Seq import Seq
from Bio.Alphabet import generic_protein
from Bio.PDB import PDBParser, PPBuilder, CaPPBuilder, PDBIO
from Bio.PDB import HSExposureCA, HSExposureCB, ExposureCN
from Bio.PDB.NeighborSearch import NeighborSearch
from Bio.PDB.PDBExceptions import PDBConstructionException, PDBConstructionWarning


Expand Down Expand Up @@ -693,27 +685,6 @@ def test_ExposureCN(self):
self.assertEqual(1, len(residues[-1].xtra))
self.assertEqual(38, residues[-1].xtra["EXP_CN"])


class NeighborTest(unittest.TestCase):
def setUp(self):
warnings.resetwarnings()

def test_neighbor_search(self):
"""NeighborSearch: Find nearby randomly generated coordinates.
Based on the self test in Bio.PDB.NeighborSearch.
"""
class RandomAtom:
def __init__(self):
self.coord = 100 * random(3)
def get_coord(self):
return self.coord
for i in range(0, 20):
atoms = [RandomAtom() for j in range(100)]
ns = NeighborSearch(atoms)
hits = ns.search_all(5.0)
self.assertTrue(hits >= 0)

# -------------------------------------------------------------

if __name__ == '__main__':
Expand Down
49 changes: 49 additions & 0 deletions Tests/test_PDB_KDTree.py
@@ -0,0 +1,49 @@
# Copyright 2009-2010 by Eric Talevich. All rights reserved.
# Revisions copyright 2010 by Peter Cock. All rights reserved.
#
# Converted by Eric Talevich from an older unit test copyright 2002
# by Thomas Hamelryck.
#
# 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.

"""Unit tests for those parts of the Bio.PDB module using Bio.KDTree."""
import unittest

try:
from numpy.random import random
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"Install NumPy if you want to use Bio.PDB.")

try:
from Bio.KDTree import _CKDTree
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"C module in Bio.KDTree not compiled")

from Bio.PDB.NeighborSearch import NeighborSearch

class NeighborTest(unittest.TestCase):
def test_neighbor_search(self):
"""NeighborSearch: Find nearby randomly generated coordinates.
Based on the self test in Bio.PDB.NeighborSearch.
"""
class RandomAtom:
def __init__(self):
self.coord = 100 * random(3)
def get_coord(self):
return self.coord
for i in range(0, 20):
atoms = [RandomAtom() for j in range(100)]
ns = NeighborSearch(atoms)
hits = ns.search_all(5.0)
self.assertTrue(hits >= 0)

if __name__ == '__main__':
runner = unittest.TextTestRunner(verbosity=2)
unittest.main(testRunner=runner)
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -138,7 +138,8 @@ def run(self):
if not check_dependencies_once():
return
# add software that requires NumPy to install
if is_Numpy_installed():
# TODO - Convert these for Python 3
if is_Numpy_installed() and sys.version_info[0] < 3:
import numpy
numpy_include_dir = numpy.get_include()
self.extensions.append(
Expand Down

0 comments on commit 4773377

Please sign in to comment.