-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_pipeline.py
78 lines (64 loc) · 2.33 KB
/
test_pipeline.py
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
from collections import namedtuple
from calm.alphabet import Alphabet
from calm.sequence import CodonSequence
from calm.pipeline import (
Pipeline,
PipelineInput,
DataCollator,
DataTrimmer,
DataPadder,
DataPreprocessor,
)
def fake_args():
Args = namedtuple('args', [
'mask_proportion',
'max_positions',
'mask_percent',
'leave_percent'
])
return Args(mask_proportion=.25, max_positions=10,
mask_percent=.8, leave_percent=.1)
def test_DataCollator_codon():
args = fake_args()
alphabet = Alphabet.from_architecture('CodonModel')
data_collator = DataCollator(args, alphabet)
seq1 = CodonSequence('AUG GGA CGC UUU UAC CAA AUG GGA CGC UUU UAC CAA UAA ' * 10)
seq2 = CodonSequence('AUG GGA CGC UAA')
input_ = PipelineInput(sequence=[seq1, seq2])
output = data_collator(input_)
assert output.ground_truth[0] == seq1.seq
assert output.sequence[0].split().count('<mask>') == int(len(seq1.tokens) * .25 * .8)
assert output.target_mask[0].sum() == int(len(seq1.tokens) * .25)
def test_DataTrimmer_codon():
args = fake_args()
alphabet = Alphabet.from_architecture('CodonModel')
data_trimmer = Pipeline([
DataCollator(args, alphabet),
DataTrimmer(args, alphabet)
])
seq1 = CodonSequence('AUG GGA CGC UUU UAC CAA AUG GGA CGC UUU UAC CAA UAA ' * 10)
seq2 = CodonSequence('AUG GGA CGC UAA')
output = data_trimmer([seq1, seq2])
def test_DataPadder_codon():
args = fake_args()
alphabet = Alphabet.from_architecture('CodonModel')
data_padder = Pipeline([
DataCollator(args, alphabet),
DataTrimmer(args, alphabet),
DataPadder(args, alphabet),
])
seq1 = CodonSequence('AUG GGA CGC UUU UAC CAA AUG GGA CGC UUU UAC CAA UAA ' * 10)
seq2 = CodonSequence('AUG GGA CGC UAA')
output = data_padder([seq1, seq2])
def test_DataPreprocessor_codon():
args = fake_args()
alphabet = Alphabet.from_architecture('CodonModel')
data_preprocessor = Pipeline([
DataCollator(args, alphabet),
DataTrimmer(args, alphabet),
DataPadder(args, alphabet),
DataPreprocessor(args, alphabet)
])
seq1 = CodonSequence('AUG GGA CGC UUU UAC CAA AUG GGA CGC UUU UAC CAA UAA ' * 10)
seq2 = CodonSequence('AUG GGA CGC UAA')
output = data_preprocessor([seq1, seq2])