コード例 #1
0
ファイル: test-transitive-2.py プロジェクト: ctb/paircomp
def is_transitive(A, B, C, windowsize=20, threshold=.5):
    ab = paircomp.do_simple_nxn_compare(A, B, windowsize, threshold)
    bc = paircomp.do_simple_nxn_compare(B, C, windowsize, threshold)
    ac = paircomp.do_simple_nxn_compare(A, C, windowsize, threshold)

    ac_tran1 = paircomp.build_transitive(ab, bc, A, C, threshold)
    ac_tran2 = paircomp.filter_transitively(ab, bc, ac)[2]

    assert ac_tran1 == ac_tran2
コード例 #2
0
ファイル: test-compare-mussa.py プロジェクト: ctb/paircomp
def test():
    t1 = fasta.load_single(thisdir + 't1.fa', force='DNA')
    t2 = fasta.load_single(thisdir + 't2.fa', force='DNA')
    t3 = fasta.load_single(thisdir + 't3.fa', force='DNA')

    AB = paircomp.do_simple_nxn_compare(t1, t2, 4, 1.0)
    BC = paircomp.do_simple_nxn_compare(t2, t3, 4, 1.0)
    AC = paircomp.do_simple_nxn_compare(t1, t3, 4, 1.0)

    (new_AB, new_BC, new_AC) = paircomp.filter_transitively(AB, BC, AC)

    #print_cmp(new_AB)
    #print_cmp(new_BC)
    #print_cmp(new_AC)

    expected = \
    """
    4:0,0,20
    4:0,0,-5
    4:0,29,20
    4:0,29,-5
    4:0,-16,-5
    4:0,-16,20
    4:33,6,33
    4:33,6,-33
    4:33,43,33
    4:33,43,-33
    4:33,-43,-33
    4:33,-43,33
    4:33,-6,-33
    4:33,-6,33\
    """

    print 'Comparing paircomp output to Mussa\'s...',

    l = print_tristan_3way(new_AB, new_BC, new_AC)
    l.sort()

    l2 = parse_tristan_3way(expected)
    l2.sort()

    assert l == l2
    print 'success'

    if l != l2:
        print 'DIFF: CTB'

        for x in l:
            if not x in l2:
                print x

        print 'vs TDB'

        for x in l2:
            if not x in l:
                print x
コード例 #3
0
ファイル: test-python-interface.py プロジェクト: ctb/paircomp
    def test(self):
        el = self.el
        br = self.br

        el_path = self.el_path
        br_path = self.br_path

        ### four different ways of doing analyses:

        #
        # execute paircomp
        #

        outname = 'el-br-0.5.p.cmp'
        os.system('rm %s >& /dev/null' % (outname,))
        os.system('%s/paircomp %s %s 20 .5 %s >& /dev/null' % \
                  (bindir, self.el_path, self.br_path, outname))
    
        p_cmp = paircomp.parse_paircomp(open(outname).read(),
                                        len(el), len(br), 20)
        os.system('rm %s >& /dev/null' % (outname,))
        
        #
        # execute seqcomp
        #

        outname = 'el-br-0.5.s.cmp'
        os.system('rm %s >& /dev/null' % (outname,))
        os.system('%s/seqcomp %s %s 20 10 noxml %s >& /dev/null' % \
                  (bindir, el_path, br_path, outname))
        s_cmp = paircomp.parse_seqcomp(open(outname).read(),
                                       len(el), len(br), 20)
        os.system('rm %s >& /dev/null' % (outname,))

        #
        # & use the python interface.
        #

        rolling_cmp = self.cmp
        simple_cmp = paircomp.do_simple_nxn_compare(el, br, 20, .5)

        ## also load in an old analysis for regression testing

        old_paircomp = paircomp.parse_paircomp(open('%s/orig-el-br.txt' % \
                                                    (thisdir,)).read(),
                                               len(el), len(br), 20)

        ## check to make sure they all return the same result!

        print 'Testing equality of internal vs external analyses...',

        assert p_cmp == s_cmp
        assert p_cmp == simple_cmp
        assert p_cmp == rolling_cmp
        assert p_cmp == old_paircomp
コード例 #4
0
ファイル: test-errors.py プロジェクト: ctb/paircomp
def test():
    el = fasta.load_single(thisdir + 'el.txt')
    br = fasta.load_single(thisdir + 'br.txt')
    re = fasta.load_single(thisdir + 're.txt')

    ### first break the algorithms.

    simple_cmp = None

    try:
        simple_cmp = paircomp.do_simple_nxn_compare("ATCCGRRRRUUUUU", br, 10, .5)
    except:
        pass
    assert simple_cmp is None

    # break on windowsizes
    try:
        simple_cmp = paircomp.do_simple_nxn_compare(el, br, -1, .5)
    except:
        pass
    assert simple_cmp is None

    try:
        simple_cmp = paircomp.do_simple_nxn_compare(el, br, 256, .5)
    except:
        pass
    assert simple_cmp is None

    try:
        # break on windowsizes in relation to sequence len
        simple_cmp = paircomp.do_simple_nxn_compare("AAAAAAAAAAAAAAAAAAA",
                                                    br, 20, .5)
    except:
        pass
    assert simple_cmp is None

    try:
        simple_cmp = paircomp.do_simple_nxn_compare(el, "AAAAAAAAAAAAAAAAAAA",
                                                    20, .5)
    except:
        pass
    assert simple_cmp is None

    # break on threshold
    try:
        simple_cmp = paircomp.do_simple_nxn_compare(el, br, 9, -.01)
    except:
        pass
    assert simple_cmp is None

    try:
        simple_cmp = paircomp.do_simple_nxn_compare(el, br, 9, 1.01)
    except:
        pass
    assert simple_cmp is None

    simple_cmp_1 = paircomp.do_simple_nxn_compare(el, br, 20, .5)

    simple_cmp_2 = paircomp.do_simple_nxn_compare(el, br, 22, .5)

    result = None
    try:
        result = simple_cmp_1.contains(simple_cmp_2)
    except:
        pass
    assert result is None

    try:
        result = simple_cmp_1.equals(simple_cmp_2)
    except:
        pass
    assert result is None

    try:
        result = simple_cmp_1.subtract(simple_cmp_2)
    except:
        pass
    assert result is None

    try:
        result = simple_cmp_1.intersect(simple_cmp_2)
    except:
        pass

    assert result is None

    ### test transitivity stuff

    windowsize = 20
    threshold = 0.7
    ab = paircomp.do_simple_nxn_compare(el, br, windowsize, threshold)
    ab2 = paircomp.do_simple_nxn_compare(el, br, windowsize+1, threshold)
    bc = paircomp.do_simple_nxn_compare(br, re, windowsize, threshold)
    bc2 = paircomp.do_simple_nxn_compare(br, re, windowsize+1, threshold)
    ac = paircomp.do_simple_nxn_compare(el, re, windowsize, threshold)

    results = None
    try:
        results = paircomp.build_transitive(ab, bc, el, br, threshold)
    except:
        pass
    assert results is None

    try:
        results = paircomp.build_transitive(ab, bc, br, re, threshold)
    except Exception, e:
        pass
コード例 #5
0
ファイル: simple-paircomp.py プロジェクト: ctb/paircomp
#! /usr/bin/env python
import sys
import fasta
import paircomp

top = fasta.load_single(sys.argv[1])
bot = fasta.load_single(sys.argv[2])
windowsize = int(sys.argv[3])
threshold = float(sys.argv[4])
outfile = sys.argv[5]

cmp = paircomp.do_simple_nxn_compare(top, bot, windowsize, threshold)
cmp.save(outfile)
コード例 #6
0
ファイル: test-transitive.py プロジェクト: ctb/paircomp
def test():
    A='aaaaaaaaaaaaaaaaaaaa'
    B='aaaaaaaaaaaaaaaaaaaa'
    C='aaaaaaaaaaaaaaaaaaaa'

    AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
    BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
    AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

    l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]

    A='aaaaaaaaaaaaaaaaaaaa'
    B='tttttttttttttttttttt'
    C='tttttttttttttttttttt'

    AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
    BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
    AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

    l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
    assert l == [0, 0, 0]

    A='tttttttttttttttttttt'
    B='aaaaaaaaaaaaaaaaaaaa'
    C='tttttttttttttttttttt'

    AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
    BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
    AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

    l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
    assert l == [0, 0, 0]

    A='tttttttttttttttttttt'
    B='tttttttttttttttttttt'
    C='aaaaaaaaaaaaaaaaaaaa'

    AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
    BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
    AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

    l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
    assert l == [0, 0, 0]

    print 'Tests PASSED.'
コード例 #7
0
ファイル: test-python-interface.py プロジェクト: ctb/paircomp
    def test_python_functions(self):

        el, br = self.el, self.br
        cmp = self.cmp
        
        #
        # ok, now abuse the Python interface.
        #

        print 'Testing basic functions...',

        assert cmp.windowsize == 20
        assert cmp.top_len == len(el)
        assert cmp.bot_len == len(br)

        n = []
        for i in range(0, len(el)):
            l = cmp[i]
            for m in l:
                assert m.top == i
            n.extend(l)

        n2 = []
        for match in cmp:
            n2.append(match)

        for (a, b) in zip(n, n2):
            assert a == b

        print 'Testing reverse of top/bottom...',

        a = cmp.reverse_top()
        b = a.reverse_top()
        c = b.reverse_top()

        assert cmp == b
        assert a == c
        assert b != c

        a = cmp.reverse_bottom()
        b = a.reverse_bottom()
        c = b.reverse_bottom()

        assert cmp == b
        assert a == c
        assert b != c

        el_rc = fasta.reverse_complement(el)
        br_rc = fasta.reverse_complement(br)
        cmp_fr = paircomp.do_simple_nxn_compare(el, br_rc, 20, .5)
        cmp_rf = paircomp.do_simple_nxn_compare(el_rc, br, 20, .5)
        cmp_rr = paircomp.do_simple_nxn_compare(el_rc, br_rc, 20, .5)
        
        assert cmp == cmp_fr.reverse_bottom()
        assert cmp == cmp_rf.reverse_top()
        assert cmp == cmp_rr.reverse_bottom().reverse_top()

        print 'Testing inverse...',

        a = cmp.invert()
        b = a.invert()
        c = b.invert()

        assert cmp == b
        assert a == c

        cmp_i = paircomp.do_simple_nxn_compare(br, el, 20, .5)
        assert cmp == cmp_i.invert()
            
        print 'Testing filter by orientation...',

        # should be equal
        a = cmp.filter_orientation(True, True)
        assert a == cmp

        # should not be equal!
        a = cmp.filter_orientation(True, False)
        assert a != cmp

        b = cmp.filter_orientation(False, True)
        assert a != cmp
        
        # should be equal
        a = cmp.filter_orientation(True, False)
        b = cmp.reverse_bottom().filter_orientation(False, True)
        b = b.reverse_bottom()

        assert a == b

        # should be equal
        a = cmp.filter_orientation(True, False)
        b = cmp.reverse_top().filter_orientation(False, True)
        b = b.reverse_top()

        assert a == b

        print 'Testing filter by threshold...',
            
        # filter gradually...
        a = cmp.filter(.6)
        b = cmp.filter(.7)
        c = cmp.filter(.8)

        # and all at once
        d = cmp.filter(.8)

        assert d == c

        ###

        print 'Testing set operations...',

        a = b = cmp
        assert a.contains(b)
        assert b.contains(a)

        c = a - b
        assert c.is_empty()
        assert a.contains(c)
        assert c == a - (a.intersect(b))

        b = cmp.filter(.6)
        assert a.contains(b)
        assert not b.contains(a)
        c = a - b
        assert not c.is_empty()

        ### 1bp conversion

        print 'Testing 1bp conversion...',

        a = b = cmp
        b = cmp.filter(.6)
        b = b.isolate_matching_bases(el, br)
        a = a.isolate_matching_bases(el, br)

        assert a.contains(b)
コード例 #8
0
ファイル: test-python-interface.py プロジェクト: ctb/paircomp
    def test_3way(self):
        "Test transitivity filtering"

        A='aaaaaaaaaaaaaaaaaaaa'
        B='tttttttttttttttttttt'
        C='tttttttttttttttttttt'

        AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
        BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
        AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

        l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
        assert l == [0, 0, 0]
        
        A='tttttttttttttttttttt'
        B='aaaaaaaaaaaaaaaaaaaa'
        C='tttttttttttttttttttt'

        AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
        BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
        AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

        l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
        assert l == [0, 0, 0]
        
        A='tttttttttttttttttttt'
        B='tttttttttttttttttttt'
        C='aaaaaaaaaaaaaaaaaaaa'

        AB=paircomp.do_simple_nxn_compare(A, B, 20, .9)
        BC=paircomp.do_simple_nxn_compare(B, C, 20, .9)
        AC=paircomp.do_simple_nxn_compare(A, C, 20, .9)

        l = [i.is_empty() for i in paircomp.parser.filter_transitively(AB, BC, AC) ]
        assert l == [0, 0, 0]
            
        ### try some broken ones.

        A='ttttttttttttttttttttt'
        B='tttttttttttttttttttt'
        C='aaaaaaaaaaaaaaaaaaa'

        AB=paircomp.do_simple_nxn_compare(A, B, 15, .9)
        BC=paircomp.do_simple_nxn_compare(B, C, 15, .9)
        AC=paircomp.do_simple_nxn_compare(A, C, 15, .9)

        failed = False
        try:
            # should fail: AB-->AC
            paircomp.parser.filter_transitively(AB, BC, AB)
            #    ---------------------------------------^^
        except:
            failed = True

        assert failed