def test_unipartite_motif_weighted_participation(self): for i in range(0,2): result = pymfinder(self.test_filename_u[i], motifsize=i+2, networktype = "unipartite", weighted=True, allmotifs=True) all_roles = result.nodes[result.nodes.keys()[0]].weighted_motifs.keys() roles=[[int(result.nodes[n].weighted_motifs[r]) for r in all_roles] for n in result.nodes] check_columns=[sum(x)/(i+2) for x in zip(*roles)]==all_roles # Check the number of nodes in each motif check_rows=[sum(x) for x in roles]==[int(result.nodes[x].id[:-1]) for x in result.nodes] # Check that each node is in only one motif self.assertTrue(check_columns and check_rows)
def test_unipartite_motif_participation(self): for i in range(0,2): result = pymfinder(self.test_filename_u[i], motifsize=i+2, networktype = "unipartite", allmotifs=True,) all_roles = result.nodes[result.nodes.keys()[0]].motifs.keys() roles=[[result.nodes[n].motifs[r] for r in all_roles] for n in result.nodes] check_columns=[sum(x) for x in zip(*roles)]==[i+2]*len(all_roles) # Check the number of nodes in each motif check_rows=[sum(x) for x in roles]==[1]*len(result.nodes) # Check that each node is in only one motif self.assertTrue(check_columns and check_rows)
def test_bipartite_motif_roles(self): for i in range(0,5): result = pymfinder(self.test_filename_b[i], motifsize=i+2, networktype = "bipartite", allmotifs=False) all_roles = result.nodes[result.nodes.keys()[0]].roles.keys() roles=[[result.nodes[n].roles[r] for r in all_roles] for n in result.nodes] check_columns=any(v==0 for v in [ sum(x) for x in zip(*roles)])==False check_rows=[sum(x) for x in roles]==[1]*len(result.nodes) self.assertTrue(check_columns and check_rows)
def test_bipartite_link_participation(self): for i in range(0,5): result = pymfinder(self.test_filename_b[i], motifsize=i+2, networktype = "bipartite",links=True, allmotifs=False) all_roles = result.links[result.links.keys()[0]].motifs.keys() # List of motifs roles=[[result.links[n].motifs[r] for r in sorted(all_roles)] for n in result.links] # r are motifs, n are link tuples motiflist=sorted(result.motifs.keys()) # Need to keep these in the same order check_columns=[sum(x) for x in zip(*roles)]==[bipartite_links_per_motif[i+2][motif] for motif in motiflist] # Each motif contains the number of links I think it should check_rows=[sum(x) for x in roles]==[1]*len(result.links) # Each link is in only one motif self.assertTrue(check_columns and check_rows)
def test_bipartite_link_roles(self): for i in range(0,5): result = pymfinder(self.test_filename_b[i], motifsize=i+2, networktype = "bipartite", links=True, allmotifs=False) all_roles = result.links[result.links.keys()[0]].roles.keys() roles=[[result.links[n].roles[r] for r in all_roles] for n in result.links] columns=[sum(x) for x in zip(*roles)] #Are there the number of links we think there are? check_total_links=sum(columns)==sum(bipartite_links_per_motif[i+2].values()) check_columns=any(v==0 for v in columns)==False # Every link has a role? check_rows=[sum(x) for x in roles]==[1]*len(result.links) # Every link is in one position only self.assertTrue(check_columns and check_rows and check_total_links)
def test_unipartite_motif_weighted_structure(self): for i in range(0,2): result = pymfinder(self.test_filename_u[i], motifsize=i+2, networktype = "unipartite", nrandomizations=0, weighted=True, allmotifs=True) motifs=[int(result.motifs[n].mean_weight)==n for n in result.motifs.keys()] self.assertTrue(all(motifs))
def test_unipartite_motif_structure(self): for i in range(0,2): result = pymfinder(self.test_filename_u[i], motifsize=i+2, networktype = "unipartite", nrandomizations=0, allmotifs=True) motifs=[result.motifs[n].real for n in result.motifs] self.assertTrue(motifs==[1]*len(motifs))