-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_gff3.py
91 lines (61 loc) · 2.32 KB
/
test_gff3.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from easydev import TempFile
from sequana.gff3 import GFF3
from . import test_dir
def test_wrong_input():
try:
gff = GFF3(f"{test_dir}/data/missing")
gff.df
assert False
except IOError:
assert True
def test_various_gff():
gff = GFF3(f"{test_dir}/data/test_small.gff3")
df = gff.df
assert "telomere" in gff.features
gff = GFF3(f"{test_dir}/data/ecoli_truncated.gff")
assert gff.df.iloc[0].ID == "id0"
gff = GFF3(f"{test_dir}/data/mm10_truncated.gff")
assert gff.df.iloc[0].ID == "chromosome:1"
gff = GFF3(f"{test_dir}/data/hg38_truncated_gtf.gff")
assert gff.df.iloc[0].gene_id == "ENSG00000223972"
assert gff.clean_gff_line_special_characters("A%09A") == "A\tA"
gff = GFF3(f"{test_dir}/data/gff/lenny.gff")
df = gff.df
gff = GFF3(f"{test_dir}/data/gff/Ld1S.gff")
df = gff.df
def test_process_attributes():
gff = GFF3(f"{test_dir}/data/mm10_truncated.gff")
res = gff._process_attributes("ID=YAL058W;Name=YAL058W")
assert len(res) == 2
res = gff._process_attributes("ID YAL058W;Name YAL058W")
assert len(res) == 2
def test_transcript_to_gene():
gff = GFF3(f"{test_dir}/data/ecoli_truncated.gff")
gff.transcript_to_gene_mapping(attribute="Name")
def test_read_and_save_selected_features(tmpdir):
tmpfile = tmpdir.join("test.gff")
gff = GFF3(f"{test_dir}/data/ecoli_truncated.gff")
gff.read_and_save_selected_features(tmpfile)
def test_get_feature_dict():
gff = GFF3(f"{test_dir}/data/ecoli_truncated.gff")
gff.features
gff.get_features_dict()
def test_attributes(tmpdir):
g = GFF3(f"{test_dir}/data/gff/lenny.gff")
assert g.attributes
def test_to_bed(tmpdir):
outname = tmpdir.join("test.bed")
gff = GFF3(f"{test_dir}/data/ecoli_truncated.gff")
gff.to_bed(outname, "gene")
def test_to_fasta(tmpdir):
outname = tmpdir.join("test.fasta")
gff = GFF3(f"{test_dir}/data/gff/ecoli_MG1655.gff")
gff.to_fasta(f"{test_dir}/data/fasta/ecoli_MG1655.fa", outname)
def test_gff_to_gtf():
gff = GFF3(f"{test_dir}/data/saccer3_truncated.gff")
with TempFile() as fout:
df = gff.to_gtf(fout.name)
def test_save_gff_filtered():
gff = GFF3(f"{test_dir}/data/saccer3_truncated.gff")
with TempFile() as fout:
df = gff.save_gff_filtered(filename=fout.name)