Example #1
0
class TestLabels(unittest.TestCase):

    def setUp(self):
        self.go = OBO('files/test_data/go.obo')
        self.go.populate_annotations(GO_URL, remote_location=True)

        self.dsrepair_term = self.go.get_term(DSREPAIR_ID)

        lines = open('files/go_neg_slim.txt').readlines()
        self.slim_terms = set([l.strip() for l in lines])

    def testOntoLabelsNeg(self):
        ol = OntoLabels(obo=self.go, slim_terms=self.slim_terms)

        (pos, neg) = ol.get_labels(DSREPAIR_ID)
        self.assertTrue(len(pos) > 0)
        self.assertEqual(pos,set(self.dsrepair_term.get_annotated_genes()))

        similar_term = self.go.get_term(DNA_REP_ID).get_annotated_genes()

        slim_overlap = self.go.get_ancestors(DNA_REP_ID) & \
            self.go.get_ancestors(DSREPAIR_ID) & \
            self.slim_terms

        self.assertTrue(DNA_METAB in slim_overlap)
        self.assertTrue(len(neg & set(similar_term)) == 0)

        for dterm in self.go.get_descendents(DNA_METAB):
            dgenes = set(self.go.get_term(dterm).get_annotated_genes())
            self.assertTrue(len(neg & dgenes) == 0)
Example #2
0
class TestOBO(unittest.TestCase):
    def setUp(self):
        self.go = OBO('files/test_data/go.obo')
        self.dsrepair_term = self.go.get_term(DSREPAIR_ID)

    def test_load_remote(self):
        """Test loading an obo file from a URL"""
        self.go = OBO()
        self.go.load_obo(GO_URL, remote_location=True)
        self.test_load()

    def test_load(self):
        """Test an obo is loaded"""
        # Check that root biologcal process term is loaded
        term = self.go.get_term('GO:0008150')
        self.assertTrue(term is not None and term.name == 'biological_process')
        self.assertTrue(len(term.parent_of) > 0)

    def test_add_annotation(self):
        """Test that adding a gene annotations is correct"""
        self.assertTrue(self.dsrepair_term is not None)

        self.dsrepair_term.add_annotation('672')
        genes = self.dsrepair_term.get_annotated_genes()
        self.assertEqual(genes[0], '672')

    def test_propagation(self):
        """Test that gene propagation adds annotations to the correct terms"""
        self.assertTrue(self.dsrepair_term is not None)

        self.dsrepair_term.add_annotation('672')
        self.go.propagate()
        term_count = 0
        for term in self.go.get_termobject_list():
            term_count += len(term.get_annotated_genes())

        self.assertEqual(term_count, 26)

    def test_direct_annotation(self):
        """Test that direct annotation status is preserved"""
        self.assertTrue(self.dsrepair_term is not None)

        self.go.add_annotation(go_id=DSREPAIR_ID,
                               gid='672',
                               ref=None,
                               direct=True)
        self.go.propagate()

        direct_count, total = 0, 0
        for term in self.go.get_termobject_list():
            for a in term.annotations:
                if a.direct:
                    direct_count += 1
                    self.assertEqual(term, self.dsrepair_term)
                total += 1
        self.assertEqual(direct_count, 1)
        self.assertEqual(total, 26)

    def test_ancestors(self):
        """Test that ancestor terms are correct"""
        self.assertTrue(self.dsrepair_term is not None)
        self.assertEqual(len(self.go.get_ancestors(self.dsrepair_term.go_id)),
                         25)

    def test_parents(self):
        """Test that parent terms are stored correctly"""
        parents = self.dsrepair_term.child_of
        self.assertEqual(len(parents), 2)
        self.assertTrue(GOTerm('GO:0006302') in parents)
        self.assertTrue(GOTerm('GO:0000725') in parents)

    def test_heads(self):
        """Test that there are only three head nodes, corresponding to:
        biological process, molecular function, and cellular component
        """
        heads = set(
            [term for term in self.go.get_termobject_list() if term.head])
        self.assertEqual(len(heads), 3)

        self.assertTrue(GOTerm('GO:0008150') in heads)
        self.assertTrue(GOTerm('GO:0003674') in heads)
        self.assertTrue(GOTerm('GO:0005575') in heads)

    def test_obsolete(self):
        """Test that none of the stored terms are obsolete"""
        for term in self.go.get_termobject_list():
            self.assertTrue(not term.obsolete)

        for term in self.go.get_obsolete_terms():
            self.assertTrue(term.obsolete)

    def test_term_equals(self):
        """Test GOTerm equals method"""
        self.assertEqual(self.dsrepair_term, GOTerm(DSREPAIR_ID))

    def tearDown(self):
        self.go = None
        self.dsrepair_term = None
Example #3
0
for (tissue, stds) in tissue_std_edges.iteritems():
    c3 = tissue_std_edges[tissue]['0']
    for c3_edge in list(c3):
        # Limit negative edges to positive genes
        if len(c3_edge & tissue_all_pos) < 2:
            c3.remove(c3_edge)

for (tissue, stds) in tissue_std_edges.iteritems():
    c1 = tissue_std_edges[tissue]['1']
    c1_g = reduce(frozenset.union, c1)
    c1_tspc = c1_g - ubiq

    c3 = tissue_std_edges[tissue]['0']
    c3_g = reduce(frozenset.union, c3)
    c3_tspc = c3_g - ubiq

    c2 = within_edges_pos - c1
    c4 = within_edges_neg - c3
    if onto:
        for dtissue in onto.get_descendents(tissue):
            if dtissue in tissue_std_edges:
                c2 -= tissue_std_edges[dtissue]['1']
                c4 -= tissue_std_edges[dtissue]['0']
        for atissue in onto.get_ancestors(tissue):
            if atissue in tissue_std_edges:
                c2 -= tissue_std_edges[atissue]['1']
                c4 -= tissue_std_edges[atissue]['0']

    print tissue, len(c1_tspc), len(c1), len(c2), len(c3), len(c4)