Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
d = Delegator(l)
c = copy(d)
assert c is not d
assert c._handler is d._handler
def test_deepcopy(self):
"""copy.deepcopy should work correctly on Delegator"""
l = ["a"]
d = Delegator(l)
c = deepcopy(d)
assert c is not d
assert c._handler is not d._handler
assert c._handler == d._handler
class FunctionWrapperTests(TestCase):
"""Tests of the FunctionWrapper class"""
def test_init(self):
"""FunctionWrapper should initialize with any callable"""
f = FunctionWrapper(str)
g = FunctionWrapper(id)
h = FunctionWrapper(iterable)
x = 3
self.assertEqual(f(x), "3")
self.assertEqual(g(x), id(x))
self.assertEqual(h(x), [3])
def test_copy(self):
"""copy should work for FunctionWrapper objects"""
f = FunctionWrapper(str)
c = copy(f)
self.assertEqual(self.taxID_to_obj[7].ParentId, 6) # NcbiTaxon objs
self.assertEqual(self.taxID_to_obj[9].ParentId, 7)
self.assertEqual(self.taxID_to_obj[1].Rank, "no rank")
self.assertEqual(self.taxID_to_obj[2].Rank, "superkingdom")
self.assertEqual(self.taxID_to_obj[6].Rank, "genus")
self.assertEqual(self.taxID_to_obj[7].Rank, "species")
self.assertEqual(self.taxID_to_obj[7].EmblCode, "AC")
self.assertEqual(self.taxID_to_obj[7].DivisionId, "0")
self.assertEqual(self.taxID_to_obj[7].DivisionInherited, 1)
self.assertEqual(self.taxID_to_obj[7].TranslTable, 11)
self.assertEqual(self.taxID_to_obj[7].TranslTableInherited, 1)
self.assertEqual(self.taxID_to_obj[7].TranslTableMt, 0)
self.assertEqual(self.taxID_to_obj[7].TranslTableMtInherited, 1)
class NcbiTaxonomyTests(TestCase):
"""Tests of the NcbiTaxonomy class."""
def setUp(self):
self.tx = NcbiTaxonomyFromFiles(good_nodes, good_names)
def test_init_good(self):
"""NcbiTaxonomyFromFiles should pass spot-checks of resulting objects"""
self.assertEqual(len(self.tx.ByName), 6)
self.assertEqual(len(self.tx.ById), 6)
self.assertEqual(self.tx[10].Name, "Fakus namus")
self.assertEqual(self.tx["1"].Name, "root")
self.assertEqual(self.tx["root"].parent, None)
self.assertEqual(self.tx.Deadbeats, {})
def test_init_bad(self):
"""NcbiTaxonomyFromFiles should produce deadbeats by default"""
brca2 = self.comp.Dmelanogaster.getGeneByStableId(
StableId='FBgn0050169')
orthologs = self.comp.getRelatedGenes(gene_region=brca2,
Relationship='ortholog_one2one')
self.assertEqual(len(orthologs.Members), 2)
def test_get_collection(self):
sc35 = self.comp.Dmelanogaster.getGeneByStableId(
StableId="FBgn0040286")
Orthologs = self.comp.getRelatedGenes(gene_region=sc35,
Relationship="ortholog_one2one")
collection = Orthologs.getSeqCollection()
self.assertTrue(len(collection.Seqs[0]) > 1000)
class MZ_Genome(TestCase):
def test_get_general_release(self):
"""should correctly infer the general release"""
rel_lt_65 = Genome('D.melanogaster', Release=22, account=account)
self.assertEqual(rel_lt_65.GeneralRelease, 75)
self.assertEqual(rel_lt_65.CoreDb.db_name,
'drosophila_melanogaster_core_22_75_546')
rel_gt_65 = Genome('D.melanogaster', Release=23, account=account)
self.assertEqual(rel_gt_65.GeneralRelease, 76)
self.assertEqual(rel_gt_65.CoreDb.db_name,
'drosophila_melanogaster_core_23_76_546')
if __name__ == "__main__":
main()
from cogent3.maths.period_numba import goertzel_inner as numba_goertzel_inner
from cogent3.maths.period_numba import ipdft_inner as numba_ipdft_inner
from cogent3.util.unit_test import TestCase, main
__author__ = "Hua Ying, Julien Epps and Gavin Huttley"
__copyright__ = "Copyright 2007-2020, The Cogent Project"
__credits__ = ["Julien Epps", "Hua Ying", "Gavin Huttley"]
__license__ = "BSD-3"
__version__ = "2020.7.2a"
__maintainer__ = "Gavin Huttley"
__email__ = "Gavin.Huttley@anu.edu.au"
__status__ = "Production"
class TestPeriod(TestCase):
def setUp(self):
t = arange(0, 10, 0.1)
n = random.randn(len(t))
nse = convolve(n, exp(-t / 0.05)) * 0.1
nse = nse[: len(t)]
self.sig = sin(2 * pi * t) + nse
self.p = 10
def test_inner_funcs(self):
"""python and pyrexed implementation should be the same"""
x = array(
[
0.04874203,
0.56831373,
0.94267804,
0.95664485,
Ala Arg Asn Asp Cys Gln Glu Gly His Ile Leu Lys Met Phe Pro Ser Thr Trp Tyr Val
S_ij = S_ji and PI_i for the Dayhoff model, with the rate Q_ij=S_ij*PI_j
The rest of the file is not used.
Prepared by Z. Yang, March 1995.
See the following reference for notation used here:
Yang, Z., R. Nielsen and M. Hasegawa. 1998. Models of amino acid substitution and
applications to mitochondrial protein evolution. Mol. Biol. Evol. 15:1600-1611.
"""
class TestParsePamlMatrix(TestCase):
def test_parse(self):
matrix, freqs = PamlMatrixParser(StringIO(data))
self.assertEqual(DSO78_matrix, matrix)
self.assertEqual(DSO78_freqs, freqs)
pass
if __name__ == "__main__":
main()
from cogent3.core.moltype import RNA
from cogent3.core.sequence import ArraySequence, RnaSequence, Sequence
from cogent3.util.unit_test import TestCase, main
__author__ = "Sandra Smit"
__copyright__ = "Copyright 2007-2020, The Cogent Project"
__credits__ = ["Sandra Smit", "Gavin Huttley"]
__license__ = "BSD-3"
__version__ = "2020.7.2a"
__maintainer__ = "Sandra Smit"
__email__ = "sandra.smit@colorado.edu"
__status__ = "Production"
class AllTests(TestCase):
def setUp(self):
"""setUp method for all tests"""
# named sequences
self.rna1 = RnaSequence("UCAGGG", name="rna1")
self.rna2 = RnaSequence("YCU-RG", name="rna2")
self.rna3 = RnaSequence("CAA-NR", name="rna3")
self.model1 = ArraySequence(
"UCAGGG", name="rna1", alphabet=RNA.alphabets.degen_gapped
)
self.model2 = ArraySequence(
"YCU-RG", name="rna2", alphabet=RNA.alphabets.degen_gapped
)
self.model3 = ArraySequence(
"CAA-NR", name="rna3", alphabet=RNA.alphabets.degen_gapped
)
self.assertFloatEqual(f(s1, s5), 2.0)
# test behavior with different normalizer
f = for_seq(diff, aggregator=sumsq, normalizer=None)
self.assertFloatEqual(f(s1, s5), 10)
f = for_seq(diff, aggregator=sumsq)
self.assertFloatEqual(f(s1, s5), 2.0)
f = for_seq(diff, aggregator=sumsq, normalizer=times_two)
self.assertFloatEqual(f(s1, s5), 20)
f = for_seq(diff, aggregator=sumsq)
self.assertFloatEqual(f(s5, short), 4)
f = for_seq(diff, aggregator=sumsq, normalizer=long_norm)
self.assertFloatEqual(f(s5, short), 0.8)
class Filter_Criteria_Tests(TestCase):
"""Tests of standalone functions used as filter criteria"""
def test_KeepChars(self):
"""KeepChars returns a string containing only chars in keep"""
f = KeepChars("ab c3*[")
self.assertEqual(f(""), "") # empty
self.assertRaises(TypeError, f, None) # None
# one character, case sensitive
self.assertEqual(f("b"), "b")
self.assertEqual(f("g"), "")
self.assertEqual(f("xyz123"), "3")
self.assertEqual(f("xyz 123"), " 3")
# more characters, case sensitive
self.assertEqual(f("kjbwherzcagebcujrkcs"), "bcabcc")
class has_y(object):
# convenience class for has_field and related functions
def __init__(self, y):
self.y = y
def __hash__(self):
return hash(self.y)
def __str__(self):
return str(self.y)
class metafunctionsTests(TestCase):
"""Tests of standalone functions."""
def setUp(self):
"""Define some standard functions and data."""
self.Numbers = list(range(20))
self.SmallNumbers = list(range(3))
self.SmallNumbersRepeated = list(range(5)) * 4
self.Letters = "abcde"
self.Mixed = list(self.Letters) + list(range(5))
self.firsts = "ab2"
self.seconds = "0bc"
self.is_char = lambda x: isinstance(x, str) and len(x) == 1
self.is_vowel = lambda x: x in "aeiou"
self.is_consonant = lambda x: x not in "aeiuo"
self.is_number = lambda x: isinstance(x, int)
from cogent3.core.profile import PSSM, MotifCountsArray, MotifFreqsArray
from cogent3.util.unit_test import TestCase, main
__author__ = "Gavin Huttley"
__copyright__ = "Copyright 2007-2020, The Cogent Project"
__credits__ = ["Sandra Smit", "Gavin Huttley"]
__license__ = "BSD-3"
__version__ = "2020.7.2a"
__maintainer__ = "Gavin Huttley"
__email__ = "Gavin.Huttley@anu.edu.au"
__status__ = "Production"
class MotifCountsArrayTests(TestCase):
def test_construct_succeeds(self):
"""construct from int array or list"""
from cogent3.maths.stats.number import CategoryCounter
states = "ACGT"
rows = [CategoryCounter([b] * 20) for b in "ACGT"]
rows = [r.tolist(states) for r in rows]
pwm = MotifCountsArray(rows, states)
data = [[2, 4], [3, 5], [4, 8]]
got = MotifCountsArray(array(data), "AB")
self.assertEqual(got.array.tolist(), data)
got = MotifCountsArray(data, "AB")
self.assertEqual(got.array.tolist(), data)
def test_Names(self):
"""NcbiTaxonomy should fill in names correctly"""
self.assertEqual(self.tx["6"].Name, "Azorhizobium")
self.assertEqual(self.tx["1"].Name, "root")
self.assertEqual(self.tx["2"].Name, "Bacteria")
self.assertEqual(self.tx["7"].Name, "Azorhizobium caulinodans")
def test_last_common_ancestor(self):
"""NcbiTaxonomy should support last_common_ancestor()"""
assert self.tx[9].last_common_ancestor(self.tx[9]) is self.tx[9]
assert self.tx[9].last_common_ancestor(self.tx[7]) is self.tx[7]
assert self.tx[9].last_common_ancestor(self.tx[10]) is self.tx[6]
assert self.tx[9].last_common_ancestor(self.tx[1]) is self.tx[1]
class NcbiTaxonNodeTests(TestCase):
"""Tests of the NcbiTaxonNode class.
Note: only testing methods that differ from the TreeNode base class.
Note: nested_species is explicitly designed to test the case where the nodes
file does _not_ contain the root, and where the id of the de facto
root is not 1, to make sure there's nothing special about a node
called 'root' or with id 1.
"""
def test_getRankedDescendants(self):
"""NcbiTaxonNode getRankedDescendants should return correct list"""
nested_species = """3\t|\t3\t|\tsuperkingdom\t|\t\t|\t8\t|\t0\t|\t1\t|\t0\t|\t0\t|\t0\t|\t0\t|\t0\t|\t\t|
11\t|\t3\t|\tkingdom\t|\t\t|\t8\t|\t0\t|\t1\t|\t0\t|\t0\t|\t0\t|\t0\t|\t0\t|\t\t|
22\t|\t11\t|\tclass\t|\t\t|\t8\t|\t0\t|\t1\t|\t0\t|\t0\t|\t0\t|\t0\t|\t0\t|\t\t|
44\t|\t22\t|\torder\t|\t\t|\t0\t|\t0\t|\t11\t|\t0\t|\t0\t|\t0\t|\t0\t|\t0\t|\t\t|