orthoxml-tools 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. orthoxml_tools-0.4.1/.github/workflows/publish.yml +37 -0
  2. orthoxml_tools-0.4.1/.github/workflows/test.yml +30 -0
  3. orthoxml_tools-0.4.1/.gitignore +175 -0
  4. orthoxml_tools-0.4.1/.python-version +1 -0
  5. orthoxml_tools-0.4.1/LEGACY-README.md +144 -0
  6. orthoxml_tools-0.4.1/LICENSE +674 -0
  7. orthoxml_tools-0.4.1/PKG-INFO +298 -0
  8. orthoxml_tools-0.4.1/README.md +284 -0
  9. orthoxml_tools-0.4.1/examples/README.md +5 -0
  10. orthoxml_tools-0.4.1/examples/data/FastOMA_v0.1.4_qfo2022_17Nov3.orthoxml.zip +0 -0
  11. orthoxml_tools-0.4.1/examples/data/OrthofinderOrthogroups.csv +428 -0
  12. orthoxml_tools-0.4.1/examples/data/ex1-int-taxon.orthoxml +42 -0
  13. orthoxml_tools-0.4.1/examples/data/ex1-ncbi-taxon.orthoxml +36 -0
  14. orthoxml_tools-0.4.1/examples/data/ex1.orthoxml +33 -0
  15. orthoxml_tools-0.4.1/examples/data/ex2-int-taxon.orthoxml +46 -0
  16. orthoxml_tools-0.4.1/examples/data/ex2-ncbi-taxon.orthoxml +40 -0
  17. orthoxml_tools-0.4.1/examples/data/ex2.orthoxml +37 -0
  18. orthoxml_tools-0.4.1/examples/data/ex3-int-taxon.orthoxml +48 -0
  19. orthoxml_tools-0.4.1/examples/data/ex3-ncbi-taxon.orthoxml +42 -0
  20. orthoxml_tools-0.4.1/examples/data/ex3.orthoxml +39 -0
  21. orthoxml_tools-0.4.1/examples/data/ex4-int-taxon-multiple-rhogs.orthoxml +71 -0
  22. orthoxml_tools-0.4.1/examples/data/ex4-int-taxon.orthoxml +63 -0
  23. orthoxml_tools-0.4.1/examples/data/ex4-ncbi-taxon.orthoxml +54 -0
  24. orthoxml_tools-0.4.1/examples/data/ex4.orthoxml +51 -0
  25. orthoxml_tools-0.4.1/examples/data/sample-for-filter.orthoxml +136 -0
  26. orthoxml_tools-0.4.1/examples/data/sample-for-og.orthoxml +167 -0
  27. orthoxml_tools-0.4.1/examples/data/sample.nhx +1 -0
  28. orthoxml_tools-0.4.1/examples/data/sample2.nhx +1 -0
  29. orthoxml_tools-0.4.1/pyproject.toml +29 -0
  30. orthoxml_tools-0.4.1/src/orthoxml/__init__.py +3 -0
  31. orthoxml_tools-0.4.1/src/orthoxml/__main__.py +6 -0
  32. orthoxml_tools-0.4.1/src/orthoxml/cli.py +313 -0
  33. orthoxml_tools-0.4.1/src/orthoxml/converters/__init__.py +1 -0
  34. orthoxml_tools-0.4.1/src/orthoxml/converters/from_nhx.py +251 -0
  35. orthoxml_tools-0.4.1/src/orthoxml/converters/from_orthofinder.py +102 -0
  36. orthoxml_tools-0.4.1/src/orthoxml/converters/to_nhx.py +169 -0
  37. orthoxml_tools-0.4.1/src/orthoxml/custom_parsers.py +356 -0
  38. orthoxml_tools-0.4.1/src/orthoxml/legacy/exceptions.py +4 -0
  39. orthoxml_tools-0.4.1/src/orthoxml/legacy/exporters.py +464 -0
  40. orthoxml_tools-0.4.1/src/orthoxml/legacy/loaders.py +168 -0
  41. orthoxml_tools-0.4.1/src/orthoxml/legacy/models.py +367 -0
  42. orthoxml_tools-0.4.1/src/orthoxml/legacy/tree.py +504 -0
  43. orthoxml_tools-0.4.1/src/orthoxml/logger.py +34 -0
  44. orthoxml_tools-0.4.1/src/orthoxml/parsers.py +190 -0
  45. orthoxml_tools-0.4.1/src/orthoxml/py.typed +0 -0
  46. orthoxml_tools-0.4.1/src/orthoxml/schemas/orthoxml-0.3.xsd +401 -0
  47. orthoxml_tools-0.4.1/src/orthoxml/schemas/orthoxml-0.4.xsd +403 -0
  48. orthoxml_tools-0.4.1/src/orthoxml/schemas/orthoxml-0.5.xsd +493 -0
  49. orthoxml_tools-0.4.1/src/orthoxml/streamfilters.py +237 -0
  50. orthoxml_tools-0.4.1/src/orthoxml/utils.py +78 -0
  51. orthoxml_tools-0.4.1/tests/test-data/case_filtering.orthoxml +136 -0
  52. orthoxml_tools-0.4.1/tests/test-data/labeled_gene_trees.nwk +1 -0
  53. orthoxml_tools-0.4.1/tests/test_cli.sh +107 -0
  54. orthoxml_tools-0.4.1/tests/test_convert.py +168 -0
  55. orthoxml_tools-0.4.1/tests/test_export.py +8 -0
  56. orthoxml_tools-0.4.1/tests/test_filtering.py +10 -0
  57. orthoxml_tools-0.4.1/tests/test_load.py +0 -0
  58. orthoxml_tools-0.4.1/tests/test_models.py +39 -0
  59. orthoxml_tools-0.4.1/tests/test_parsers.py +58 -0
@@ -0,0 +1,37 @@
1
+ # publish.yml
2
+
3
+ name: "Publish"
4
+
5
+ on:
6
+ push:
7
+ branches:
8
+ - main
9
+
10
+ jobs:
11
+ publish:
12
+ if: startsWith(github.event.head_commit.message, 'release:')
13
+ name: "Build and Publish"
14
+ runs-on: ubuntu-latest
15
+ permissions:
16
+ contents: write
17
+ id-token: write
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - name: Install uv
23
+ uses: astral-sh/setup-uv@v5
24
+
25
+ - name: Set up Python
26
+ uses: actions/setup-python@v5
27
+ with:
28
+ python-version-file: ".python-version"
29
+
30
+ - name: Build
31
+ run: uv build
32
+
33
+ - name: Publish to PyPI
34
+ uses: pypa/gh-action-pypi-publish@release/v1
35
+ with:
36
+ repository-url: https://upload.pypi.org/legacy/
37
+
@@ -0,0 +1,30 @@
1
+ name: "Test"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - develop
8
+
9
+ jobs:
10
+ test:
11
+ name: "Test on Python Versions"
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: |
26
+ pip install .
27
+ pip install '.[test]'
28
+
29
+ - name: Run tests
30
+ run: pytest -vv
@@ -0,0 +1,175 @@
1
+ # Customs
2
+
3
+ tests_output/
4
+
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ # For a library or package, you might want to ignore these files since the code is
91
+ # intended to run in multiple environments; otherwise, check them in:
92
+ # .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # UV
102
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
103
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
104
+ # commonly ignored for libraries.
105
+ #uv.lock
106
+
107
+ # poetry
108
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
109
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
110
+ # commonly ignored for libraries.
111
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
112
+ #poetry.lock
113
+
114
+ # pdm
115
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
116
+ #pdm.lock
117
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
118
+ # in version control.
119
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
120
+ .pdm.toml
121
+ .pdm-python
122
+ .pdm-build/
123
+
124
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
125
+ __pypackages__/
126
+
127
+ # Celery stuff
128
+ celerybeat-schedule
129
+ celerybeat.pid
130
+
131
+ # SageMath parsed files
132
+ *.sage.py
133
+
134
+ # Environments
135
+ .env
136
+ .venv
137
+ env/
138
+ venv/
139
+ ENV/
140
+ env.bak/
141
+ venv.bak/
142
+
143
+ # Spyder project settings
144
+ .spyderproject
145
+ .spyproject
146
+
147
+ # Rope project settings
148
+ .ropeproject
149
+
150
+ # mkdocs documentation
151
+ /site
152
+
153
+ # mypy
154
+ .mypy_cache/
155
+ .dmypy.json
156
+ dmypy.json
157
+
158
+ # Pyre type checker
159
+ .pyre/
160
+
161
+ # pytype static type analyzer
162
+ .pytype/
163
+
164
+ # Cython debug symbols
165
+ cython_debug/
166
+
167
+ # PyCharm
168
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
169
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
170
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
171
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
172
+ #.idea/
173
+
174
+ # PyPI configuration file
175
+ .pypirc
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,144 @@
1
+ The `orthoxml-tools` package used to provides a object oriented interface for working with OrthoXML files. This API is deprecated and will be removed in v1.0.0. Please use the new streaming CLI method. the rationale behind this migration mainly comes from memory usage consideration.
2
+
3
+ # Legacy API Usage
4
+
5
+ ```python
6
+ >>> from orthoxml import OrthoXMLTree
7
+ >>> otree = OrthoXMLTree.from_file("data/sample.orthoxml", validate=True)
8
+ >>> otree
9
+ 2025-02-11 11:43:17 - loaders - INFO - OrthoXML file is valid for version 0.5
10
+ OrthoXMLTree(genes=[5 genes], species=[3 species], groups=[0 groups], taxonomy=[0 taxons], orthoxml_version=0.5)
11
+ ```
12
+
13
+ ### Filter Based on CompletenessScore at Loading
14
+ ```python
15
+ >>> from orthoxml import OrthoXMLTree
16
+ >>> otree = OrthoXMLTree.from_file("data/sample.orthoxml", CompletenessScore_threshold=0.95, validate=True)
17
+ >>> otree
18
+ 2025-02-11 11:43:17 - loaders - INFO - OrthoXML file is valid for version 0.5
19
+ OrthoXMLTree(genes=[5 genes], species=[3 species], groups=[0 groups], taxonomy=[0 taxons], orthoxml_version=0.5)
20
+ ```
21
+
22
+ ### Accessing Specific Data
23
+
24
+ * **Groups**
25
+
26
+ ```python
27
+ >>> otree.groups
28
+ OrthologGroup(taxonId=5, geneRefs=['5'], orthologGroups=[OrthologGroup(taxonId=4, geneRefs=['4'], orthologGroups=[], paralogGroups=[ParalogGroup(taxonId=None, geneRefs=['1', '2', '3'], orthologGroups=[], paralogGroups=[])])], paralogGroups=[])
29
+ ```
30
+
31
+ * **Genes**
32
+
33
+ ```python
34
+ >>> otree.genes
35
+ defaultdict(orthoxml.models.Gene,
36
+ {'1': Gene(id=1, geneId=hsa1, protId=None),
37
+ '2': Gene(id=2, geneId=hsa2, protId=None),
38
+ '3': Gene(id=3, geneId=hsa3, protId=None),
39
+ '4': Gene(id=4, geneId=ptr1, protId=None),
40
+ '5': Gene(id=5, geneId=mmu1, protId=None)})
41
+ ```
42
+
43
+ * **Taxonomy**
44
+
45
+ ```python
46
+ >>> otree.taxonomy
47
+ Taxon(id=5, name=Root, children=[Taxon(id=3, name=Mus musculus, children=[]), Taxon(id=4, name=Primates, children=[Taxon(id=1, name=Homo sapiens, children=[]), Taxon(id=2, name=Pan troglodytes, children=[])])])
48
+ ```
49
+
50
+ For a more human-readable tree structure:
51
+
52
+ ```python
53
+ >>> print(otree.taxonomy.to_str())
54
+ Root
55
+ ├── Mus musculus
56
+ └── Primates
57
+ ├── Homo sapiens
58
+ └── Pan troglodytes
59
+ ```
60
+
61
+ * **Species**
62
+
63
+ ```python
64
+ >>> otree.species
65
+ [Species(name=Homo sapiens, NCBITaxId=9606, genes=[Gene(id=1, geneId=hsa1), Gene(id=2, geneId=hsa2), Gene(id=3, geneId=hsa3)]),
66
+ Species(name=Pan troglodytes, NCBITaxId=9598, genes=[Gene(id=4, geneId=ptr1)]),
67
+ Species(name=Mus musculus, NCBITaxId=10090, genes=[Gene(id=5, geneId=mmu1)])]
68
+ ```
69
+
70
+ ### Statistics of the OrthoXML tree
71
+
72
+ * **Basic Stats**
73
+ ```python
74
+ >>> otree.base_stats()
75
+ {'genes': 10,
76
+ 'species': 3,
77
+ 'groups': 3,
78
+ 'taxonomy': 0,
79
+ 'orthoxml_version': '0.5'}
80
+ ```
81
+
82
+ * **Gene Number per Taxonomic Level Stats**
83
+ ```python
84
+ >>> otree.gene_stats()
85
+ {'5': 4, '3': 3, '4': 3, '2': 6, '1': 10}
86
+ >>> otree.gene_stats(filepath="out.csv", sep=",") # to also writes the stats to file with two columns: taxonId and gene_count
87
+ {'5': 4, '3': 3, '4': 3, '2': 6, '1': 10}
88
+ ```
89
+
90
+ ### Manipulate the Tree
91
+
92
+ * **Split an instance of OrthoXML Tree to separate OrthoXML Trees based on rootHOGs**
93
+ ```python
94
+ >>> otrees = otree.split_by_rootHOGs()
95
+ >>> otrees[0].groups
96
+ OrthologGroup(taxonId=1, geneRefs=['1000000002'], orthologGroups=[OrthologGroup(taxonId=2, geneRefs=['1001000001', '1002000001'], orthologGroups=[], paralogGroups=[])], paralogGroups=[])
97
+ ```
98
+
99
+ ### Export Options
100
+
101
+ * **Orthologous Pairs**
102
+
103
+ ```python
104
+ >>> otree.to_ortho_pairs()
105
+ [('1', '2'), ('1', '3')]
106
+ >>> otree.to_ortho_pairs(filepath="out.csv") # to also writes the pairs to file
107
+ [('1', '2'), ('1', '3')]
108
+ ```
109
+
110
+ * **Get Orthologous Pairs of an Specific Gene**
111
+
112
+ ```python
113
+ >>> otree.to_ortho_pairs_of_gene("1001000001")
114
+ [('1001000001', '1002000001'), ('1000000002', '1001000001')]
115
+ >>> otree.to_ortho_pairs_of_gene("1001000001", filepath="out.csv") # to also writes the pairs to file
116
+ [('1001000001', '1002000001'), ('1000000002', '1001000001')]
117
+ ```
118
+
119
+ * **Orthologous Groups**
120
+
121
+ ```python
122
+ >>> otree.to_ogs()
123
+ [['1000000002', '1001000001', '1002000001'],
124
+ ['1000000003', '1001000002', '1002000002'],
125
+ ['1000000004', '1001000003', '1002000003']]
126
+ >>> otree.to_ogs(filepath="out.csv") # to also writes the groups to file
127
+ [['1000000002', '1001000001', '1002000001'],
128
+ ['1000000003', '1001000002', '1002000002'],
129
+ ['1000000004', '1001000003', '1002000003']]
130
+ ```
131
+
132
+ ### Export Options
133
+
134
+ * **Export Back Manipulated Tree to OrthoXML**
135
+
136
+ ```python
137
+ >>> otree.to_orthoxml()
138
+ <?xml version='1.0' encoding='utf-8'?>
139
+ <orthoXML xmlns="http://orthoXML.org/2011/" version="0.5" origin="orthoXML.org" originVersion="1.0">
140
+ <species name="Homo sapiens" NCBITaxId="9606">
141
+ ...
142
+ </groups>
143
+ </orthoXML>
144
+ ```