File: sitemask_tests.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (84 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download
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
"""
Tests for `bx.align.maf.sitemask`.
"""

import tempfile
from io import StringIO

import bx.align.maf
from bx.align.sitemask import cpg

test_maf_cpg = """##maf version=1 scoring=none
a score=0
s apple  34 64 + 110 AGGGA---GTTCGTCACT------GTCGTAAGGGTTCAGA--CTGTCTATGTATACACAAGTTGTGTTGCA--ACCG
s orange 19 61 - 100 AGGGATGCGTT--TCACTGCTATCGTCGTA----TTCAGACTTCG-CTATCT------GAGTTGT---GCATTACCG
"""

cpg_inclusive_result = [
    "##maf,version=1",
    "a,score=0",
    "s,apple,34,64,+,110,AGGGA---GTTCGTCACT------GT##TAAGGGTTCAGA--CTGTCTATGTATACACAAGTTGTGTTGCA--ACCG",
    "s,orange,19,61,-,100,AGGGATG#GTT--TCACTGCTAT#GT##TA----TTCAGACTTCG-CTATCT------GAGTTGT---GCATTACCG",
]

cpg_restricted_result = [
    "##maf,version=1",
    "a,score=0",
    "s,apple,34,64,+,110,A##GA---#TT##TC#C#------#T##TA###GTTC#GA--C##TC#A#G#ATAC####GT#G#GT#GC#--AC#G",
    "s,orange,19,61,-,100,A##GA#G##TT--TC#C#GC#AT##T##TA----TTC#GAC#T##-C#A#C#------##GT#G#---GC#TTAC#G",
]

noncpg_result = [
    "##maf,version=1",
    "a,score=0",
    "s,apple,34,64,+,110,#GG##---G##CG##A#T------G#CG##AGG####A##--#TG##T#T#T####ACAA##T#T##T##A--##CG",
    "s,orange,19,61,-,100,#GG##T#CG##--##A#T##T##CG#CG##----###A###T#CG-#T#T#T------GA##T#T---##A####CG",
]


def test_cpg_inclusive():
    reader = bx.align.maf.Reader(StringIO(test_maf_cpg))
    out = tempfile.NamedTemporaryFile("w")
    writer = bx.align.maf.Writer(out)
    cpgfilter = cpg.Inclusive(mask="#")
    cpgfilter.run(reader, writer.write)
    out.seek(0)
    j = 0
    for line in open(out.name):
        line = line.strip()
        if not (line):
            continue
        assert cpg_inclusive_result[j] == ",".join(line.split())
        j += 1


def test_cpg_restricted():
    reader = bx.align.maf.Reader(StringIO(test_maf_cpg))
    out = tempfile.NamedTemporaryFile("w")
    writer = bx.align.maf.Writer(out)
    cpgfilter = cpg.Restricted(mask="#")
    cpgfilter.run(reader, writer.write)
    out.seek(0)
    j = 0
    for line in open(out.name):
        line = line.strip()
        if not (line):
            continue
        assert cpg_restricted_result[j] == ",".join(line.split())
        j += 1


def test_non_cpg():
    reader = bx.align.maf.Reader(StringIO(test_maf_cpg))
    out = tempfile.NamedTemporaryFile("w")
    writer = bx.align.maf.Writer(out)
    cpgfilter = cpg.nonCpG(mask="#")
    cpgfilter.run(reader, writer.write)
    out.seek(0)
    j = 0
    for line in open(out.name):
        line = line.strip()
        if not (line):
            continue
        assert noncpg_result[j] == ",".join(line.split())
        j += 1