-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_basics.py
60 lines (51 loc) · 2.17 KB
/
test_basics.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
import os
import matplotlib
matplotlib.use("Agg")
from crazydoc import CrazydocParser, CrazydocSketcher, records_to_genbank
example_path = os.path.join("tests", "data", "test_sample.docx")
protein_path = os.path.join("tests", "data", "test_protein_seq.docx")
def test_crazydocparser(tmpdir):
parser = CrazydocParser(
["highlight_color", "bold", "underline", "lower_case", "font_color"]
)
biopython_records = parser.parse_doc_file(example_path)
record_features = [
[(f.location.start, f.location.end, f.qualifiers) for f in record.features]
for record in biopython_records
]
assert len(
[
start
for start, end, qual in record_features[0]
if (start, end, qual.get("lower_case", False)) == (1237, 1253, True)
]
)
records_to_genbank(biopython_records, path=str(tmpdir))
sketcher = CrazydocSketcher()
for record in biopython_records:
sketch = sketcher.translate_record(record)
ax, _ = sketch.plot()
ax.set_title(record.id)
filepath = os.path.join(str(tmpdir), "%s.png" % record.id)
ax.figure.savefig(filepath, bbox_inches="tight")
# PROTEIN SEQUENCES:
biopython_records = parser.parse_doc_file(protein_path, is_protein=True)
record_features = [
[(f.location.start, f.location.end, f.qualifiers) for f in record.features]
for record in biopython_records
]
# Test for names with "/":
records_to_genbank(biopython_records, path=str(tmpdir), is_protein=True)
assert os.path.exists(os.path.join(tmpdir, "Protein sequence 2-a.gp"))
# Test truncation of LOCUS names to 20 characters in Genbank file:
with open(os.path.join(tmpdir, "Protein sequence with a long name 1.gp")) as f:
first_line = f.readline()
first_line.split()[1] == "Protein_sequence_wit"
sketcher = CrazydocSketcher()
for record in biopython_records:
sketch = sketcher.translate_record(record)
ax, _ = sketch.plot()
ax.set_title(record.id)
filename = record.id.replace("/", "-") + ".png"
filepath = os.path.join(str(tmpdir), filename)
ax.figure.savefig(filepath, bbox_inches="tight")