def test_cstr_error(): o_src = Gene('source') o_tgt = Gene('target') # genes should have a family with pytest.raises(Exception): o_edge = Edge(o_src, o_tgt) o_family = GeneFamily(None, None) o_family.addGene(o_src) # both genes sould have a family with pytest.raises(Exception): o_edge = Edge(o_src, o_tgt) # gene should belong to the same organism o_family.addGene(o_tgt) o_src.fill_parents("", None) o_tgt.fill_parents(None, None) with pytest.raises(Exception): o_edge = Edge(o_src, o_tgt)
def test_edges(filled_families): lo_fam, lo_genes = filled_families # get several genes and make an edge # between them and the first of the list n_genes = randint(2, len(lo_genes)) sample_genes = sample(lo_genes, n_genes ) l_edges = [] for o_gene in sample_genes: # it is strange to me to update family attribute from another class. l_edges.append( Edge(lo_genes[0], o_gene) ) # we have 0->{*} l = lo_fam[0].edges #set because order is not guaranted assert set(l_edges) == set(l)
def test_cstr(): o_src = Gene('source') o_tgt = Gene('target') # set organism and contig to None. o_src.fill_parents(None, None) o_tgt.fill_parents(None, None) # define the None GeneFamily, and add the 2 genes to it. o_family = GeneFamily(None, None) o_family.addGene(o_src) o_family.addGene(o_tgt) o_edge = Edge(o_src, o_tgt) assert isinstance(o_edge, Edge) assert o_edge.source == o_src.family assert o_edge.target == o_tgt.family assert dict(o_edge.organisms) == {None: [(o_src, o_tgt)]}
def filled_edge(make_gene_pair): # Note that the same edge here links 4 families. p1 = make_gene_pair("org1", "s1", "t1") p2 = make_gene_pair("org1", "s2", "t1") p3 = make_gene_pair("org2", "s1", "t2") p4 = make_gene_pair("org2", "s1", "s2") # org1: s1,s2 -- t1 # org2: s1 -- t2,s2 o_edge = Edge(*p1) o_edge.addGenes(*p2) o_edge.addGenes(*p3) o_edge.addGenes(*p4) return o_edge
def test_addGenes(make_gene_pair): p1 = make_gene_pair("org1", "s1", "t1") p2 = make_gene_pair("org1", "s2", "t1") p3 = make_gene_pair("org2", "s1", "t2") p4 = make_gene_pair("org2", "s1", "s2") # org1: s1,s2 -- t1 # org2: s1 -- t2,s2 o_edge = Edge(*p1) o_edge.addGenes(*p2) o_edge.addGenes(*p3) o_edge.addGenes(*p4) assert set(o_edge.organisms.keys()) == set(["org1", "org2"]) assert o_edge.organisms["org1"] == [p1, p2] assert o_edge.organisms["org2"] == [p3, p4]
def test_neighbors(filled_families): lo_fam, lo_genes = filled_families # get several genes and make an edge # between them and the first of the list n_genes = randint(2, len(lo_genes)) sample_genes = sample(lo_genes, n_genes ) for o_gene in sample_genes: # it is strange to me to update family attribute from another class. Edge(lo_genes[0], o_gene) # we have 0->{*} # first gene belong to the first family # let's get the family neighbors # set because order is not guaranted s = set(lo_fam[0].neighbors) print(s) assert n_genes == len(s) xpected = { g.family for g in sample_genes } assert xpected == s
def test_genePairs(make_gene_pair): # cannot use filled_edge because i need access to pairs. p1 = make_gene_pair("org1", "s1", "t1") p2 = make_gene_pair("org1", "s2", "t1") p3 = make_gene_pair("org2", "s1", "t2") p4 = make_gene_pair("org2", "s1", "s2") # org1: s1,s2 -- t1 # org2: s1 -- t2,s2 o_edge = Edge(*p1) o_edge.addGenes(*p2) o_edge.addGenes(*p3) o_edge.addGenes(*p4) # 'set' because the order is not guaranted due to '.values()'. l_pairs = o_edge.genePairs assert set(l_pairs) == set([p1, p2, p3, p4])
def o_edge(make_gene_pair): p = make_gene_pair("org", "src", "tgt") return Edge(*p)