Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from mhcflurry.fixed_length_peptides import (
all_kmers,
extend_peptide,
shorten_peptide,
fixed_length_from_many_peptides,
)
from nose.tools import eq_
def test_all_kmers():
kmers = all_kmers(2, alphabet=["A", "B"])
assert len(kmers) == 4, kmers
eq_(set(kmers), {"AA", "AB", "BA", "BB"})
def test_all_kmers_string_alphabet():
kmers = all_kmers(2, alphabet="AB")
assert len(kmers) == 4, kmers
eq_(set(kmers), {"AA", "AB", "BA", "BB"})
def test_extend_peptide_all_positions():
# insert 0 or 1 at every position
results = extend_peptide(
"111",
desired_length=4,
start_offset=0,
end_offset=0,
alphabet="01")
expected = [
"0111",
"1111",
"1011",
"1111",
"1101",
"1111",
"1110",
"1111",
]
eq_(results, expected)
def test_shorten_peptide_all_positions():
# insert 0 or 1 at every position
results = shorten_peptide(
"012",
desired_length=2,
start_offset=0,
end_offset=0,
alphabet="012")
expected = [
"12",
"02",
"01"
]
eq_(results, expected)
def test_shorten_peptide_all_positions_except_first():
# insert 0 or 1 at every position
results = shorten_peptide(
"012",
desired_length=2,
start_offset=1,
end_offset=0,
alphabet="012")
expected = [
"02",
"01",
]
eq_(results, expected)
def test_shorten_peptide_all_positions_except_last():
# insert 0 or 1 at every position
results = shorten_peptide(
"012",
desired_length=2,
start_offset=0,
end_offset=1,
alphabet="012")
expected = [
"12",
"02",
]
eq_(results, expected)
def test_fixed_length_from_many_peptides():
kmers, original, counts = fixed_length_from_many_peptides(
peptides=["ABC", "A"],
desired_length=2,
start_offset_extend=0,
end_offset_extend=0,
start_offset_shorten=0,
end_offset_shorten=0,
alphabet="ABC")
print(kmers)
print(original)
print(counts)
eq_(len(kmers), len(original))
eq_(len(kmers), len(counts))
eq_(kmers, ["BC", "AC", "AB", "AA", "BA", "CA", "AA", "AB", "AC"])
eq_(original, ["ABC", "ABC", "ABC", "A", "A", "A", "A", "A", "A"])
eq_(counts, [3, 3, 3, 6, 6, 6, 6, 6, 6])