def count_ecological_edges(methods, num_ees, ro):
    '''Automates counting of ecological edges.

    Inputs:
     methods - list of strs. names of methods that weer used to generate the 
      engineered edges. must be formatted properly (e.g. 
      'amensally_related_1d_st_3' and in the same order as the num_ees list. 
     num_ees - list of ints. numbers of otus that are generated by each 
      method in the methods list.
     ro - result object.
    '''
    starts = cumsum([0]+num_ees[:-1]) #add a 0 entry for start indices
    stops = cumsum(num_ees)
    method_names, strengths, dims = get_params_from_methods(methods)
    edge_counts = [interacting_edges(starts[i], stops[i], dims[i], ro.edges, 
        ro.interactions) for i in range(len(num_ees))] 
    return (method_names, strengths, dims, edge_counts, len(ro.edges))
def count_ecological_edges(methods, num_ees, ro):
    '''Automates counting of ecological edges.

    Inputs:
     methods - list of strs. names of methods that weer used to generate the 
      engineered edges. must be formatted properly (e.g. 
      'amensally_related_1d_st_3' and in the same order as the num_ees list. 
     num_ees - list of ints. numbers of otus that are generated by each 
      method in the methods list.
     ro - result object.
    '''
    starts = cumsum([0] + num_ees[:-1])  #add a 0 entry for start indices
    stops = cumsum(num_ees)
    method_names, strengths, dims = get_params_from_methods(methods)
    edge_counts = [
        interacting_edges(starts[i], stops[i], dims[i], ro.edges,
                          ro.interactions) for i in range(len(num_ees))
    ]
    return (method_names, strengths, dims, edge_counts, len(ro.edges))
Exemplo n.º 3
0
    def test_interacting_edges(self):
        '''Test that interacting edges are calculated correctly.'''    
        edges = [\
            ('o0','o2'),
            ('o1','o2'),
            ('o0','o1'),
            ('o3','o2'),
            ('o3','o5'),
            ('o11','o25'),
            ('o0','o6'),
            ('o47','o50'),
            ('o6','o7')]
        interactions = [\
            'mutualExclusion',
            'mutualExclusion',
            'mutualExclusion',
            'mutualExclusion',
            'copresence',
            'copresence',
            'copresence',
            'copresence',
            'copresence']

        # test with 1d relationships
        start = 0
        stop = 10
        dim = 1

        exp_total_detected = 3
        exp_cis_edges = 0
        exp_cis_cps = 0
        exp_cis_mes = 0
        exp_trans_edges = 3
        exp_trans_cps = 1
        exp_trans_mes = 2

        self.assertEqual((exp_total_detected, exp_cis_edges, exp_cis_cps, 
            exp_cis_mes, exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # test with 1d relationships, offset from last 
        start = 1
        stop = 5
        dim = 1

        exp_total_detected = 1
        exp_cis_edges = 0
        exp_cis_cps = 0
        exp_cis_mes = 0
        exp_trans_edges = 1
        exp_trans_cps = 0
        exp_trans_mes = 1

        self.assertEqual((exp_total_detected, exp_cis_edges, exp_cis_cps, 
            exp_cis_mes, exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))
        
        # test case with 2d relationships. inverted direction in some cases.
        start = 0
        stop = 6
        dim = 2    
        
        exp_total_detected = 4
        exp_cis_edges = 1
        exp_cis_cps = 0
        exp_cis_mes = 1
        exp_trans_edges = 3
        exp_trans_cps = 1
        exp_trans_mes = 2

        self.assertEqual((exp_total_detected, exp_cis_edges, exp_cis_cps, 
            exp_cis_mes, exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))
        
        # adjust start to make sure it handles non zero starts correctly
        start = 3
        stop = 9
        dim = 2

        exp_total_detected = 2
        exp_cis_edges = 1
        exp_cis_cps = 1
        exp_cis_mes = 0
        exp_trans_edges = 1
        exp_trans_cps = 1
        exp_trans_mes = 0

        self.assertEqual((exp_total_detected, exp_cis_edges, exp_cis_cps, 
            exp_cis_mes, exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # test with 4d relationships
        start = 0
        stop = 50
        dim = 5

        exp_total_detected = 6
        exp_cis_edges = 5
        exp_cis_cps = 1
        exp_cis_mes = 4
        exp_trans_edges = 1
        exp_trans_cps = 1
        exp_trans_mes = 0

        self.assertEqual((exp_total_detected, exp_cis_edges, exp_cis_cps, 
            exp_cis_mes, exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))
Exemplo n.º 4
0
    def test_interacting_edges(self):
        '''Test that interacting edges are calculated correctly.'''
        edges = [\
            ('o0','o2'),
            ('o1','o2'),
            ('o0','o1'),
            ('o3','o2'),
            ('o3','o5'),
            ('o11','o25'),
            ('o0','o6'),
            ('o47','o50'),
            ('o6','o7')]
        interactions = [\
            'mutualExclusion',
            'mutualExclusion',
            'mutualExclusion',
            'mutualExclusion',
            'copresence',
            'copresence',
            'copresence',
            'copresence',
            'copresence']

        # test with 1d relationships
        start = 0
        stop = 10
        dim = 1

        exp_total_detected = 3
        exp_cis_edges = 0
        exp_cis_cps = 0
        exp_cis_mes = 0
        exp_trans_edges = 3
        exp_trans_cps = 1
        exp_trans_mes = 2

        self.assertEqual(
            (exp_total_detected, exp_cis_edges, exp_cis_cps, exp_cis_mes,
             exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # test with 1d relationships, offset from last
        start = 1
        stop = 5
        dim = 1

        exp_total_detected = 1
        exp_cis_edges = 0
        exp_cis_cps = 0
        exp_cis_mes = 0
        exp_trans_edges = 1
        exp_trans_cps = 0
        exp_trans_mes = 1

        self.assertEqual(
            (exp_total_detected, exp_cis_edges, exp_cis_cps, exp_cis_mes,
             exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # test case with 2d relationships. inverted direction in some cases.
        start = 0
        stop = 6
        dim = 2

        exp_total_detected = 4
        exp_cis_edges = 1
        exp_cis_cps = 0
        exp_cis_mes = 1
        exp_trans_edges = 3
        exp_trans_cps = 1
        exp_trans_mes = 2

        self.assertEqual(
            (exp_total_detected, exp_cis_edges, exp_cis_cps, exp_cis_mes,
             exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # adjust start to make sure it handles non zero starts correctly
        start = 3
        stop = 9
        dim = 2

        exp_total_detected = 2
        exp_cis_edges = 1
        exp_cis_cps = 1
        exp_cis_mes = 0
        exp_trans_edges = 1
        exp_trans_cps = 1
        exp_trans_mes = 0

        self.assertEqual(
            (exp_total_detected, exp_cis_edges, exp_cis_cps, exp_cis_mes,
             exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))

        # test with 4d relationships
        start = 0
        stop = 50
        dim = 5

        exp_total_detected = 6
        exp_cis_edges = 5
        exp_cis_cps = 1
        exp_cis_mes = 4
        exp_trans_edges = 1
        exp_trans_cps = 1
        exp_trans_mes = 0

        self.assertEqual(
            (exp_total_detected, exp_cis_edges, exp_cis_cps, exp_cis_mes,
             exp_trans_edges, exp_trans_cps, exp_trans_mes),
            interacting_edges(start, stop, dim, edges, interactions))