{"id":22141235,"url":"https://github.com/hetio/xswap","last_synced_at":"2025-07-25T23:31:58.313Z","repository":{"id":62590234,"uuid":"160249904","full_name":"hetio/xswap","owner":"hetio","description":"Python library (C++ backend) for degree-preserving network randomization","archived":false,"fork":false,"pushed_at":"2019-10-14T19:39:40.000Z","size":1110,"stargazers_count":12,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-13T23:11:23.054Z","etag":null,"topics":["hetio","hetnets","networks","permutation","randomization"],"latest_commit_sha":null,"homepage":"https://hetio.github.io/xswap/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hetio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-03T20:30:53.000Z","updated_at":"2024-05-24T16:42:29.000Z","dependencies_parsed_at":"2022-11-03T17:56:53.666Z","dependency_job_id":null,"html_url":"https://github.com/hetio/xswap","commit_stats":null,"previous_names":["greenelab/xswap"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetio%2Fxswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetio%2Fxswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetio%2Fxswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetio%2Fxswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hetio","download_url":"https://codeload.github.com/hetio/xswap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227629031,"owners_count":17796054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hetio","hetnets","networks","permutation","randomization"],"created_at":"2024-12-01T21:11:36.178Z","updated_at":"2024-12-01T21:11:36.799Z","avatar_url":"https://github.com/hetio.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XSwap: Fast degree-preserving network permutation\n\n[![Linux Build Status](https://img.shields.io/travis/com/hetio/xswap/master.svg?logo=travis)](https://travis-ci.com/hetio/xswap)\n[![PyPI](https://img.shields.io/pypi/v/xswap.svg?logo=pypi\u0026logoColor=white)](https://pypi.org/project/xswap/)\n[![GitHub issues](https://img.shields.io/github/issues/hetio/xswap.svg?logo=github)](https://github.com/hetio/xswap/issues)\n\n**Full documentation:** \u003chttps://hetio.github.io/xswap/\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/hetio/xswap/master/docs/img/xswap.svg?sanitize=true\" width=\"250px\"\u003e\n\nXSwap is an algorithm for degree-preserving network randomization (permutation) [1].\nPermuted networks can be used for a number of purposes in network analysis, including for generating counterfactual distributions of features when only the network's degree sequence is maintained or for computing a prior probability of an edge given only the network's degree sequence.\nOverall, permuted networks allow one to quantify the effects of degree on analysis and prediction methods.\nUnderstanding this effect is useful when a network's degree sequence is subject to biases.\nThis implementation is a modified version of the algorithm due to Hanhijärvi et al. with two additional parameters (`allow_self_loops` and `allow_antiparallel`), which enable greater generalizability to bipartite, directed, and undirected networks.\n\n1. **Randomization Techniques for Graphs**  \nSami Hanhijärvi, Gemma C. Garriga, Kai Puolamäki  \n*Proceedings of the 2009 SIAM International Conference on Data Mining* (2009-04-30) \u003chttps://doi.org/f3mn58\u003e  \nDOI: [10.1137/1.9781611972795.67](https://doi.org/10.1137/1.9781611972795.67)\n\n## Usage examples\n\n#### Permuting an edge list\n\n```python\n\u003e\u003e\u003e edges = [(0, 1), (1, 0)]\n\u003e\u003e\u003e permuted_edges, permutation_statistics = xswap.permute_edge_list(\n        edges, allow_self_loops=True, allow_antiparallel=True,\n        multiplier=10)\n\u003e\u003e\u003e permuted_edges\n[(0, 0), (1, 1)]\n\u003e\u003e\u003e permutation_statistics\n{'swap_attempts': 20, 'same_edge': 10, 'self_loop': 0, 'duplicate': 1,\n 'undir_duplicate': 0, 'excluded': 0}\n```\n\n#### Computing degree-sequence based prior probabilities of edges existing\n\n```python\n\u003e\u003e\u003e edges = [(0, 1), (1, 0)]\n\u003e\u003e\u003e prior_prob_df = xswap.prior.compute_xswap_priors(\n        edges, n_permutations=10000, shape=(2, 2), allow_self_loops=True,\n        allow_antiparallel=True)\n\u003e\u003e\u003e prior_prob_df\n   source_id  target_id   edge  source_degree  target_degree  xswap_prior\n0          0          0  False              1              1          0.5\n1          0          1   True              1              1          0.5\n2          1          0   True              1              1          0.5\n3          1          1  False              1              1          0.5\n```\n\n## Choice of parameters\n\n#### Bipartite networks\n\nBipartite networks should be indexed using the bi-adjacency matrix, meaning that the edge `(0, 0)` is from source node 0 to target node 0, and is not a self-loop.\nMoreover, bipartite networks should be permuted using `allow_self_loops=False` and `allow_antiparallel=True`.\n\n#### Directed and undirected networks\n\nFor non-bipartite networks, the decisions of `allow_self_loops` and `allow_antiparallel` are not always the same.\nFor undirected networks, set `allow_antiparallel=False`, as otherwise the edges (1, 0) and (0, 1), which represent the same edge, will be treated as separate.\nAntiparallel edges may or may not be allowed for directed networks, depending on context.\nSimilarly, self-loops may or may not be allowed for directed or undirected networks, depending on the specific network being permuted.\n\n## Libraries\n\nThe XSwap library includes [Roaring Bitmaps](https://github.com/RoaringBitmap/CRoaring), available under the [Apache 2.0 license](https://github.com/RoaringBitmap/CRoaring/blob/LICENSE).\n\n## Acknowledgments\n\nDevelopment of this project has largely taken place in the [Greene Lab](http://www.greenelab.com/) at the University of Pennsylvania. As an open source project under the `hetio` organization, this repository is grateful for its community of maintainers, contributors, and users.\n\nThis work is funded in part by the Gordon and Betty Moore Foundation’s Data-Driven Discovery Initiative through Grants [GBMF4552](https://www.moore.org/grant-detail?grantId=GBMF4552) to Casey Greene, [GBMF4560](https://www.moore.org/grant-detail?grantId=GBMF4560) to Blair Sullivan, and the National Institutes of Health’s National Human Genome Research Institute [R01 HG010067](http://grantome.com/grant/NIH/R01-HG010067-02).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetio%2Fxswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhetio%2Fxswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetio%2Fxswap/lists"}