本文整理汇总了Python中skbio.SequenceCollection.distribution_stats方法的典型用法代码示例。如果您正苦于以下问题:Python SequenceCollection.distribution_stats方法的具体用法?Python SequenceCollection.distribution_stats怎么用?Python SequenceCollection.distribution_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.SequenceCollection
的用法示例。
在下文中一共展示了SequenceCollection.distribution_stats方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import distribution_stats [as 别名]
#.........这里部分代码省略.........
# Test to ensure floating point precision bug isn't present. See the
# tests for BiologicalSequence.k_word_frequencies for more details.
sc = SequenceCollection([RNA('C' * 10, id='s1'),
RNA('G' * 10, id='s2')])
self.assertEqual(sc.k_word_frequencies(1),
[defaultdict(float, {'C': 1.0}),
defaultdict(float, {'G': 1.0})])
def test_str(self):
exp1 = ">d1\nGATTACA\n>d2\nTTG\n"
self.assertEqual(str(self.s1), exp1)
exp2 = ">r1\nGAUUACA\n>r2\nUUG\n>r3\nU-----UGCC--\n"
self.assertEqual(str(self.s2), exp2)
exp4 = ""
self.assertEqual(str(self.empty), exp4)
def test_distances(self):
s1 = SequenceCollection([DNA("ACGT", "d1"), DNA("ACGG", "d2")])
expected = [[0, 0.25],
[0.25, 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
actual = s1.distances(hamming)
self.assertEqual(actual, expected)
# alt distance function provided
def dumb_distance(s1, s2):
return 42.
expected = [[0, 42.],
[42., 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
actual = s1.distances(dumb_distance)
self.assertEqual(actual, expected)
def test_distribution_stats(self):
actual1 = self.s1.distribution_stats()
self.assertEqual(actual1[0], 2)
self.assertAlmostEqual(actual1[1], 5.0, 3)
self.assertAlmostEqual(actual1[2], 2.0, 3)
actual2 = self.s2.distribution_stats()
self.assertEqual(actual2[0], 3)
self.assertAlmostEqual(actual2[1], 7.333, 3)
self.assertAlmostEqual(actual2[2], 3.682, 3)
actual3 = self.s3.distribution_stats()
self.assertEqual(actual3[0], 5)
self.assertAlmostEqual(actual3[1], 6.400, 3)
self.assertAlmostEqual(actual3[2], 3.323, 3)
actual4 = self.empty.distribution_stats()
self.assertEqual(actual4[0], 0)
self.assertEqual(actual4[1], 0.0)
self.assertEqual(actual4[2], 0.0)
def test_degap(self):
expected = SequenceCollection([
RNASequence('GAUUACA', id="r1"),
RNASequence('UUG', id="r2"),
RNASequence('UUGCC', id="r3")])
actual = self.s2.degap()
self.assertEqual(actual, expected)
def test_get_seq(self):
self.assertEqual(self.s1.get_seq('d1'), self.d1)
self.assertEqual(self.s1.get_seq('d2'), self.d2)
示例2: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import distribution_stats [as 别名]
#.........这里部分代码省略.........
self.assertEqual(sc.kmer_frequencies(1, relative=True),
[defaultdict(float, {'C': 1.0}),
defaultdict(float, {'G': 1.0})])
def test_str(self):
exp1 = ">d1\nGATTACA\n>d2\nTTG\n"
self.assertEqual(str(self.s1), exp1)
exp2 = ">r1\nGAUUACA\n>r2\nUUG\n>r3\nU-----UGCC--\n"
self.assertEqual(str(self.s2), exp2)
exp4 = ""
self.assertEqual(str(self.empty), exp4)
def test_distances(self):
s1 = SequenceCollection([DNA("ACGT", metadata={'id': "d1"}),
DNA("ACGG", metadata={'id': "d2"})])
expected = [[0, 0.25],
[0.25, 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
def h(s1, s2):
return hamming(s1.values, s2.values)
actual = s1.distances(h)
self.assertEqual(actual, expected)
# alt distance function provided
def dumb_distance(s1, s2):
return 42.
expected = [[0, 42.],
[42., 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
actual = s1.distances(dumb_distance)
self.assertEqual(actual, expected)
def test_distribution_stats(self):
actual1 = self.s1.distribution_stats()
self.assertEqual(actual1[0], 2)
self.assertAlmostEqual(actual1[1], 5.0, 3)
self.assertAlmostEqual(actual1[2], 2.0, 3)
actual2 = self.s2.distribution_stats()
self.assertEqual(actual2[0], 3)
self.assertAlmostEqual(actual2[1], 7.333, 3)
self.assertAlmostEqual(actual2[2], 3.682, 3)
actual3 = self.s3.distribution_stats()
self.assertEqual(actual3[0], 5)
self.assertAlmostEqual(actual3[1], 6.400, 3)
self.assertAlmostEqual(actual3[2], 3.323, 3)
actual4 = self.empty.distribution_stats()
self.assertEqual(actual4[0], 0)
self.assertEqual(actual4[1], 0.0)
self.assertEqual(actual4[2], 0.0)
def test_degap(self):
expected = SequenceCollection([
RNA('GAUUACA', metadata={'id': "r1"}),
RNA('UUG', metadata={'id': "r2"}),
RNA('UUGCC', metadata={'id': "r3"})])
actual = self.s2.degap()
self.assertEqual(actual, expected)
def test_get_seq(self):
self.assertEqual(self.s1.get_seq('d1'), self.d1)
self.assertEqual(self.s1.get_seq('d2'), self.d2)
示例3: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import distribution_stats [as 别名]
#.........这里部分代码省略.........
[expected1, expected2])
self.assertEqual(self.empty.k_word_frequencies(k=1), [])
def test_str(self):
"""str functions as expected
"""
exp1 = ">d1\nGATTACA\n>d2\nTTG\n"
self.assertEqual(str(self.s1), exp1)
exp2 = ">r1\nGAUUACA\n>r2\nUUG\n>r3\nU-----UGCC--\n"
self.assertEqual(str(self.s2), exp2)
exp4 = ""
self.assertEqual(str(self.empty), exp4)
def test_distances(self):
"""distances functions as expected
"""
s1 = SequenceCollection([DNA("ACGT", "d1"), DNA("ACGG", "d2")])
expected = [[0, 0.25],
[0.25, 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
actual = s1.distances(hamming)
self.assertEqual(actual, expected)
# alt distance function provided
def dumb_distance(s1, s2):
return 42.
expected = [[0, 42.],
[42., 0]]
expected = DistanceMatrix(expected, ['d1', 'd2'])
actual = s1.distances(dumb_distance)
self.assertEqual(actual, expected)
def test_distribution_stats(self):
"""distribution_stats functions as expected
"""
actual1 = self.s1.distribution_stats()
self.assertEqual(actual1[0], 2)
self.assertAlmostEqual(actual1[1], 5.0, 3)
self.assertAlmostEqual(actual1[2], 2.0, 3)
actual2 = self.s2.distribution_stats()
self.assertEqual(actual2[0], 3)
self.assertAlmostEqual(actual2[1], 7.333, 3)
self.assertAlmostEqual(actual2[2], 3.682, 3)
actual3 = self.s3.distribution_stats()
self.assertEqual(actual3[0], 5)
self.assertAlmostEqual(actual3[1], 6.400, 3)
self.assertAlmostEqual(actual3[2], 3.323, 3)
actual4 = self.empty.distribution_stats()
self.assertEqual(actual4[0], 0)
self.assertEqual(actual4[1], 0.0)
self.assertEqual(actual4[2], 0.0)
def test_degap(self):
"""degap functions as expected
"""
expected = [(id_, seq.replace('.', '').replace('-', ''))
for id_, seq in self.seqs2_t]
expected = SequenceCollection.from_fasta_records(expected, RNASequence)
actual = self.s2.degap()
self.assertEqual(actual, expected)
def test_get_seq(self):