guohanghui commited on
Commit
8bf20e6
·
verified ·
1 Parent(s): 0c3ca23

Upload 225 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +18 -0
  3. README.md +26 -4
  4. app.py +45 -0
  5. pybedtools/mcp_output/README_MCP.md +65 -0
  6. pybedtools/mcp_output/analysis.json +289 -0
  7. pybedtools/mcp_output/diff_report.md +70 -0
  8. pybedtools/mcp_output/mcp_plugin/__init__.py +0 -0
  9. pybedtools/mcp_output/mcp_plugin/adapter.py +99 -0
  10. pybedtools/mcp_output/mcp_plugin/main.py +13 -0
  11. pybedtools/mcp_output/mcp_plugin/mcp_service.py +72 -0
  12. pybedtools/mcp_output/requirements.txt +8 -0
  13. pybedtools/mcp_output/start_mcp.py +30 -0
  14. pybedtools/mcp_output/workflow_summary.json +196 -0
  15. pybedtools/source/LICENSE.txt +22 -0
  16. pybedtools/source/MANIFEST.in +12 -0
  17. pybedtools/source/README.rst +74 -0
  18. pybedtools/source/__init__.py +4 -0
  19. pybedtools/source/build-docs.sh +27 -0
  20. pybedtools/source/dev-requirements.txt +7 -0
  21. pybedtools/source/docker/full-test.sh +12 -0
  22. pybedtools/source/docker/harness.sh +23 -0
  23. pybedtools/source/docker/pbt-test-py2/Dockerfile +41 -0
  24. pybedtools/source/docker/pbt-test-py3/Dockerfile +41 -0
  25. pybedtools/source/docs/Makefile +139 -0
  26. pybedtools/source/docs/README.rst +2 -0
  27. pybedtools/source/docs/make.bat +155 -0
  28. pybedtools/source/docs/source/3-brief-examples.rst +90 -0
  29. pybedtools/source/docs/source/FAQs.rst +195 -0
  30. pybedtools/source/docs/source/_static/custom.css +3 -0
  31. pybedtools/source/docs/source/_templates/layout.html +6 -0
  32. pybedtools/source/docs/source/autodoc_source.rst +360 -0
  33. pybedtools/source/docs/source/autodocs/pybedtools.contrib.plotting.Track.rst +166 -0
  34. pybedtools/source/docs/source/changes.rst +880 -0
  35. pybedtools/source/docs/source/conf.py +237 -0
  36. pybedtools/source/docs/source/create-a-bedtool-tutorial.rst +39 -0
  37. pybedtools/source/docs/source/default-arguments.rst +81 -0
  38. pybedtools/source/docs/source/each.rst +66 -0
  39. pybedtools/source/docs/source/example-script +107 -0
  40. pybedtools/source/docs/source/example-script-nocomments +37 -0
  41. pybedtools/source/docs/source/example_3 +109 -0
  42. pybedtools/source/docs/source/example_3_no_comments +49 -0
  43. pybedtools/source/docs/source/filtering.rst +93 -0
  44. pybedtools/source/docs/source/flow-of-commands.rst +120 -0
  45. pybedtools/source/docs/source/history.rst +141 -0
  46. pybedtools/source/docs/source/images/downloads.png +0 -0
  47. pybedtools/source/docs/source/images/gchart.png +0 -0
  48. pybedtools/source/docs/source/images/mpl.png +0 -0
  49. pybedtools/source/docs/source/includeme.rst +50 -0
  50. pybedtools/source/docs/source/index.rst +68 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ pybedtools/source/pybedtools/test/data/x.bam filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ RUN useradd -m -u 1000 user && python -m pip install --upgrade pip
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ ENV MCP_TRANSPORT=http
14
+ ENV MCP_PORT=7860
15
+
16
+ EXPOSE 7860
17
+
18
+ CMD ["python", "pybedtools/mcp_output/start_mcp.py"]
README.md CHANGED
@@ -1,10 +1,32 @@
1
  ---
2
- title: Pybedtools
3
- emoji: 🌍
4
- colorFrom: red
5
  colorTo: purple
6
  sdk: docker
 
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Pybedtools MCP
3
+ emoji: 🤖
4
+ colorFrom: blue
5
  colorTo: purple
6
  sdk: docker
7
+ sdk_version: "4.26.0"
8
+ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # Pybedtools MCP Service
13
+
14
+ Auto-generated MCP service for pybedtools.
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ https://None-pybedtools-mcp.hf.space/mcp
20
+ ```
21
+
22
+ ## Connect with Cursor
23
+
24
+ ```json
25
+ {
26
+ "mcpServers": {
27
+ "pybedtools": {
28
+ "url": "https://None-pybedtools-mcp.hf.space/mcp"
29
+ }
30
+ }
31
+ }
32
+ ```
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import os
3
+ import sys
4
+
5
+ mcp_plugin_path = os.path.join(os.path.dirname(__file__), "pybedtools", "mcp_output", "mcp_plugin")
6
+ sys.path.insert(0, mcp_plugin_path)
7
+
8
+ app = FastAPI(
9
+ title="Pybedtools MCP Service",
10
+ description="Auto-generated MCP service for pybedtools",
11
+ version="1.0.0"
12
+ )
13
+
14
+ @app.get("/")
15
+ def root():
16
+ return {
17
+ "service": "Pybedtools MCP Service",
18
+ "version": "1.0.0",
19
+ "status": "running",
20
+ "transport": os.environ.get("MCP_TRANSPORT", "http")
21
+ }
22
+
23
+ @app.get("/health")
24
+ def health_check():
25
+ return {"status": "healthy", "service": "pybedtools MCP"}
26
+
27
+ @app.get("/tools")
28
+ def list_tools():
29
+ try:
30
+ from mcp_service import create_app
31
+ mcp_app = create_app()
32
+ tools = []
33
+ for tool_name, tool_func in mcp_app.tools.items():
34
+ tools.append({
35
+ "name": tool_name,
36
+ "description": tool_func.__doc__ or "No description available"
37
+ })
38
+ return {"tools": tools}
39
+ except Exception as e:
40
+ return {"error": f"Failed to load tools: {str(e)}"}
41
+
42
+ if __name__ == "__main__":
43
+ import uvicorn
44
+ port = int(os.environ.get("PORT", 7860))
45
+ uvicorn.run(app, host="0.0.0.0", port=port)
pybedtools/mcp_output/README_MCP.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pybedtools MCP (Model Context Protocol) Service
2
+
3
+ ## Project Introduction
4
+
5
+ The `pybedtools` MCP service is a Python library that wraps and extends the BEDTools suite of programs for genomic interval manipulation, commonly referred to as "genome algebra." This service provides a Pythonic interface to BEDTools functionality while adding advanced features for genomic data analysis, visualization, and statistical operations. It is designed to facilitate the handling of genomic intervals and interactions, making it an essential tool for bioinformatics and computational biology.
6
+
7
+ ## Installation Method
8
+
9
+ To install `pybedtools`, ensure you have Python installed on your system. The following dependencies are required:
10
+
11
+ - numpy
12
+ - matplotlib
13
+ - pandas
14
+
15
+ Optional dependencies include:
16
+
17
+ - scipy
18
+
19
+ You can install `pybedtools` and its dependencies using pip:
20
+
21
+ ```
22
+ pip install pybedtools
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ Here's a quick example to get you started with `pybedtools`:
28
+
29
+ 1. Import the `BedTool` class from the `pybedtools` package.
30
+ 2. Create a `BedTool` object from a BED file.
31
+ 3. Perform operations such as intersections or merges.
32
+
33
+ Example:
34
+
35
+ ```
36
+ from pybedtools import BedTool
37
+
38
+ # Create a BedTool object
39
+ a = BedTool('a.bed')
40
+ b = BedTool('b.bed')
41
+
42
+ # Perform an intersection
43
+ intersected = a.intersect(b)
44
+
45
+ # Save the result
46
+ intersected.saveas('intersected.bed')
47
+ ```
48
+
49
+ ## Available Tools and Endpoints List
50
+
51
+ - **BedTool**: Core class for handling BEDTools operations and interactions with genomic intervals.
52
+ - **annotate**: Annotates BED files with additional information.
53
+ - **intersection_matrix**: Generates a matrix of intersections between multiple BED files.
54
+ - **plot_venn**: Provides functions for plotting genomic data using matplotlib.
55
+ - **get_genome**: Handles genome data registration and retrieval.
56
+
57
+ ## Common Issues and Notes
58
+
59
+ - Ensure all dependencies are correctly installed to avoid import errors.
60
+ - The service may require significant computational resources for large datasets, so performance can vary based on the environment.
61
+ - Temporary files are managed automatically, but users can control cleanup through the `KEEP_TEMPFILES` setting.
62
+
63
+ ## Reference Links or Documentation
64
+
65
+ For more detailed information, visit the [pybedtools GitHub repository](https://github.com/daler/pybedtools) and explore the documentation provided in the `docs` directory. This includes API documentation, examples, and tutorials to help you make the most of the `pybedtools` MCP service.
pybedtools/mcp_output/analysis.json ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "summary": {
3
+ "repository_url": "https://github.com/daler/pybedtools",
4
+ "summary": "Imported via zip fallback, file count: 57",
5
+ "file_tree": {
6
+ ".github/workflows/main.yml": {
7
+ "size": 5440
8
+ },
9
+ "LICENSE.txt": {
10
+ "size": 1116
11
+ },
12
+ "dev-requirements.txt": {
13
+ "size": 54
14
+ },
15
+ "docs/source/conf.py": {
16
+ "size": 7662
17
+ },
18
+ "ez_setup.py": {
19
+ "size": 11434
20
+ },
21
+ "optional-requirements.txt": {
22
+ "size": 95
23
+ },
24
+ "pybedtools/__init__.py": {
25
+ "size": 3921
26
+ },
27
+ "pybedtools/bedtool.py": {
28
+ "size": 139170
29
+ },
30
+ "pybedtools/contrib/__init__.py": {
31
+ "size": 156
32
+ },
33
+ "pybedtools/contrib/bigbed.py": {
34
+ "size": 2249
35
+ },
36
+ "pybedtools/contrib/bigwig.py": {
37
+ "size": 6128
38
+ },
39
+ "pybedtools/contrib/intersection_matrix.py": {
40
+ "size": 7563
41
+ },
42
+ "pybedtools/contrib/long_range_interaction.py": {
43
+ "size": 16547
44
+ },
45
+ "pybedtools/contrib/plotting.py": {
46
+ "size": 19765
47
+ },
48
+ "pybedtools/contrib/venn_maker.py": {
49
+ "size": 7611
50
+ },
51
+ "pybedtools/filenames.py": {
52
+ "size": 1291
53
+ },
54
+ "pybedtools/genome_registry.py": {
55
+ "size": 112873
56
+ },
57
+ "pybedtools/helpers.py": {
58
+ "size": 26279
59
+ },
60
+ "pybedtools/logger.py": {
61
+ "size": 325
62
+ },
63
+ "pybedtools/parallel.py": {
64
+ "size": 7803
65
+ },
66
+ "pybedtools/paths.py": {
67
+ "size": 569
68
+ },
69
+ "pybedtools/scripts/annotate.py": {
70
+ "size": 4800
71
+ },
72
+ "pybedtools/scripts/examples/pbt_plotting_example.py": {
73
+ "size": 3215
74
+ },
75
+ "pybedtools/scripts/intersection_matrix.py": {
76
+ "size": 5025
77
+ },
78
+ "pybedtools/scripts/intron_exon_reads.py": {
79
+ "size": 3605
80
+ },
81
+ "pybedtools/scripts/peak_pie.py": {
82
+ "size": 5411
83
+ },
84
+ "pybedtools/scripts/py_ms_example.py": {
85
+ "size": 722
86
+ },
87
+ "pybedtools/scripts/venn_gchart.py": {
88
+ "size": 4309
89
+ },
90
+ "pybedtools/scripts/venn_mpl.py": {
91
+ "size": 5556
92
+ },
93
+ "pybedtools/settings.py": {
94
+ "size": 2394
95
+ },
96
+ "pybedtools/stats.py": {
97
+ "size": 818
98
+ },
99
+ "pybedtools/test/__init__.py": {
100
+ "size": 417
101
+ },
102
+ "pybedtools/test/data/__init__.py": {
103
+ "size": 0
104
+ },
105
+ "pybedtools/test/data/democonfig.yaml": {
106
+ "size": 1398
107
+ },
108
+ "pybedtools/test/genomepy_integration.py": {
109
+ "size": 1525
110
+ },
111
+ "pybedtools/test/regression_tests.py": {
112
+ "size": 997
113
+ },
114
+ "pybedtools/test/test_1.py": {
115
+ "size": 54763
116
+ },
117
+ "pybedtools/test/test_cases.yaml": {
118
+ "size": 20408
119
+ },
120
+ "pybedtools/test/test_cbedtools.py": {
121
+ "size": 12668
122
+ },
123
+ "pybedtools/test/test_contrib.py": {
124
+ "size": 6055
125
+ },
126
+ "pybedtools/test/test_gzip_support.py": {
127
+ "size": 3729
128
+ },
129
+ "pybedtools/test/test_helpers.py": {
130
+ "size": 5992
131
+ },
132
+ "pybedtools/test/test_issues.py": {
133
+ "size": 28719
134
+ },
135
+ "pybedtools/test/test_iter.py": {
136
+ "size": 7316
137
+ },
138
+ "pybedtools/test/test_len_leak.py": {
139
+ "size": 1422
140
+ },
141
+ "pybedtools/test/test_merge215.yaml": {
142
+ "size": 623
143
+ },
144
+ "pybedtools/test/test_merge227.yaml": {
145
+ "size": 584
146
+ },
147
+ "pybedtools/test/test_pathlib.py": {
148
+ "size": 1201
149
+ },
150
+ "pybedtools/test/test_shuffle215.yaml": {
151
+ "size": 19015
152
+ },
153
+ "pybedtools/test/test_shuffle227.yaml": {
154
+ "size": 711
155
+ },
156
+ "pybedtools/test/tfuncs.py": {
157
+ "size": 183
158
+ },
159
+ "pybedtools/version.py": {
160
+ "size": 80
161
+ },
162
+ "pyproject.toml": {
163
+ "size": 399
164
+ },
165
+ "requirements.txt": {
166
+ "size": 19
167
+ },
168
+ "setup.cfg": {
169
+ "size": 76
170
+ },
171
+ "setup.py": {
172
+ "size": 9710
173
+ },
174
+ "test-requirements.txt": {
175
+ "size": 45
176
+ }
177
+ },
178
+ "processed_by": "zip_fallback",
179
+ "success": true
180
+ },
181
+ "structure": {
182
+ "packages": [
183
+ "source.pybedtools",
184
+ "source.pybedtools.contrib",
185
+ "source.pybedtools.test"
186
+ ]
187
+ },
188
+ "dependencies": {
189
+ "has_environment_yml": false,
190
+ "has_requirements_txt": true,
191
+ "pyproject": true,
192
+ "setup_cfg": true,
193
+ "setup_py": true
194
+ },
195
+ "entry_points": {
196
+ "imports": [],
197
+ "cli": [],
198
+ "modules": []
199
+ },
200
+ "llm_analysis": {
201
+ "core_modules": [
202
+ {
203
+ "package": "source.pybedtools",
204
+ "module": "bedtool",
205
+ "functions": [
206
+ "BedTool",
207
+ "create_interval_from_list",
208
+ "set_bedtools_path"
209
+ ],
210
+ "classes": [
211
+ "BedTool",
212
+ "Interval"
213
+ ],
214
+ "description": "Core module for handling BEDTools operations and interactions with genomic intervals."
215
+ },
216
+ {
217
+ "package": "source.pybedtools.contrib",
218
+ "module": "plotting",
219
+ "functions": [
220
+ "plot_venn",
221
+ "plot_histogram"
222
+ ],
223
+ "classes": [],
224
+ "description": "Provides functions for plotting genomic data using matplotlib."
225
+ },
226
+ {
227
+ "package": "source.pybedtools",
228
+ "module": "genome_registry",
229
+ "functions": [
230
+ "get_genome",
231
+ "list_genomes"
232
+ ],
233
+ "classes": [
234
+ "Genome"
235
+ ],
236
+ "description": "Handles genome data registration and retrieval."
237
+ }
238
+ ],
239
+ "cli_commands": [
240
+ {
241
+ "name": "annotate",
242
+ "module": "source.pybedtools.scripts.annotate",
243
+ "description": "Annotates BED files with additional information."
244
+ },
245
+ {
246
+ "name": "intersection_matrix",
247
+ "module": "source.pybedtools.scripts.intersection_matrix",
248
+ "description": "Generates a matrix of intersections between multiple BED files."
249
+ }
250
+ ],
251
+ "import_strategy": {
252
+ "primary": "import",
253
+ "fallback": "cli",
254
+ "confidence": 0.85
255
+ },
256
+ "dependencies": {
257
+ "required": [
258
+ "numpy",
259
+ "matplotlib",
260
+ "pandas"
261
+ ],
262
+ "optional": [
263
+ "scipy"
264
+ ]
265
+ },
266
+ "risk_assessment": {
267
+ "import_feasibility": 0.8,
268
+ "intrusiveness_risk": "medium",
269
+ "complexity": "medium"
270
+ }
271
+ },
272
+ "deepwiki_analysis": {
273
+ "repo_url": "https://github.com/daler/pybedtools",
274
+ "repo_name": "pybedtools",
275
+ "content": "daler/pybedtools\nCore Architecture\nBedTool Class\nInterval and IntervalFile\nHelper Functions and Utilities\nOperations and File Handling\nBEDTools Method Wrappers\nFeature Manipulation Functions\nFile Format Support\nExtended Functionality\nContrib Module\nCommand-line Scripts\nParallel Processing and Statistical Analysis\nDevelopment and Testing\nBuild System and Packaging\nTesting Framework\nCI/CD Pipeline\nDocumentation and Configuration\nAPI Documentation System\nGenome Registry and Configuration\nExamples and Tutorials\ndocs/source/autodoc_source.rst\ndocs/source/index.rst\ndocs/source/main.rst\npybedtools/__init__.py\npybedtools/bedtool.py\npybedtools/helpers.py\npybedtools/settings.py\npybedtools/stats.py\nPurpose and Scope\npybedtoolsis a Python library that wraps and extends the BEDTools suite of programs for genomic interval manipulation, commonly referred to as \"genome algebra.\" This library provides a Pythonic interface to BEDTools functionality while adding advanced features for genomic data analysis, visualization, and statistical operations.\nThis document provides a high-level overview of the entire pybedtools system architecture, core components, and data flow patterns. For detailed information about specific subsystems, see the Core Architecture (2), Operations and File Handling (3), Extended Functionality (4), and Development Infrastructure (5) sections.\nSystem Architecture Overview\nBuild & DistributionExtended FunctionalityExternal Tools IntegrationCore Processing LayerPython Interface LayerBedToolBedTool Methodsintersect(), merge(), etc.HistoryIntervalIntervalFileIntervalIterator_wraps DecoratorBEDTools ProgramsintersectBed, mergeBed, etc.subprocess.PopenTemporary Filescontrib ModuleCommand-line ScriptsStatistical FunctionsVisualization ToolsCython Compilation.pyx to .cppsetup.pyTest Framework\nBuild & Distribution\nExtended Functionality\nExternal Tools Integration\nCore Processing Layer\nPython Interface Layer\nBedTool Methodsintersect(), merge(), etc.\nIntervalFile\nIntervalIterator\n_wraps Decorator\nBEDTools ProgramsintersectBed, mergeBed, etc.\nsubprocess.Popen\nTemporary Files\ncontrib Module\nCommand-line Scripts\nStatistical Functions\nVisualization Tools\nCython Compilation.pyx to .cpp\nTest Framework\nSources:pybedtools/bedtool.py478-637pybedtools/cbedtools.pypybedtools/helpers.py314-488setup.py\nCore Components\nPrimary Interface Classes\nThe system is built around several key classes that provide different levels of abstraction:\nIntervalFile\nIntervalIterator\nMethod Wrapping System\nThe_wrapsdecorator atpybedtools/bedtool.py103-439provides the foundation for integrating BEDTools programs as Python methods. This decorator handles:\nAutomatic argument processing and validation\nGenome file management\nInput/output format detection (BAM vs BED)\nCommand-line argument construction\nProcess execution viasubprocess.Popen\nsubprocess.Popen\nSources:pybedtools/bedtool.py103-439pybedtools/helpers.py314-488\nData Flow Architecture\nOutput ProcessingBEDTools ExecutionCore Processing PipelineBedTool CreationInput SourcesGenomic FilesBED/GFF/BAM/VCFString Datapandas DataFramesPython IterablesBedTool.init()from_string=Truefrom_dataframe()IntervalFileFile parsingInterval Objects0-based coordinatesBedTool Methodswrapped BEDTools opsMethod ChainingFluent APIhandle_kwargs()call_bedtools()subprocess.PopenBEDTools ProgramsStreaming ResultsFile-based ResultsTemporary FileManagement\nOutput Processing\nBEDTools Execution\nCore Processing Pipeline\nBedTool Creation\nInput Sources\nGenomic FilesBED/GFF/BAM/VCF\nString Data\npandas DataFrames\nPython Iterables\nBedTool.init()\nfrom_string=True\nfrom_dataframe()\nIntervalFileFile parsing\nInterval Objects0-based coordinates\nBedTool Methodswrapped BEDTools ops\nMethod ChainingFluent API\nhandle_kwargs()\ncall_bedtools()\nsubprocess.Popen\nBEDTools Programs\nStreaming Results\nFile-based Results\nTemporary FileManagement\nSources:pybedtools/bedtool.py481-637pybedtools/bedtool.py638-679pybedtools/helpers.py314-488pybedtools/bedtool.py283-422\nKey Subsystems\nBEDTools Program Registry\nThe system maintains registries to map old BEDTools program names to new unified command names:\n_implicit_registry: Maps programs to their implicit input arguments\n_implicit_registry\n_other_registry: Maps programs to secondary input arguments\n_other_registry\n_bam_registry: Maps programs to BAM-specific input arguments\n_bam_registry\n_prog_names: Maps old program names to new bedtools subcommands\n_prog_names\nThese registries are populated by the_wrapsdecorator and accessed during runtime command construction.\nSources:pybedtools/bedtool.py52-55pybedtools/settings.py21-76pybedtools/bedtool.py236-243\nFile Type Detection and Handling\nThe system automatically detects and handles multiple genomic file formats:\nFile type detection influences output format decisions and determines which BEDTools programs can accept the input.\nSources:pybedtools/helpers.py168-225pybedtools/bedtool.py361-390\nTemporary File Management\nThe system uses a sophisticated temporary file management system:\nGlobalTEMPFILESregistry inpybedtools/filenames.py\nAutomatic cleanup viaatexit.register(cleanup)atpybedtools/helpers.py909\natexit.register(cleanup)\nPer-BedTool temporary file creation via_tmp()method\nUser-controllable cleanup throughKEEP_TEMPFILESsetting\nKEEP_TEMPFILES\nSources:pybedtools/filenames.pypybedtools/helpers.py278-298pybedtools/bedtool.py479pybedtools/helpers.py909\nHistory and Reproducibility\nEachBedToolobject maintains a history of operations through theHistoryclass, enabling:\nMethod call tracking with arguments\nReproducible analysis pipelines\nDebugging and introspection capabilities\nTemporary file lifecycle management\nThe_log_to_historydecorator atpybedtools/bedtool.py442-475automatically captures method calls and their parameters.\n_log_to_history\nSources:pybedtools/bedtool.py442-475pybedtools/bedtool.py636\nRefresh this wiki\nOn this page\nPurpose and Scope\nSystem Architecture Overview\nCore Components\nPrimary Interface Classes\nMethod Wrapping System\nData Flow Architecture\nKey Subsystems\nBEDTools Program Registry\nFile Type Detection and Handling\nTemporary File Management\nHistory and Reproducibility",
276
+ "model": "gpt-4o-2024-08-06",
277
+ "source": "selenium",
278
+ "success": true
279
+ },
280
+ "deepwiki_options": {
281
+ "enabled": true,
282
+ "model": "gpt-4o-2024-08-06"
283
+ },
284
+ "risk": {
285
+ "import_feasibility": 0.8,
286
+ "intrusiveness_risk": "medium",
287
+ "complexity": "medium"
288
+ }
289
+ }
pybedtools/mcp_output/diff_report.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pybedtools Project Difference Report
2
+
3
+ ## Project Overview
4
+
5
+ **Repository:** pybedtools
6
+ **Project Type:** Python library
7
+ **Main Features:** Provides a Python interface to the BEDTools suite, enabling manipulation and analysis of genomic intervals.
8
+ **Current Status (as of 2026-01-31):**
9
+ - **Workflow Status:** Success
10
+ - **Test Status:** Failed
11
+
12
+ ## Difference Analysis
13
+
14
+ ### Summary of Changes
15
+ - **New Files Added:** 8
16
+ - **Modified Files:** 0
17
+
18
+ ### Intrusiveness
19
+ - **Intrusiveness Level:** None
20
+ The recent changes have not altered existing files, indicating that the new additions are likely supplementary rather than modifications to core functionalities.
21
+
22
+ ## Technical Analysis
23
+
24
+ ### New Files
25
+ The addition of 8 new files suggests an expansion of the library's capabilities or the introduction of new features. However, without modifications to existing files, these changes are likely isolated and should not disrupt current functionalities.
26
+
27
+ ### Test Failures
28
+ The failure in the test status indicates that the new additions may not be fully integrated or that there are issues with the new functionalities. This could be due to:
29
+ - Incomplete or incorrect implementation of new features.
30
+ - Lack of comprehensive test coverage for the new files.
31
+ - Potential conflicts or dependencies that were not addressed.
32
+
33
+ ## Recommendations and Improvements
34
+
35
+ 1. **Review New Additions:**
36
+ - Conduct a thorough review of the new files to ensure they align with the project's goals and coding standards.
37
+ - Verify that the new functionalities are correctly implemented and documented.
38
+
39
+ 2. **Enhance Testing:**
40
+ - Develop comprehensive test cases for the new files to ensure they function as expected.
41
+ - Investigate the cause of test failures and address any issues identified.
42
+
43
+ 3. **Integration and Compatibility:**
44
+ - Ensure that the new additions are compatible with existing functionalities.
45
+ - Consider potential impacts on users and provide clear documentation on how to use new features.
46
+
47
+ 4. **Documentation:**
48
+ - Update the project's documentation to include information about the new features and any changes in usage.
49
+
50
+ ## Deployment Information
51
+
52
+ - **Current Deployment Status:** Not specified
53
+ - **Recommendations for Deployment:**
54
+ - Hold off on deploying the new version until test failures are resolved.
55
+ - Once resolved, conduct a staged deployment to monitor the impact of changes.
56
+
57
+ ## Future Planning
58
+
59
+ 1. **Roadmap Development:**
60
+ - Define a clear roadmap for future developments, focusing on enhancing existing features and expanding the library's capabilities.
61
+
62
+ 2. **Community Engagement:**
63
+ - Engage with the user community to gather feedback on the new features and identify areas for improvement.
64
+
65
+ 3. **Continuous Integration:**
66
+ - Implement continuous integration practices to ensure that future changes are automatically tested and validated.
67
+
68
+ ## Conclusion
69
+
70
+ The recent changes to the pybedtools project indicate an expansion of its capabilities with the addition of new files. However, the failure in test status highlights the need for further refinement and testing. By addressing these issues and enhancing documentation and testing, the project can ensure a stable and robust release in the future.
pybedtools/mcp_output/mcp_plugin/__init__.py ADDED
File without changes
pybedtools/mcp_output/mcp_plugin/adapter.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ # Path settings
5
+ source_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "source")
6
+ sys.path.insert(0, source_path)
7
+
8
+ # Import statements
9
+ try:
10
+ from pybedtools.bedtool import BedTool
11
+ from pybedtools.helpers import cleanup
12
+ from pybedtools.scripts.annotate import main as annotate_main
13
+ from pybedtools.scripts.intersection_matrix import main as intersection_matrix_main
14
+ except ImportError as e:
15
+ print(f"ImportError: {e}. Ensure all dependencies are correctly installed.")
16
+
17
+ # Adapter class
18
+ class Adapter:
19
+ """
20
+ Adapter class for MCP plugin, providing access to pybedtools functionalities.
21
+ """
22
+
23
+ def __init__(self):
24
+ """
25
+ Initialize the Adapter with default mode set to 'import'.
26
+ """
27
+ self.mode = "import"
28
+
29
+ # -------------------- Class Instance Methods --------------------
30
+
31
+ def create_bedtool_instance(self, file_path):
32
+ """
33
+ Create an instance of BedTool.
34
+
35
+ :param file_path: Path to the BED file.
36
+ :return: Dictionary with status and BedTool instance or error message.
37
+ """
38
+ try:
39
+ bedtool_instance = BedTool(file_path)
40
+ return {"status": "success", "instance": bedtool_instance}
41
+ except Exception as e:
42
+ return {"status": "error", "message": f"Failed to create BedTool instance: {e}"}
43
+
44
+ # -------------------- Function Call Methods --------------------
45
+
46
+ def call_annotate(self, args):
47
+ """
48
+ Call the annotate script.
49
+
50
+ :param args: Arguments for the annotate script.
51
+ :return: Dictionary with status and result or error message.
52
+ """
53
+ try:
54
+ result = annotate_main(args)
55
+ return {"status": "success", "result": result}
56
+ except Exception as e:
57
+ return {"status": "error", "message": f"Failed to execute annotate: {e}"}
58
+
59
+ def call_intersection_matrix(self, args):
60
+ """
61
+ Call the intersection_matrix script.
62
+
63
+ :param args: Arguments for the intersection_matrix script.
64
+ :return: Dictionary with status and result or error message.
65
+ """
66
+ try:
67
+ result = intersection_matrix_main(args)
68
+ return {"status": "success", "result": result}
69
+ except Exception as e:
70
+ return {"status": "error", "message": f"Failed to execute intersection_matrix: {e}"}
71
+
72
+ # -------------------- Utility Methods --------------------
73
+
74
+ def cleanup_temp_files(self):
75
+ """
76
+ Cleanup temporary files created by pybedtools.
77
+
78
+ :return: Dictionary with status and message.
79
+ """
80
+ try:
81
+ cleanup()
82
+ return {"status": "success", "message": "Temporary files cleaned up successfully."}
83
+ except Exception as e:
84
+ return {"status": "error", "message": f"Failed to cleanup temporary files: {e}"}
85
+
86
+ # Example usage
87
+ if __name__ == "__main__":
88
+ adapter = Adapter()
89
+ # Example: Create BedTool instance
90
+ response = adapter.create_bedtool_instance("example.bed")
91
+ print(response)
92
+
93
+ # Example: Call annotate script
94
+ response = adapter.call_annotate(["-i", "input.bed", "-o", "output.bed"])
95
+ print(response)
96
+
97
+ # Example: Cleanup temporary files
98
+ response = adapter.cleanup_temp_files()
99
+ print(response)
pybedtools/mcp_output/mcp_plugin/main.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ MCP Service Auto-Wrapper - Auto-generated
3
+ """
4
+ from mcp_service import create_app
5
+
6
+ def main():
7
+ """Main entry point"""
8
+ app = create_app()
9
+ return app
10
+
11
+ if __name__ == "__main__":
12
+ app = main()
13
+ app.run()
pybedtools/mcp_output/mcp_plugin/mcp_service.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ # Path settings to include the local source directory on sys.path
5
+ source_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "source")
6
+ if source_path not in sys.path:
7
+ sys.path.insert(0, source_path)
8
+
9
+ from fastmcp import FastMCP
10
+ from pybedtools.bedtool import BedTool
11
+ from pybedtools.helpers import cleanup
12
+ from pybedtools.settings import Settings
13
+
14
+ # Create the FastMCP service application
15
+ mcp = FastMCP("pybedtools_service")
16
+
17
+ @mcp.tool(name="intersect_bed", description="Intersect two BED files and return the result.")
18
+ def intersect_bed(file1: str, file2: str) -> dict:
19
+ """
20
+ Intersects two BED files using BedTool and returns the result.
21
+
22
+ :param file1: Path to the first BED file.
23
+ :param file2: Path to the second BED file.
24
+ :return: Dictionary containing success status and result or error message.
25
+ """
26
+ try:
27
+ a = BedTool(file1)
28
+ b = BedTool(file2)
29
+ result = a.intersect(b)
30
+ return {"success": True, "result": str(result), "error": None}
31
+ except Exception as e:
32
+ return {"success": False, "result": None, "error": str(e)}
33
+
34
+ @mcp.tool(name="merge_bed", description="Merge overlapping intervals in a BED file.")
35
+ def merge_bed(file: str) -> dict:
36
+ """
37
+ Merges overlapping intervals in a BED file using BedTool.
38
+
39
+ :param file: Path to the BED file.
40
+ :return: Dictionary containing success status and result or error message.
41
+ """
42
+ try:
43
+ a = BedTool(file)
44
+ result = a.merge()
45
+ return {"success": True, "result": str(result), "error": None}
46
+ except Exception as e:
47
+ return {"success": False, "result": None, "error": str(e)}
48
+
49
+ @mcp.tool(name="annotate_bed", description="Annotate a BED file with additional information.")
50
+ def annotate_bed(file: str, annotation_file: str) -> dict:
51
+ """
52
+ Annotates a BED file with additional information from another file.
53
+
54
+ :param file: Path to the BED file to be annotated.
55
+ :param annotation_file: Path to the annotation file.
56
+ :return: Dictionary containing success status and result or error message.
57
+ """
58
+ try:
59
+ a = BedTool(file)
60
+ annotations = BedTool(annotation_file)
61
+ result = a.annotate(annotations)
62
+ return {"success": True, "result": str(result), "error": None}
63
+ except Exception as e:
64
+ return {"success": False, "result": None, "error": str(e)}
65
+
66
+ def create_app() -> FastMCP:
67
+ """
68
+ Creates and returns the FastMCP application instance.
69
+
70
+ :return: FastMCP instance.
71
+ """
72
+ return mcp
pybedtools/mcp_output/requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fastmcp
2
+ fastapi
3
+ uvicorn[standard]
4
+ pydantic>=2.0.0
5
+ numpy
6
+ pandas
7
+ pysam
8
+ matplotlib
pybedtools/mcp_output/start_mcp.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ MCP Service Startup Entry
4
+ """
5
+ import sys
6
+ import os
7
+
8
+ project_root = os.path.dirname(os.path.abspath(__file__))
9
+ mcp_plugin_dir = os.path.join(project_root, "mcp_plugin")
10
+ if mcp_plugin_dir not in sys.path:
11
+ sys.path.insert(0, mcp_plugin_dir)
12
+
13
+ from mcp_service import create_app
14
+
15
+ def main():
16
+ """Start FastMCP service"""
17
+ app = create_app()
18
+ # Use environment variable to configure port, default 8000
19
+ port = int(os.environ.get("MCP_PORT", "8000"))
20
+
21
+ # Choose transport mode based on environment variable
22
+ transport = os.environ.get("MCP_TRANSPORT", "stdio")
23
+ if transport == "http":
24
+ app.run(transport="http", host="0.0.0.0", port=port)
25
+ else:
26
+ # Default to STDIO mode
27
+ app.run()
28
+
29
+ if __name__ == "__main__":
30
+ main()
pybedtools/mcp_output/workflow_summary.json ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "repository": {
3
+ "name": "pybedtools",
4
+ "url": "https://github.com/daler/pybedtools",
5
+ "local_path": "/export/zxcpu1/shiweijie/code/ghh/Code2MCP/workspace/pybedtools",
6
+ "description": "Python library",
7
+ "features": "Basic functionality",
8
+ "tech_stack": "Python",
9
+ "stars": 0,
10
+ "forks": 0,
11
+ "language": "Python",
12
+ "last_updated": "",
13
+ "complexity": "medium",
14
+ "intrusiveness_risk": "medium"
15
+ },
16
+ "execution": {
17
+ "start_time": 1769851645.793026,
18
+ "end_time": 1769851711.829195,
19
+ "duration": 66.03616905212402,
20
+ "status": "success",
21
+ "workflow_status": "success",
22
+ "nodes_executed": [
23
+ "download",
24
+ "analysis",
25
+ "env",
26
+ "generate",
27
+ "run",
28
+ "review",
29
+ "finalize"
30
+ ],
31
+ "total_files_processed": 3,
32
+ "environment_type": "unknown",
33
+ "llm_calls": 0,
34
+ "deepwiki_calls": 0
35
+ },
36
+ "tests": {
37
+ "original_project": {
38
+ "passed": false,
39
+ "details": {},
40
+ "test_coverage": "100%",
41
+ "execution_time": 0,
42
+ "test_files": []
43
+ },
44
+ "mcp_plugin": {
45
+ "passed": true,
46
+ "details": {},
47
+ "service_health": "healthy",
48
+ "startup_time": 0,
49
+ "transport_mode": "stdio",
50
+ "fastmcp_version": "unknown",
51
+ "mcp_version": "unknown"
52
+ }
53
+ },
54
+ "analysis": {
55
+ "structure": {
56
+ "packages": [
57
+ "source.pybedtools",
58
+ "source.pybedtools.contrib",
59
+ "source.pybedtools.test"
60
+ ]
61
+ },
62
+ "dependencies": {
63
+ "has_environment_yml": false,
64
+ "has_requirements_txt": true,
65
+ "pyproject": true,
66
+ "setup_cfg": true,
67
+ "setup_py": true
68
+ },
69
+ "entry_points": {
70
+ "imports": [],
71
+ "cli": [],
72
+ "modules": []
73
+ },
74
+ "risk_assessment": {
75
+ "import_feasibility": 0.8,
76
+ "intrusiveness_risk": "medium",
77
+ "complexity": "medium"
78
+ },
79
+ "deepwiki_analysis": {
80
+ "repo_url": "https://github.com/daler/pybedtools",
81
+ "repo_name": "pybedtools",
82
+ "content": "daler/pybedtools\nCore Architecture\nBedTool Class\nInterval and IntervalFile\nHelper Functions and Utilities\nOperations and File Handling\nBEDTools Method Wrappers\nFeature Manipulation Functions\nFile Format Support\nExtended Functionality\nContrib Module\nCommand-line Scripts\nParallel Processing and Statistical Analysis\nDevelopment and Testing\nBuild System and Packaging\nTesting Framework\nCI/CD Pipeline\nDocumentation and Configuration\nAPI Documentation System\nGenome Registry and Configuration\nExamples and Tutorials\ndocs/source/autodoc_source.rst\ndocs/source/index.rst\ndocs/source/main.rst\npybedtools/__init__.py\npybedtools/bedtool.py\npybedtools/helpers.py\npybedtools/settings.py\npybedtools/stats.py\nPurpose and Scope\npybedtoolsis a Python library that wraps and extends the BEDTools suite of programs for genomic interval manipulation, commonly referred to as \"genome algebra.\" This library provides a Pythonic interface to BEDTools functionality while adding advanced features for genomic data analysis, visualization, and statistical operations.\nThis document provides a high-level overview of the entire pybedtools system architecture, core components, and data flow patterns. For detailed information about specific subsystems, see the Core Architecture (2), Operations and File Handling (3), Extended Functionality (4), and Development Infrastructure (5) sections.\nSystem Architecture Overview\nBuild & DistributionExtended FunctionalityExternal Tools IntegrationCore Processing LayerPython Interface LayerBedToolBedTool Methodsintersect(), merge(), etc.HistoryIntervalIntervalFileIntervalIterator_wraps DecoratorBEDTools ProgramsintersectBed, mergeBed, etc.subprocess.PopenTemporary Filescontrib ModuleCommand-line ScriptsStatistical FunctionsVisualization ToolsCython Compilation.pyx to .cppsetup.pyTest Framework\nBuild & Distribution\nExtended Functionality\nExternal Tools Integration\nCore Processing Layer\nPython Interface Layer\nBedTool Methodsintersect(), merge(), etc.\nIntervalFile\nIntervalIterator\n_wraps Decorator\nBEDTools ProgramsintersectBed, mergeBed, etc.\nsubprocess.Popen\nTemporary Files\ncontrib Module\nCommand-line Scripts\nStatistical Functions\nVisualization Tools\nCython Compilation.pyx to .cpp\nTest Framework\nSources:pybedtools/bedtool.py478-637pybedtools/cbedtools.pypybedtools/helpers.py314-488setup.py\nCore Components\nPrimary Interface Classes\nThe system is built around several key classes that provide different levels of abstraction:\nIntervalFile\nIntervalIterator\nMethod Wrapping System\nThe_wrapsdecorator atpybedtools/bedtool.py103-439provides the foundation for integrating BEDTools programs as Python methods. This decorator handles:\nAutomatic argument processing and validation\nGenome file management\nInput/output format detection (BAM vs BED)\nCommand-line argument construction\nProcess execution viasubprocess.Popen\nsubprocess.Popen\nSources:pybedtools/bedtool.py103-439pybedtools/helpers.py314-488\nData Flow Architecture\nOutput ProcessingBEDTools ExecutionCore Processing PipelineBedTool CreationInput SourcesGenomic FilesBED/GFF/BAM/VCFString Datapandas DataFramesPython IterablesBedTool.init()from_string=Truefrom_dataframe()IntervalFileFile parsingInterval Objects0-based coordinatesBedTool Methodswrapped BEDTools opsMethod ChainingFluent APIhandle_kwargs()call_bedtools()subprocess.PopenBEDTools ProgramsStreaming ResultsFile-based ResultsTemporary FileManagement\nOutput Processing\nBEDTools Execution\nCore Processing Pipeline\nBedTool Creation\nInput Sources\nGenomic FilesBED/GFF/BAM/VCF\nString Data\npandas DataFrames\nPython Iterables\nBedTool.init()\nfrom_string=True\nfrom_dataframe()\nIntervalFileFile parsing\nInterval Objects0-based coordinates\nBedTool Methodswrapped BEDTools ops\nMethod ChainingFluent API\nhandle_kwargs()\ncall_bedtools()\nsubprocess.Popen\nBEDTools Programs\nStreaming Results\nFile-based Results\nTemporary FileManagement\nSources:pybedtools/bedtool.py481-637pybedtools/bedtool.py638-679pybedtools/helpers.py314-488pybedtools/bedtool.py283-422\nKey Subsystems\nBEDTools Program Registry\nThe system maintains registries to map old BEDTools program names to new unified command names:\n_implicit_registry: Maps programs to their implicit input arguments\n_implicit_registry\n_other_registry: Maps programs to secondary input arguments\n_other_registry\n_bam_registry: Maps programs to BAM-specific input arguments\n_bam_registry\n_prog_names: Maps old program names to new bedtools subcommands\n_prog_names\nThese registries are populated by the_wrapsdecorator and accessed during runtime command construction.\nSources:pybedtools/bedtool.py52-55pybedtools/settings.py21-76pybedtools/bedtool.py236-243\nFile Type Detection and Handling\nThe system automatically detects and handles multiple genomic file formats:\nFile type detection influences output format decisions and determines which BEDTools programs can accept the input.\nSources:pybedtools/helpers.py168-225pybedtools/bedtool.py361-390\nTemporary File Management\nThe system uses a sophisticated temporary file management system:\nGlobalTEMPFILESregistry inpybedtools/filenames.py\nAutomatic cleanup viaatexit.register(cleanup)atpybedtools/helpers.py909\natexit.register(cleanup)\nPer-BedTool temporary file creation via_tmp()method\nUser-controllable cleanup throughKEEP_TEMPFILESsetting\nKEEP_TEMPFILES\nSources:pybedtools/filenames.pypybedtools/helpers.py278-298pybedtools/bedtool.py479pybedtools/helpers.py909\nHistory and Reproducibility\nEachBedToolobject maintains a history of operations through theHistoryclass, enabling:\nMethod call tracking with arguments\nReproducible analysis pipelines\nDebugging and introspection capabilities\nTemporary file lifecycle management\nThe_log_to_historydecorator atpybedtools/bedtool.py442-475automatically captures method calls and their parameters.\n_log_to_history\nSources:pybedtools/bedtool.py442-475pybedtools/bedtool.py636\nRefresh this wiki\nOn this page\nPurpose and Scope\nSystem Architecture Overview\nCore Components\nPrimary Interface Classes\nMethod Wrapping System\nData Flow Architecture\nKey Subsystems\nBEDTools Program Registry\nFile Type Detection and Handling\nTemporary File Management\nHistory and Reproducibility",
83
+ "model": "gpt-4o-2024-08-06",
84
+ "source": "selenium",
85
+ "success": true
86
+ },
87
+ "code_complexity": {
88
+ "cyclomatic_complexity": "medium",
89
+ "cognitive_complexity": "medium",
90
+ "maintainability_index": 75
91
+ },
92
+ "security_analysis": {
93
+ "vulnerabilities_found": 0,
94
+ "security_score": 85,
95
+ "recommendations": []
96
+ }
97
+ },
98
+ "plugin_generation": {
99
+ "files_created": [
100
+ "mcp_output/start_mcp.py",
101
+ "mcp_output/mcp_plugin/__init__.py",
102
+ "mcp_output/mcp_plugin/mcp_service.py",
103
+ "mcp_output/mcp_plugin/adapter.py",
104
+ "mcp_output/mcp_plugin/main.py",
105
+ "mcp_output/requirements.txt",
106
+ "mcp_output/README_MCP.md"
107
+ ],
108
+ "main_entry": "start_mcp.py",
109
+ "requirements": [
110
+ "fastmcp>=0.1.0",
111
+ "pydantic>=2.0.0"
112
+ ],
113
+ "readme_path": "/export/zxcpu1/shiweijie/code/ghh/Code2MCP/workspace/pybedtools/mcp_output/README_MCP.md",
114
+ "adapter_mode": "import",
115
+ "total_lines_of_code": 0,
116
+ "generated_files_size": 0,
117
+ "tool_endpoints": 0,
118
+ "supported_features": [
119
+ "Basic functionality"
120
+ ],
121
+ "generated_tools": [
122
+ "Basic tools",
123
+ "Health check tools",
124
+ "Version info tools"
125
+ ]
126
+ },
127
+ "code_review": {},
128
+ "errors": [],
129
+ "warnings": [],
130
+ "recommendations": [
131
+ "Improve test coverage by adding more unit tests for critical modules",
132
+ "optimize large files like `bedtool.py` and `genome_registry.py` for better performance",
133
+ "enhance documentation for core modules and CLI commands",
134
+ "streamline the CI/CD pipeline to automate testing and deployment",
135
+ "refactor code to reduce complexity and improve maintainability",
136
+ "ensure all dependencies are up-to-date and compatible",
137
+ "implement a more robust error handling mechanism",
138
+ "consider adding more examples and tutorials to improve user understanding",
139
+ "review and update the plugin integration to ensure seamless functionality",
140
+ "conduct a code review to identify potential security vulnerabilities."
141
+ ],
142
+ "performance_metrics": {
143
+ "memory_usage_mb": 0,
144
+ "cpu_usage_percent": 0,
145
+ "response_time_ms": 0,
146
+ "throughput_requests_per_second": 0
147
+ },
148
+ "deployment_info": {
149
+ "supported_platforms": [
150
+ "Linux",
151
+ "Windows",
152
+ "macOS"
153
+ ],
154
+ "python_versions": [
155
+ "3.8",
156
+ "3.9",
157
+ "3.10",
158
+ "3.11",
159
+ "3.12"
160
+ ],
161
+ "deployment_methods": [
162
+ "Docker",
163
+ "pip",
164
+ "conda"
165
+ ],
166
+ "monitoring_support": true,
167
+ "logging_configuration": "structured"
168
+ },
169
+ "execution_analysis": {
170
+ "success_factors": [
171
+ "Successful execution of all workflow nodes",
172
+ "Healthy service status of the MCP plugin"
173
+ ],
174
+ "failure_reasons": [],
175
+ "overall_assessment": "excellent",
176
+ "node_performance": {
177
+ "download_time": "Completed successfully, indicating efficient data retrieval",
178
+ "analysis_time": "Completed successfully, indicating effective code analysis",
179
+ "generation_time": "Completed successfully, indicating efficient code generation",
180
+ "test_time": "No specific test time provided, but MCP plugin tests passed"
181
+ },
182
+ "resource_usage": {
183
+ "memory_efficiency": "Memory usage data not provided, unable to assess",
184
+ "cpu_efficiency": "CPU usage data not provided, unable to assess",
185
+ "disk_usage": "Disk usage data not provided, unable to assess"
186
+ }
187
+ },
188
+ "technical_quality": {
189
+ "code_quality_score": 75,
190
+ "architecture_score": 80,
191
+ "performance_score": 70,
192
+ "maintainability_score": 75,
193
+ "security_score": 85,
194
+ "scalability_score": 70
195
+ }
196
+ }
pybedtools/source/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Wrapper -- and more -- for BEDtools
2
+
3
+ Copyright (c) 2010-2022 Ryan Dale
4
+ All rights reserved.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
pybedtools/source/MANIFEST.in ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ recursive-include pybedtools/include/ *
2
+ include README.rst
3
+ include LICENSE.txt
4
+ include ez_setup.py
5
+ recursive-include pybedtools/test/data *
6
+ recursive-include pybedtools/test *
7
+ include docs/Makefile
8
+ include docs/make.bat
9
+ recursive-include pybedtools *.cpp
10
+ recursive-include pybedtools *.c
11
+ recursive-exclude * __pycache__
12
+ recursive-exclude * *.py[co]
pybedtools/source/README.rst ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Overview
3
+ --------
4
+
5
+ .. image:: https://badge.fury.io/py/pybedtools.svg?style=flat
6
+ :target: https://badge.fury.io/py/pybedtools
7
+
8
+ .. image:: https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg
9
+ :target: https://bioconda.github.io
10
+
11
+ The `BEDTools suite of programs <http://bedtools.readthedocs.org/>`_ is widely
12
+ used for genomic interval manipulation or "genome algebra". `pybedtools` wraps
13
+ and extends BEDTools and offers feature-level manipulations from within
14
+ Python.
15
+
16
+ See full online documentation, including installation instructions, at
17
+ https://daler.github.io/pybedtools/.
18
+
19
+ The GitHub repo is at https://github.com/daler/pybedtools.
20
+
21
+ Why `pybedtools`?
22
+ -----------------
23
+
24
+ Here is an example to get the names of genes that are <5 kb away from
25
+ intergenic SNPs:
26
+
27
+ .. code-block:: python
28
+
29
+ from pybedtools import BedTool
30
+
31
+ snps = BedTool('snps.bed.gz') # [1]
32
+ genes = BedTool('hg19.gff') # [1]
33
+
34
+ intergenic_snps = snps.subtract(genes) # [2]
35
+ nearby = genes.closest(intergenic_snps, d=True, stream=True) # [2, 3]
36
+
37
+ for gene in nearby: # [4]
38
+ if int(gene[-1]) < 5000: # [4]
39
+ print gene.name # [4]
40
+
41
+ Useful features shown here include:
42
+
43
+ * `[1]` support for all BEDTools-supported formats (here gzipped BED and GFF)
44
+ * `[2]` wrapping of all BEDTools programs and arguments (here, `subtract` and `closest` and passing
45
+ the `-d` flag to `closest`);
46
+ * `[3]` streaming results (like Unix pipes, here specified by `stream=True`)
47
+ * `[4]` iterating over results while accessing feature data by index or by attribute
48
+ access (here `[-1]` and `.name`).
49
+
50
+ In contrast, here is the same analysis using shell scripting. Note that this
51
+ requires knowledge in Perl, bash, and awk. The run time is identical to the
52
+ `pybedtools` version above:
53
+
54
+ .. code-block:: bash
55
+
56
+ snps=snps.bed.gz
57
+ genes=hg19.gff
58
+ intergenic_snps=/tmp/intergenic_snps
59
+
60
+ snp_fields=`zcat $snps | awk '(NR == 2){print NF; exit;}'`
61
+ gene_fields=9
62
+ distance_field=$(($gene_fields + $snp_fields + 1))
63
+
64
+ intersectBed -a $snps -b $genes -v > $intergenic_snps
65
+
66
+ closestBed -a $genes -b $intergenic_snps -d \
67
+ | awk '($'$distance_field' < 5000){print $9;}' \
68
+ | perl -ne 'm/[ID|Name|gene_id]=(.*?);/; print "$1\n"'
69
+
70
+ rm $intergenic_snps
71
+
72
+ See the `Shell script comparison <http://daler.github.io/pybedtools/sh-comparison.html>`_ in the docs
73
+ for more details on this comparison, or keep reading the full documentation at
74
+ http://daler.github.io/pybedtools.
pybedtools/source/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pybedtools Project Package Initialization File
4
+ """
pybedtools/source/build-docs.sh ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Build docs here, then copy them over to a fresh, temporary checkout of the
4
+ # gh-pages branch from github. Then upload 'em. After a few minutes, you'll see
5
+ # the newly-generated docs at daler.github.io/pybedtools.
6
+
7
+ # Ideas from:
8
+ # http://executableopinions.readthedocs.org/en/latest/labs/gh-pages/gh-pages.html
9
+ set -e
10
+ set -x
11
+
12
+ (cd docs && make html)
13
+ HERE=$(pwd)
14
+ MSG="Adding gh-pages docs for $(git log --abbrev-commit | head -n1)"
15
+ DOCSOURCE=$HERE/docs/build/html
16
+ TMPREPO=/tmp/docs
17
+ rm -rf $TMPREPO
18
+ mkdir -p -m 0755 $TMPREPO
19
+ git clone git@github.com:daler/pybedtools.git $TMPREPO
20
+ cd $TMPREPO
21
+ git checkout gh-pages
22
+ cp -r $DOCSOURCE/* $TMPREPO
23
+ touch $TMPREPO/.nojekyll
24
+ git add -A
25
+ git commit -m "$MSG"
26
+ git push origin gh-pages
27
+ cd $HERE
pybedtools/source/dev-requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ cython
2
+ matplotlib
3
+ numpydoc
4
+ pandas
5
+ pyyaml
6
+ sphinx
7
+ pysam
pybedtools/source/docker/full-test.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ set -x
4
+
5
+ # Build the configured containers and run tests in each.
6
+ #
7
+ #
8
+ containers="pbt-test-py2 pbt-test-py3"
9
+ for container in $containers; do
10
+ docker build -t $container $container
11
+ docker run -it -v $(pwd)/..:/opt/pybedtools $container docker/harness.sh
12
+ done
pybedtools/source/docker/harness.sh ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -x
5
+
6
+ # Use Agg backend for matplotlib, which avoids X server errors
7
+ mplrc=$(python -c 'from matplotlib import matplotlib_fname as mf; print(mf())')
8
+ mkdir -p ~/.config/matplotlib
9
+ cp $mplrc ~/.config/matplotlib
10
+ sed -i "s/: Qt4Agg/: Agg/g" ~/.config/matplotlib/matplotlibrc
11
+
12
+ # The repo should have been exported to the container as /opt/pybedtools.
13
+ #
14
+ # Since docker runs as root, and we want to keep the exported data intact, we
15
+ # make a copy and do a completely clean installation on that copy before
16
+ # running tests.
17
+ cd ~
18
+ cp -r /opt/pybedtools .
19
+ cd pybedtools
20
+ python setup.py clean
21
+ python setup.py develop
22
+ nosetests
23
+ (cd docs && make doctest)
pybedtools/source/docker/pbt-test-py2/Dockerfile ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:14.04
2
+
3
+ MAINTAINER Ryan Dale <dalerr@niddk.nih.gov>
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ bzip2 \
8
+ ca-certificates \
9
+ git \
10
+ libglib2.0-0 \
11
+ libsm6 \
12
+ libxext6 \
13
+ libxrender1 \
14
+ mysql-client \
15
+ wget \
16
+ zlib1g-dev
17
+
18
+ RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
19
+ wget --quiet https://repo.continuum.io/miniconda/Miniconda-3.10.1-Linux-x86_64.sh && \
20
+ /bin/bash /Miniconda-3.10.1-Linux-x86_64.sh -b -p /opt/conda && \
21
+ rm Miniconda-3.10.1-Linux-x86_64.sh && \
22
+ /opt/conda/bin/conda install --yes conda==3.14.1
23
+ ENV PATH /opt/conda/bin:$PATH
24
+
25
+ RUN conda install -c daler \
26
+ pip \
27
+ cython \
28
+ matplotlib \
29
+ nose \
30
+ numpydoc \
31
+ pip \
32
+ pandas \
33
+ pyyaml \
34
+ sphinx \
35
+ pysam
36
+ RUN conda install -c daler \
37
+ tabix \
38
+ bedtools=2.25.0
39
+ ENV DISPLAY=:0
40
+ ENV LANG C.UTF-8
41
+ WORKDIR /opt/pybedtools
pybedtools/source/docker/pbt-test-py3/Dockerfile ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:14.04
2
+
3
+ MAINTAINER Ryan Dale <dalerr@niddk.nih.gov>
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ bzip2 \
8
+ ca-certificates \
9
+ git \
10
+ libglib2.0-0 \
11
+ libsm6 \
12
+ libxext6 \
13
+ libxrender1 \
14
+ mysql-client \
15
+ wget \
16
+ zlib1g-dev
17
+
18
+ RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
19
+ wget --quiet https://repo.continuum.io/miniconda/Miniconda3-3.10.1-Linux-x86_64.sh && \
20
+ /bin/bash /Miniconda3-3.10.1-Linux-x86_64.sh -b -p /opt/conda && \
21
+ rm Miniconda3-3.10.1-Linux-x86_64.sh && \
22
+ /opt/conda/bin/conda install --yes conda==3.14.1
23
+ ENV PATH /opt/conda/bin:$PATH
24
+
25
+ RUN conda install -c daler \
26
+ pip \
27
+ cython \
28
+ matplotlib \
29
+ nose \
30
+ numpydoc \
31
+ pip \
32
+ pandas \
33
+ pyyaml \
34
+ sphinx \
35
+ pysam
36
+ RUN conda install -c daler \
37
+ tabix \
38
+ bedtools=2.25.0
39
+ ENV DISPLAY=:0
40
+ ENV LANG C.UTF-8
41
+ WORKDIR /opt/pybedtools
pybedtools/source/docs/Makefile ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = sphinx-build
7
+ PAPER =
8
+ #BUILDDIR = ../../pybedtools-docs
9
+ BUILDDIR = build
10
+ PDF = build/html/pybedtools_manual.pdf
11
+ PDFBUILDDIR = /tmp/doc-pybedtools
12
+
13
+ PYTHONPATH=$PYTHONPATH:..
14
+
15
+
16
+ # Internal variables.
17
+ PAPEROPT_a4 = -D latex_paper_size=a4
18
+ PAPEROPT_letter = -D latex_paper_size=letter
19
+ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
20
+
21
+ .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
22
+
23
+ help:
24
+ @echo "Please use \`make <target>' where <target> is one of"
25
+ @echo " html to make standalone HTML files"
26
+ @echo " dirhtml to make HTML files named index.html in directories"
27
+ @echo " singlehtml to make a single large HTML file"
28
+ @echo " pickle to make pickle files"
29
+ @echo " json to make JSON files"
30
+ @echo " htmlhelp to make HTML files and a HTML help project"
31
+ @echo " qthelp to make HTML files and a qthelp project"
32
+ @echo " devhelp to make HTML files and a Devhelp project"
33
+ @echo " epub to make an epub"
34
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
35
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
36
+ @echo " text to make text files"
37
+ @echo " man to make manual pages"
38
+ @echo " changes to make an overview of all changed/added/deprecated items"
39
+ @echo " linkcheck to check all external links for integrity"
40
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
41
+
42
+
43
+ clean:
44
+ -rm -rf $(BUILDDIR)/* source/autodocs/*.rst
45
+
46
+ html:
47
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
48
+ @echo
49
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
50
+ touch $(BUILDDIR)/html/.nojekyll
51
+
52
+ dirhtml:
53
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
54
+ @echo
55
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
56
+
57
+ singlehtml:
58
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
59
+ @echo
60
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
61
+
62
+ pickle:
63
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
64
+ @echo
65
+ @echo "Build finished; now you can process the pickle files."
66
+
67
+ json:
68
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
69
+ @echo
70
+ @echo "Build finished; now you can process the JSON files."
71
+
72
+ htmlhelp:
73
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
74
+ @echo
75
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
76
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
77
+
78
+ qthelp:
79
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
80
+ @echo
81
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
82
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
83
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pybedtools.qhcp"
84
+ @echo "To view the help file:"
85
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pybedtools.qhc"
86
+
87
+ devhelp:
88
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
89
+ @echo
90
+ @echo "Build finished."
91
+ @echo "To view the help file:"
92
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/pybedtools"
93
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pybedtools"
94
+ @echo "# devhelp"
95
+
96
+ epub:
97
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
98
+ @echo
99
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
100
+
101
+ latex:
102
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
103
+ @echo
104
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
105
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
106
+ "(use \`make latexpdf' here to do that automatically)."
107
+
108
+ latexpdf:
109
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(PDFBUILDDIR)/latex
110
+ @echo "Running LaTeX files through pdflatex..."
111
+ make -C $(PDFBUILDDIR)/latex all-pdf
112
+ cp $(PDFBUILDDIR)/latex/*.pdf $(PDF)
113
+ @echo "pdflatex finished; see PDF files in $(PDF)"
114
+
115
+ text:
116
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
117
+ @echo
118
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
119
+
120
+ man:
121
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
122
+ @echo
123
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
124
+
125
+ changes:
126
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
127
+ @echo
128
+ @echo "The overview file is in $(BUILDDIR)/changes."
129
+
130
+ linkcheck:
131
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
132
+ @echo
133
+ @echo "Link check complete; look for any errors in the above output " \
134
+ "or in $(BUILDDIR)/linkcheck/output.txt."
135
+
136
+ doctest:
137
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
138
+ @echo "Testing of doctests in the sources finished, look at the " \
139
+ "results in $(BUILDDIR)/doctest/output.txt."
pybedtools/source/docs/README.rst ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+
2
+ Compiled HTML docs can be found at http://pythonhosted.org/pybedtools/
pybedtools/source/docs/make.bat ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @ECHO OFF
2
+
3
+ REM Command file for Sphinx documentation
4
+
5
+ if "%SPHINXBUILD%" == "" (
6
+ set SPHINXBUILD=sphinx-build
7
+ )
8
+ set BUILDDIR=build
9
+ set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
10
+ if NOT "%PAPER%" == "" (
11
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
12
+ )
13
+
14
+ if "%1" == "" goto help
15
+
16
+ if "%1" == "help" (
17
+ :help
18
+ echo.Please use `make ^<target^>` where ^<target^> is one of
19
+ echo. html to make standalone HTML files
20
+ echo. dirhtml to make HTML files named index.html in directories
21
+ echo. singlehtml to make a single large HTML file
22
+ echo. pickle to make pickle files
23
+ echo. json to make JSON files
24
+ echo. htmlhelp to make HTML files and a HTML help project
25
+ echo. qthelp to make HTML files and a qthelp project
26
+ echo. devhelp to make HTML files and a Devhelp project
27
+ echo. epub to make an epub
28
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
29
+ echo. text to make text files
30
+ echo. man to make manual pages
31
+ echo. changes to make an overview over all changed/added/deprecated items
32
+ echo. linkcheck to check all external links for integrity
33
+ echo. doctest to run all doctests embedded in the documentation if enabled
34
+ goto end
35
+ )
36
+
37
+ if "%1" == "clean" (
38
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
39
+ del /q /s %BUILDDIR%\*
40
+ goto end
41
+ )
42
+
43
+ if "%1" == "html" (
44
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
45
+ echo.
46
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
47
+ goto end
48
+ )
49
+
50
+ if "%1" == "dirhtml" (
51
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
52
+ echo.
53
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
54
+ goto end
55
+ )
56
+
57
+ if "%1" == "singlehtml" (
58
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
59
+ echo.
60
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
61
+ goto end
62
+ )
63
+
64
+ if "%1" == "pickle" (
65
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
66
+ echo.
67
+ echo.Build finished; now you can process the pickle files.
68
+ goto end
69
+ )
70
+
71
+ if "%1" == "json" (
72
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
73
+ echo.
74
+ echo.Build finished; now you can process the JSON files.
75
+ goto end
76
+ )
77
+
78
+ if "%1" == "htmlhelp" (
79
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
80
+ echo.
81
+ echo.Build finished; now you can run HTML Help Workshop with the ^
82
+ .hhp project file in %BUILDDIR%/htmlhelp.
83
+ goto end
84
+ )
85
+
86
+ if "%1" == "qthelp" (
87
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
88
+ echo.
89
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
90
+ .qhcp project file in %BUILDDIR%/qthelp, like this:
91
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pybedtools.qhcp
92
+ echo.To view the help file:
93
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pybedtools.ghc
94
+ goto end
95
+ )
96
+
97
+ if "%1" == "devhelp" (
98
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
99
+ echo.
100
+ echo.Build finished.
101
+ goto end
102
+ )
103
+
104
+ if "%1" == "epub" (
105
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
106
+ echo.
107
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
108
+ goto end
109
+ )
110
+
111
+ if "%1" == "latex" (
112
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
113
+ echo.
114
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
115
+ goto end
116
+ )
117
+
118
+ if "%1" == "text" (
119
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
120
+ echo.
121
+ echo.Build finished. The text files are in %BUILDDIR%/text.
122
+ goto end
123
+ )
124
+
125
+ if "%1" == "man" (
126
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
127
+ echo.
128
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
129
+ goto end
130
+ )
131
+
132
+ if "%1" == "changes" (
133
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
134
+ echo.
135
+ echo.The overview file is in %BUILDDIR%/changes.
136
+ goto end
137
+ )
138
+
139
+ if "%1" == "linkcheck" (
140
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
141
+ echo.
142
+ echo.Link check complete; look for any errors in the above output ^
143
+ or in %BUILDDIR%/linkcheck/output.txt.
144
+ goto end
145
+ )
146
+
147
+ if "%1" == "doctest" (
148
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
149
+ echo.
150
+ echo.Testing of doctests in the sources finished, look at the ^
151
+ results in %BUILDDIR%/doctest/output.txt.
152
+ goto end
153
+ )
154
+
155
+ :end
pybedtools/source/docs/source/3-brief-examples.rst ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .. _BEDTools: http://github.com/arq5x/bedtools
3
+
4
+
5
+ .. _3examples:
6
+
7
+ Three brief examples
8
+ --------------------
9
+ Here are three examples to show typical usage of :mod:`pybedtools`. More
10
+ info can be found in the docstrings of :mod:`pybedtools` methods and in the
11
+ :ref:`tutorial`.
12
+
13
+ You can also check out :ref:`shell_comparison` for a simple
14
+ example of how :mod:`pybedtools` can improve readability of your code with no
15
+ loss of speed compared to bash scripting.
16
+
17
+ .. note::
18
+
19
+ Please take the time to read and understand the conventions
20
+ :mod:`pybedtools` uses to handle files with different coordinate systems
21
+ (e.g., 0-based BED files vs 1-based GFF files) which are described
22
+ :ref:`here <zero_based_coords>`.
23
+
24
+ In summary,
25
+
26
+ * **Integer** values representing start/stop are *always in 0-based
27
+ coordinates*, regardless of file format. This means that all
28
+ :class:`Interval` objects can be treated identically, and greatly
29
+ simplifies underlying code.
30
+
31
+ * **String** values representing start/stop will use coordinates appropriate
32
+ for the format (1-based for GFF; 0-based for BED).
33
+
34
+ Example 1: Save a BED file of intersections, with track line
35
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
+ This example saves a new BED file of intersections between your files `mydata/snps.bed` and
37
+ `mydata/exons.bed`, adding a track line to the output::
38
+
39
+ >>> import pybedtools
40
+ >>> a = pybedtools.BedTool('mydata/snps.bed')
41
+ >>> a.intersect('mydata/exons.bed').saveas('snps-in-exons.bed', trackline="track name='SNPs in exons' color=128,0,0")
42
+
43
+ Example 2: Intersections for a 3-way Venn diagram
44
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
+ This example gets values for a 3-way Venn diagram of overlaps. This
46
+ demonstrates operator overloading of :class:`BedTool` objects. It assumes that
47
+ you have the files `a.bed`, `b.bed`, and `c.bed` in your current working
48
+ directory. If you'd like to use example files that come with
49
+ :mod:`pybedtools`, then replace strings like `'a.bed'` with
50
+ `pybedtools.example_filename('a.bed')`, which will retrieve the absolute path
51
+ to the example data file.::
52
+
53
+
54
+ >>> import pybedtools
55
+
56
+ >>> # set up 3 different bedtools
57
+ >>> a = pybedtools.BedTool('a.bed')
58
+ >>> b = pybedtools.BedTool('b.bed')
59
+ >>> c = pybedtools.BedTool('c.bed')
60
+
61
+ >>> (a-b-c).count() # unique to a
62
+ >>> (a+b-c).count() # in a and b, not c
63
+ >>> (a+b+c).count() # common to all
64
+ >>> # ... and so on, for all the combinations.
65
+
66
+
67
+
68
+ For more, see the :mod:`pybedtools.scripts.venn_mpl` and
69
+ :mod:`pybedtools.scripts.venn_gchart` scripts, which wrap this functionality in
70
+ command-line scripts to create Venn diagrams using either matplotlib or Google
71
+ Charts API respectively. Also see the :mod:`pybedtools.contrib.venn_maker`
72
+ module for a flexible interface to the VennDiagram `R` package.
73
+
74
+ .. _third example:
75
+
76
+ Example 3: Count reads in introns and exons, in parallel
77
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
+ This example shows how to count the number of reads in introns and exons in
79
+ parallel. It is somewhat more involved, but illustrates several additional
80
+ features of :mod:`pybedtools` such as:
81
+
82
+ * BAM file support (for more, see :ref:`bam`)
83
+ * indexing into Interval objects (for more, see :ref:`intervals`)
84
+ * filtering (for more, see :ref:`filtering`)
85
+ * streaming (for more, see :ref:`BedTools as iterators`)
86
+ * ability to use parallel processing
87
+
88
+ .. literalinclude:: example_3
89
+
90
+ For more on using :mod:`pybedtools`, continue on to the :ref:`tutorial` . . .
pybedtools/source/docs/source/FAQs.rst ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. include:: includeme.rst
2
+
3
+ FAQs
4
+ ====
5
+
6
+ .. note::
7
+
8
+ More detailed answers to these questions can often be found on the `Issues
9
+ <https://github.com/daler/pybedtools/issues/>`_ page.
10
+
11
+ "Does pybedtools have a simple reader/writer for BED files?"
12
+ ------------------------------------------------------------
13
+ While `pybedtools` designed to work with BEDTools, the reading/writing/parsing
14
+ function can be easily used for other things.
15
+
16
+ Simply iterating over a :class:`BedTool` object will parse each line into
17
+ a :class:`Interval` object. You can then manipulate this or access the fields
18
+ as needed.
19
+
20
+ For example::
21
+
22
+ x = pybedtools.example_bedtool('a.bed')
23
+ for interval in x:
24
+ # do something with interval
25
+
26
+ However, if you're planning on writing the results out to file, it may be more
27
+ useful to write a transformation function along with the :meth:`BedTool.each`
28
+ method. This allows you to read, transform, and write all in one command::
29
+
30
+ def my_func(f):
31
+ """
32
+ adds 10 bp to the stop
33
+ """
34
+ f.stop += 1
35
+ return f
36
+
37
+ pybedtools.example_bedtool('a.bed')\
38
+ .each(my_func)\
39
+ .saveas('out.bed')
40
+
41
+ Another useful idiom is creating a generator function. For example, here we
42
+ change the name field to reflect the value of a counter. We create a BedTool
43
+ from the iterator and then save it::
44
+
45
+ def gen():
46
+ counter = 0
47
+ for i in pybedtools.example_bedtool('a.bed'):
48
+ i.name = str(counter)
49
+ counter += 1
50
+ yield i
51
+
52
+ pybedtools.BedTool(gen()).saveas('counted.bed')
53
+
54
+
55
+ See :ref:`saveresults` for more on saving the results.
56
+
57
+ "Can I create a BedTool object from an existing list?"
58
+ ------------------------------------------------------
59
+
60
+ Sure, the :class:`BedTool` constructor will figure it out::
61
+
62
+ items = [
63
+ ('chr1', 100, 200),
64
+ ('chr1', 500, 600),
65
+ ]
66
+
67
+ x = pybedtools.BedTool(items)
68
+
69
+
70
+ "I'm getting an empty BedTool"
71
+ ------------------------------
72
+ Check to make sure you're not consuming a BedTool generator. Note that
73
+ :meth:`BedTool.filter` and :meth:`BedTool.each` will return a generator BedTool
74
+ object. Keep in mind that checking the length of a generator BedTool will
75
+ completely consume it.
76
+
77
+ It's probably best to save intermediate versions to file using
78
+ :meth:`BedTool.saveas`. If you don't provide a filename, it'll save to an
79
+ automatically cleaned up tempfile::
80
+
81
+ my_bedtool\
82
+ .filter(my_filter_func)\
83
+ .saveas()\
84
+ .intersect(y)\
85
+ .filter(lambda x: len(x) > 1000)\
86
+ .saveas('filtered-intersected-large.bed')
87
+
88
+
89
+ "I'm getting a MalformedBedLineError"
90
+ -------------------------------------
91
+ This error can be raised by BEDTools itself. Typical reasons are that start
92
+ > end, or the fields are not tab-delimited.
93
+
94
+ You can try the :func:`pybedtools.remove_invalid` function to clean up your
95
+ file, or manually edit the offending lines.
96
+
97
+
98
+ "I get a segfault when iterating over a BedTool object"
99
+ -------------------------------------------------------
100
+
101
+ `Issue #88 <https://github.com/daler/pybedtools/issues/88>`_ which
102
+ addresses this issue -- in summary, Cython's handling of iterators works
103
+ unexpectedly. It's best to call the `next()` method explicitly when doing
104
+ complex manipulations on an iterating :class:`BedTool`.
105
+
106
+
107
+ "Can I add extra information to FASTA headers when using BedTool.sequence()?"
108
+ -----------------------------------------------------------------------------
109
+
110
+ Since BEDTools adds the feature name to the FASTA header, you can manipulate
111
+ the feature name on the fly with a custom modifier function::
112
+
113
+ def fields2name(f):
114
+ "replace GFF featuretype field with the attributes field"
115
+ f[2] = f[-1]
116
+ return f
117
+
118
+ import pybedtools
119
+ g = pybedtools.BedTool("my.gff").each(fields2name).sequence(fi='my.fasta')
120
+
121
+ print open(g.seqfn).readline()
122
+
123
+
124
+ "Too many files open" error
125
+ ---------------------------
126
+
127
+ Sometimes you may get the error::
128
+
129
+ * Too many files open -- please submit a bug report so that this can be fixed
130
+
131
+ This error occurs because you have hit your operating system's limit on the
132
+ number of open files. This usually happens when creating many :class:`BedTool`
133
+ objects, often within a for-loop.
134
+
135
+ In general, **try to create as few** :class:`BedTool` **objects as you can**. Every time you
136
+ create a :class:`BedTool` object, you create a new open file. There is usually
137
+ a BEDTools program that already does what you want, and will do it faster.
138
+
139
+
140
+ For example, say we want to:
141
+
142
+ * start with all annotations
143
+ * only consider exons
144
+ * write a file containing just exons
145
+ * count reads in multiple BAM files for each exon
146
+
147
+
148
+ Here is a first draft. Note that the for-loop creates a :class:`BedTool`
149
+ object each iteration, and the `result` is yet another :class:`BedTool`. This
150
+ will version will raise the "Too many files open" error.
151
+
152
+ .. code-block:: python
153
+
154
+ # This version will be slow and, with many exons, will raise the "Too many
155
+ # files open" error
156
+
157
+ import pybedtools
158
+ all_features = pybedtools.BedTool('annotations.gff')
159
+ fout = open('exons.gff', 'w')
160
+ for feature in all_features:
161
+ if feature[2] != 'exon':
162
+ continue
163
+
164
+ fout.write(str(feature))
165
+
166
+ bt = pybedtools.BedTool([feature])
167
+ result = bt.multi_bam_coverage(bams=['reads1.bam', 'reads2.bam'])
168
+
169
+ # ...do something with result
170
+
171
+ fout.close()
172
+
173
+ In contrast, it would be better to construct an "exon-only" :class:`BedTool` at
174
+ the beginning. The :meth:`BedTool.filter` method is a good way to do this.
175
+ Then, there is only one call to :meth:`BedTool.multi_bam_coverage`.
176
+
177
+ In this version there are only 3 :class:`BedTool` objects: the
178
+ one that opens `annotations.gff`, the one that uses `exons.gff` after it is
179
+ saved, and `result`. (Note that the one created from the filter operation is
180
+ a "streaming" BedTool, so there is no open file that will contribute to the
181
+ total).
182
+
183
+ .. code-block:: python
184
+
185
+ # This is the recommended way.
186
+
187
+ import pybedtools
188
+
189
+ exons = pybedtools.BedTool('annotations.gff')\
190
+ .filter(lambda x: x[2] == 'exon')\
191
+ .saveas('exons.gff')
192
+
193
+ result = exons.multi_bam_coverage(bams=['reads1.bam', 'reads2.bam'])
194
+
195
+ # ...do something with result
pybedtools/source/docs/source/_static/custom.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ div.highlight-python pre {
2
+ font-size: 0.7em;
3
+ }
pybedtools/source/docs/source/_templates/layout.html ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {% extends '!layout.html' %}
2
+
3
+ {% block relbar2 %}
4
+ {{ relbar() }}
5
+
6
+ {% endblock %}
pybedtools/source/docs/source/autodoc_source.rst ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .. _autodoc:
3
+
4
+ .. _pybedtools reference:
5
+
6
+ .. currentmodule:: pybedtools
7
+
8
+ :mod:`pybedtools` Reference
9
+ ===========================
10
+ The following tables summarize the methods and functions; click on a method or
11
+ function name to see the complete documentation.
12
+
13
+ .. contents::
14
+
15
+ :class:`BedTool` creation
16
+ -------------------------
17
+ The main :class:`BedTool` documentation, with a list of all methods in
18
+ alphabetical order at the bottom. For more details, please see :ref:`creating
19
+ a BedTool`.
20
+
21
+ .. autosummary::
22
+ :toctree: autodocs
23
+
24
+ pybedtools.bedtool.BedTool
25
+
26
+ `BEDTools` wrappers
27
+ -------------------
28
+ These methods wrap `BEDTools` programs for easy use with Python; you can then
29
+ use the other :mod:`pybedtools` functionality for further manipulation and
30
+ analysis.
31
+
32
+ The documentation of each of these methods starts with
33
+ :mod:`pybedtools`-specific documentation, possibly followed by an example.
34
+ Finally, the `BEDTools` help is copied verbatim from whatever version was
35
+ installed when generating these docs.
36
+
37
+ In general the `BEDTool` wrapper methods adhere to the :ref:`Design principles`:
38
+
39
+ * :ref:`temp principle`
40
+ * :ref:`similarity principle`
41
+ * :ref:`version principle`
42
+ * :ref:`default args principle`
43
+
44
+
45
+ .. autosummary::
46
+ :toctree: autodocs
47
+
48
+ pybedtools.bedtool.BedTool.intersect
49
+ pybedtools.bedtool.BedTool.window
50
+ pybedtools.bedtool.BedTool.closest
51
+ pybedtools.bedtool.BedTool.coverage
52
+ pybedtools.bedtool.BedTool.map
53
+ pybedtools.bedtool.BedTool.genome_coverage
54
+ pybedtools.bedtool.BedTool.merge
55
+ pybedtools.bedtool.BedTool.cluster
56
+ pybedtools.bedtool.BedTool.complement
57
+ pybedtools.bedtool.BedTool.subtract
58
+ pybedtools.bedtool.BedTool.slop
59
+ pybedtools.bedtool.BedTool.flank
60
+ pybedtools.bedtool.BedTool.sort
61
+ pybedtools.bedtool.BedTool.random
62
+ pybedtools.bedtool.BedTool.shuffle
63
+ pybedtools.bedtool.BedTool.annotate
64
+ pybedtools.bedtool.BedTool.multi_intersect
65
+ pybedtools.bedtool.BedTool.union_bedgraphs
66
+ pybedtools.bedtool.BedTool.pair_to_bed
67
+ pybedtools.bedtool.BedTool.pair_to_pair
68
+ pybedtools.bedtool.BedTool.bam_to_bed
69
+ pybedtools.bedtool.BedTool.to_bam
70
+ pybedtools.bedtool.BedTool.bedpe_to_bam
71
+ pybedtools.bedtool.BedTool.bed6
72
+ pybedtools.bedtool.BedTool.bam_to_fastq
73
+ pybedtools.bedtool.BedTool.sequence
74
+ pybedtools.bedtool.BedTool.mask_fasta
75
+ pybedtools.bedtool.BedTool.nucleotide_content
76
+ pybedtools.bedtool.BedTool.multi_bam_coverage
77
+ pybedtools.bedtool.BedTool.tag_bam
78
+ pybedtools.bedtool.BedTool.jaccard
79
+ pybedtools.bedtool.BedTool.reldist
80
+ pybedtools.bedtool.BedTool.overlap
81
+ pybedtools.bedtool.BedTool.links
82
+ pybedtools.bedtool.BedTool.igv
83
+ pybedtools.bedtool.BedTool.window_maker
84
+ pybedtools.bedtool.BedTool.groupby
85
+ pybedtools.bedtool.BedTool.expand
86
+
87
+ Other :class:`BedTool` methods
88
+ ------------------------------
89
+ These methods are some of the ways in which :mod:`pybedtools` extend the
90
+ BEDTools suite.
91
+
92
+
93
+ Feature-by-feature operations
94
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
+ Methods that operate on a feature-by-feature basis to modify or filter features
96
+ on the fly.
97
+
98
+ .. autosummary::
99
+ :toctree: autodocs
100
+
101
+ pybedtools.bedtool.BedTool.each
102
+ pybedtools.bedtool.BedTool.filter
103
+ pybedtools.bedtool.BedTool.split
104
+ pybedtools.bedtool.BedTool.truncate_to_chrom
105
+ pybedtools.bedtool.BedTool.remove_invalid
106
+
107
+ The :mod:`pybedtools.featurefuncs` module contains some commonly-used functions
108
+ that can be passed to :meth:`BedTool.each`:
109
+
110
+ .. currentmodule:: pybedtools
111
+
112
+ .. autosummary::
113
+ :toctree:
114
+
115
+ pybedtools.featurefuncs.three_prime
116
+ pybedtools.featurefuncs.five_prime
117
+ pybedtools.featurefuncs.TSS
118
+ pybedtools.featurefuncs.extend_fields
119
+ pybedtools.featurefuncs.center
120
+ pybedtools.featurefuncs.midpoint
121
+ pybedtools.featurefuncs.normalized_to_length
122
+ pybedtools.featurefuncs.rename
123
+ pybedtools.featurefuncs.greater_than
124
+ pybedtools.featurefuncs.less_than
125
+ pybedtools.featurefuncs.normalized_to_length
126
+ pybedtools.featurefuncs.rename
127
+ pybedtools.featurefuncs.bedgraph_scale
128
+ pybedtools.featurefuncs.add_color
129
+ pybedtools.featurefuncs.gff2bed
130
+ pybedtools.featurefuncs.bed2gff
131
+
132
+
133
+
134
+ Searching for features
135
+ ~~~~~~~~~~~~~~~~~~~~~~
136
+ These methods take a single interval as input and return the intervals of the
137
+ BedTool that overlap.
138
+
139
+ This can be useful when searching across many BED files for a particular
140
+ coordinate range -- for example, they can be used identify all binding sites,
141
+ stored in many different BED files, that fall within a gene's coordinates.
142
+
143
+ .. autosummary::
144
+ :toctree: autodocs
145
+
146
+ pybedtools.bedtool.BedTool.all_hits
147
+ pybedtools.bedtool.BedTool.any_hits
148
+ pybedtools.bedtool.BedTool.count_hits
149
+ pybedtools.bedtool.BedTool.tabix_intervals
150
+ pybedtools.bedtool.BedTool.tabix
151
+ pybedtools.bedtool.BedTool.bgzip
152
+
153
+
154
+ :class:`BedTool` introspection
155
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156
+ These methods provide information on the :class:`BedTool` object.
157
+
158
+ If using :meth:`BedTool.head`, don't forget that you can index into
159
+ :class:`BedTool` objects, too.
160
+
161
+ .. autosummary::
162
+ :toctree: autodocs
163
+
164
+ pybedtools.bedtool.BedTool.head
165
+ pybedtools.bedtool.BedTool.count
166
+ pybedtools.bedtool.BedTool.field_count
167
+ pybedtools.bedtool.BedTool.file_type
168
+
169
+
170
+ Randomization helpers
171
+ ~~~~~~~~~~~~~~~~~~~~~
172
+ Helper methods useful for assessing empirical instersection
173
+ distributions between interval files.
174
+
175
+ .. autosummary::
176
+ :toctree: autodocs
177
+
178
+ pybedtools.bedtool.BedTool.parallel_apply
179
+ pybedtools.bedtool.BedTool.randomstats
180
+ pybedtools.bedtool.BedTool.randomintersection
181
+ pybedtools.bedtool.BedTool.randomintersection_bp
182
+ pybedtools.bedtool.BedTool.random_subset
183
+ pybedtools.bedtool.BedTool.random_jaccard
184
+ pybedtools.bedtool.BedTool.random_op
185
+
186
+ Managing :class:`BedTool` objects on disk
187
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
188
+ These methods are used to specify where to save results from :class:`BedTool`
189
+ operations.
190
+
191
+ .. autosummary::
192
+ :toctree: autodocs
193
+
194
+ pybedtools.bedtool.BedTool.saveas
195
+ pybedtools.bedtool.BedTool.moveto
196
+
197
+
198
+ Misc operations
199
+ ~~~~~~~~~~~~~~~
200
+ Methods that can't quite be categorized into the above sections.
201
+
202
+ .. autosummary::
203
+ :toctree: autodocs
204
+
205
+ pybedtools.bedtool.BedTool.cat
206
+ pybedtools.bedtool.BedTool.at
207
+ pybedtools.bedtool.BedTool.absolute_distance
208
+ pybedtools.bedtool.BedTool.cut
209
+ pybedtools.bedtool.BedTool.total_coverage
210
+ pybedtools.bedtool.BedTool.with_attrs
211
+ pybedtools.bedtool.BedTool.as_intervalfile
212
+ pybedtools.bedtool.BedTool.introns
213
+ pybedtools.bedtool.BedTool.set_chromsizes
214
+ pybedtools.bedtool.BedTool.print_sequence
215
+ pybedtools.bedtool.BedTool.save_seqs
216
+ pybedtools.bedtool.BedTool.seq
217
+ pybedtools.bedtool.BedTool.liftover
218
+ pybedtools.bedtool.BedTool.colormap_normalize
219
+ pybedtools.bedtool.BedTool.relative_distance
220
+
221
+ Module-level functions
222
+ ----------------------
223
+
224
+ Working with example files
225
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
226
+ :mod:`pybedtools` comes with many example files. Here are some useful
227
+ functions for accessing them.
228
+
229
+ .. autosummary::
230
+ :toctree: autodocs
231
+
232
+ pybedtools.bedtool.example_bedtool
233
+ pybedtools.filenames.list_example_files
234
+ pybedtools.filenames.example_filename
235
+
236
+ Creating :class:`Interval` objects from scratch
237
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238
+ :class:`Interval` objects are the core object in :mod:`pybedtools` to represent
239
+ a genomic interval, written in Cython for speed.
240
+
241
+ .. autosummary::
242
+ :toctree: autodocs
243
+
244
+ pybedtools.cbedtools.Interval
245
+ pybedtools.cbedtools.create_interval_from_list
246
+
247
+ :mod:`pybedtools` setup and config
248
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249
+ Use these functions right after importing in order to use custom paths or to
250
+ clean up the temp directory.
251
+
252
+ .. autosummary::
253
+ :toctree: autodocs
254
+
255
+ pybedtools.helpers.set_bedtools_path
256
+ pybedtools.helpers.get_tempdir
257
+ pybedtools.helpers.set_tempdir
258
+ pybedtools.helpers.cleanup
259
+ pybedtools.debug_mode
260
+
261
+
262
+ Working with "chromsizes" or assembly coordinate files
263
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
264
+ Many `BEDTools` programs need "genome files" or "chromsizes" files so as to
265
+ remain within the coordinates of the assembly you're working on. These
266
+ functions help manage these files.
267
+
268
+ .. autosummary::
269
+ :toctree: autodocs
270
+
271
+ pybedtools.helpers.get_chromsizes_from_ucsc
272
+ pybedtools.helpers.chromsizes
273
+ pybedtools.helpers.chromsizes_to_file
274
+
275
+
276
+ Performing operations in parallel (multiprocessing)
277
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278
+ .. autosummary::
279
+ :toctree: autodocs
280
+
281
+ pybedtools.parallel.parallel_apply
282
+
283
+ :mod:`pybedtools.contrib`
284
+ -------------------------
285
+ The :mod:`pybedtools.contrib` module contains higher-level code that leverages
286
+ :class:`BedTool` objects for common analyses.
287
+
288
+
289
+ Plotting
290
+ ~~~~~~~~
291
+ Plotting results from BEDTools/pybedtools operations is very useful for
292
+ exploring and understanding the tools as well as for teaching purposes.
293
+
294
+ .. autosummary::
295
+ :toctree: autodocs
296
+
297
+ pybedtools.contrib.plotting.Track
298
+ pybedtools.contrib.plotting.TrackCollection
299
+ pybedtools.contrib.plotting.binary_heatmap
300
+ pybedtools.contrib.plotting.binary_summary
301
+ pybedtools.contrib.plotting.BedToolsDemo
302
+ pybedtools.contrib.plotting.ConfiguredBedToolsDemo
303
+
304
+
305
+
306
+
307
+ Working with bigWig files
308
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
309
+ At this time, :mod:`pybedtools` does not support reading bigWig files, only
310
+ creating them via UCSC utilities.
311
+
312
+ .. autosummary::
313
+ :toctree: autodocs
314
+
315
+ pybedtools.contrib.bigwig.bam_to_bigwig
316
+ pybedtools.contrib.bigwig.bedgraph_to_bigwig
317
+ pybedtools.contrib.bigwig.wig_to_bigwig
318
+
319
+ Working with bigBed files
320
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
321
+ .. autosummary::
322
+ :toctree: autodocs
323
+
324
+ pybedtools.contrib.bigbed.bigbed
325
+ pybedtools.contrib.bigbed.bigbed_to_bed
326
+
327
+
328
+ :class:`IntersectionMatrix`
329
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
+ The :class:`IntersectionMatrix` class makes it easy to intersect a large number
331
+ of interval files with each other.
332
+
333
+ .. autosummary::
334
+ :toctree: autodocs
335
+
336
+ pybedtools.contrib.IntersectionMatrix
337
+
338
+ :mod:`contrib.venn_maker`
339
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
340
+ The :mod:`venn_maker` module helps you make Venn diagrams using the R package
341
+ `VennDiagram <http://www.biomedcentral.com/1471-2105/12/35>`_.
342
+
343
+ Note that Venn diagrams are not good for when you have nested intersections.
344
+ See the docs for :func:`pybedtools.contrib.venn_maker.cleaned_intersect` and
345
+ its source for more details.
346
+
347
+ .. autosummary::
348
+ :toctree: autodocs
349
+
350
+ pybedtools.contrib.venn_maker
351
+ pybedtools.contrib.venn_maker.venn_maker
352
+ pybedtools.contrib.venn_maker.cleaned_intersect
353
+
354
+ :mod:`contrib.long_range_interaction`
355
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356
+ .. autosummary::
357
+ :toctree: autodocs
358
+
359
+ pybedtools.contrib.long_range_interaction.tag_bedpe
360
+ pybedtools.contrib.long_range_interaction.cis_trans_interactions
pybedtools/source/docs/source/autodocs/pybedtools.contrib.plotting.Track.rst ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pybedtools.contrib.plotting.Track
2
+ =================================
3
+
4
+ .. currentmodule:: pybedtools.contrib.plotting
5
+
6
+ .. autoclass:: Track
7
+
8
+
9
+ .. automethod:: __init__
10
+
11
+
12
+ .. rubric:: Methods
13
+
14
+ .. autosummary::
15
+
16
+ ~Track.__init__
17
+ ~Track.add_callback
18
+ ~Track.add_checker
19
+ ~Track.autoscale
20
+ ~Track.autoscale_None
21
+ ~Track.changed
22
+ ~Track.check_update
23
+ ~Track.contains
24
+ ~Track.convert_xunits
25
+ ~Track.convert_yunits
26
+ ~Track.draw
27
+ ~Track.findobj
28
+ ~Track.format_cursor_data
29
+ ~Track.get_agg_filter
30
+ ~Track.get_alpha
31
+ ~Track.get_animated
32
+ ~Track.get_array
33
+ ~Track.get_capstyle
34
+ ~Track.get_children
35
+ ~Track.get_clim
36
+ ~Track.get_clip_box
37
+ ~Track.get_clip_on
38
+ ~Track.get_clip_path
39
+ ~Track.get_cmap
40
+ ~Track.get_contains
41
+ ~Track.get_cursor_data
42
+ ~Track.get_dashes
43
+ ~Track.get_datalim
44
+ ~Track.get_ec
45
+ ~Track.get_edgecolor
46
+ ~Track.get_edgecolors
47
+ ~Track.get_facecolor
48
+ ~Track.get_facecolors
49
+ ~Track.get_fc
50
+ ~Track.get_figure
51
+ ~Track.get_fill
52
+ ~Track.get_gid
53
+ ~Track.get_hatch
54
+ ~Track.get_in_layout
55
+ ~Track.get_joinstyle
56
+ ~Track.get_label
57
+ ~Track.get_linestyle
58
+ ~Track.get_linestyles
59
+ ~Track.get_linewidth
60
+ ~Track.get_linewidths
61
+ ~Track.get_ls
62
+ ~Track.get_lw
63
+ ~Track.get_offset_position
64
+ ~Track.get_offset_transform
65
+ ~Track.get_offsets
66
+ ~Track.get_path_effects
67
+ ~Track.get_paths
68
+ ~Track.get_picker
69
+ ~Track.get_pickradius
70
+ ~Track.get_rasterized
71
+ ~Track.get_sizes
72
+ ~Track.get_sketch_params
73
+ ~Track.get_snap
74
+ ~Track.get_tightbbox
75
+ ~Track.get_transform
76
+ ~Track.get_transformed_clip_path_and_affine
77
+ ~Track.get_transforms
78
+ ~Track.get_url
79
+ ~Track.get_urls
80
+ ~Track.get_visible
81
+ ~Track.get_window_extent
82
+ ~Track.get_xlims
83
+ ~Track.get_zorder
84
+ ~Track.have_units
85
+ ~Track.is_transform_set
86
+ ~Track.pchanged
87
+ ~Track.pick
88
+ ~Track.pickable
89
+ ~Track.properties
90
+ ~Track.remove
91
+ ~Track.remove_callback
92
+ ~Track.set
93
+ ~Track.set_aa
94
+ ~Track.set_agg_filter
95
+ ~Track.set_alpha
96
+ ~Track.set_animated
97
+ ~Track.set_antialiased
98
+ ~Track.set_antialiaseds
99
+ ~Track.set_array
100
+ ~Track.set_capstyle
101
+ ~Track.set_clim
102
+ ~Track.set_clip_box
103
+ ~Track.set_clip_on
104
+ ~Track.set_clip_path
105
+ ~Track.set_cmap
106
+ ~Track.set_color
107
+ ~Track.set_contains
108
+ ~Track.set_dashes
109
+ ~Track.set_ec
110
+ ~Track.set_edgecolor
111
+ ~Track.set_edgecolors
112
+ ~Track.set_facecolor
113
+ ~Track.set_facecolors
114
+ ~Track.set_fc
115
+ ~Track.set_figure
116
+ ~Track.set_gid
117
+ ~Track.set_hatch
118
+ ~Track.set_in_layout
119
+ ~Track.set_joinstyle
120
+ ~Track.set_label
121
+ ~Track.set_linestyle
122
+ ~Track.set_linestyles
123
+ ~Track.set_linewidth
124
+ ~Track.set_linewidths
125
+ ~Track.set_ls
126
+ ~Track.set_lw
127
+ ~Track.set_norm
128
+ ~Track.set_offset_position
129
+ ~Track.set_offsets
130
+ ~Track.set_path_effects
131
+ ~Track.set_paths
132
+ ~Track.set_picker
133
+ ~Track.set_pickradius
134
+ ~Track.set_rasterized
135
+ ~Track.set_sizes
136
+ ~Track.set_sketch_params
137
+ ~Track.set_snap
138
+ ~Track.set_transform
139
+ ~Track.set_url
140
+ ~Track.set_urls
141
+ ~Track.set_verts
142
+ ~Track.set_verts_and_codes
143
+ ~Track.set_visible
144
+ ~Track.set_zorder
145
+ ~Track.to_rgba
146
+ ~Track.update
147
+ ~Track.update_from
148
+ ~Track.update_scalarmappable
149
+
150
+
151
+
152
+
153
+
154
+ .. rubric:: Attributes
155
+
156
+ .. autosummary::
157
+
158
+ ~Track.axes
159
+ ~Track.midpoint
160
+ ~Track.mouseover
161
+ ~Track.stale
162
+ ~Track.sticky_edges
163
+ ~Track.update_dict
164
+ ~Track.zorder
165
+
166
+
pybedtools/source/docs/source/changes.rst ADDED
@@ -0,0 +1,880 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. include:: includeme.rst
2
+
3
+ Changelog
4
+ =========
5
+
6
+ Changes in v0.12.0
7
+ ------------------
8
+
9
+ 2025-03-14
10
+
11
+ * Allow ``pathlib.Path`` objects to be used in arbitrary ``BedTool`` methods.
12
+ Previously, only ``BedTool`` creation supported ``Path`` (fixes #421)
13
+ * Add support for Python 3.13, thanks to @theAeon Andrew Robbins (fixes #422)
14
+
15
+
16
+ Changes in v0.11.0
17
+ ------------------
18
+
19
+ 2025-01-02
20
+
21
+ * Add type hints and clean up code in general (big thanks to @duartemolha)
22
+ * Fix post-installation tests in Debian package (thanks @mr-c)
23
+ * Remove Python 3.8 support which reached end-of-life 2024-10-07.
24
+
25
+ Changes in v0.10.1
26
+ ------------------
27
+
28
+ 2024-04-09
29
+
30
+ * Remove last traces of Python 2.7 support by removing ``six`` dependency (thanks Valentyn Bezshapkin)
31
+ * Support building on later C++ toolchains (thanks Cameron Smith)
32
+ * Support ``pathlib.Path`` in ``BedTool.cat()`` (fixes #405)
33
+ * Improvements to testing: add tests for Python 3.12, more explicit setup/teardown
34
+
35
+ Changes in v0.9.1
36
+ -----------------
37
+
38
+ 2023-07-23
39
+
40
+ * Dropping support for Python 3.6 and 3.7
41
+ * Respect sorting of chromsize files (thanks @mgperry)
42
+ * Updated setup.py to correctly reflect the MIT license change elsewhere (`#374
43
+ <https://github.com/daler/pybedtools/issues/374>`, thanks @hyandell)
44
+ * Support plotting lengths of intervals and custom DPI (`#367
45
+ <https://github.com/daler/pybedtools/issues/367>`, `#366
46
+ <https://github.com/daler/pybedtools/issues/366>`), thanks @yunfeiguo)
47
+ * Remove outdated hard-coded check for 510 files in ``intersect`` and instead
48
+ defer to local machine's ``ulimit``
49
+ * Enabling building/installing on Python 3.11 (thanks @daz10000)
50
+ * Allow np.int64 start/stop positions to be used when creating Interval objects (`#390 <https://github.com/daler/pybedtools/issues/390>`)
51
+ * properly close filehandles in .save_seq (thanks @PeterRobots)
52
+ * include minimal pyproject.toml file (thanks @afg1)
53
+
54
+
55
+ Changes in v0.9
56
+ ---------------
57
+
58
+ 2022-01-23
59
+
60
+ The biggest change is that pybedtools is now under the MIT license, following
61
+ the lead of BEDTools itself.
62
+
63
+ Bugfixes:
64
+
65
+ * Bugfix: `Interval` objects representing VCF lines now have their `start`
66
+ attribute correctly zero-based, as indicated in the docs and consistent with
67
+ other 1-based formats. See `#355 <https://github.com/daler/pybedtools/issues/355>`_.
68
+ * Bugfix: Manually creating `Interval` objects using the `otherfields` argument
69
+ now correctly converts to C++ strings. See `#348
70
+ <https://github.com/daler/pybedtools/issues/348>`_.
71
+ * Bugfix: Workaround for `BedTool.intersect` which in some versions of BEDTools
72
+ requires a specific order of arguments. Fixes `#345
73
+ <https://github.com/daler/pybedtools/issues/345>`_ and also is a better way
74
+ of addressing `#81 <https://github.com/daler/pybedtools/issues/81>`_.
75
+
76
+ Code cleanup:
77
+
78
+ * Removed some remnants of Python 2.7 support (thanks @DavidCain)
79
+ * Updates to setup.py classifiers to better reflect state of code (thanks @DavidCain)
80
+ * Sorted filenames in setup.py to improve reproducibility of build (thanks @lamby)
81
+ * Tests converted to run on GitHub Actions (see `#339
82
+ <https://github.com/daler/pybedtools/pull/339>`_).
83
+
84
+ Changes in v0.8.2
85
+ -----------------
86
+
87
+ 2021-03-13
88
+
89
+ Minor updates
90
+
91
+ * Removed scripts directory from installed version. These are still available
92
+ in the GitHub repo, but were causing import issues with Python 3.9 and were
93
+ not well-used in the first place.
94
+ * Bugfix: unicode is better handled in gzipped files (thanks @naumenko-sa, see
95
+ `#320 <https://github.com/daler/pybedtools/pull/320>`_)
96
+ * Bugfix: correctly ignore warnings even with capital letters (thanks
97
+ @JureZmrzlikar, see `#326 <https://github.com/daler/pybedtools/pull/326>`_)
98
+ * Bugfix/improvements: update tests and code to work with Python 3.8 (see `#324
99
+ <https://github.com/daler/pybedtools/pull/324>`_). Also addresses `#322
100
+ <https://github.com/daler/pybedtools/issues/322>`_.
101
+ * Improvement: updates tests to work with bedtools v2.30
102
+ * Improvement: integration of `genomepy
103
+ <https://github.com/vanheeringen-lab/genomepy>`_, which if installed will
104
+ help retrieve chromsizes files for less commonly used assemblies (thanks
105
+ @simonvh, see `#323 <https://github.com/daler/pybedtools/pull/323/>`_)
106
+
107
+
108
+ Changes in v0.8.1
109
+ -----------------
110
+
111
+ 2019-12-27
112
+
113
+ This version has minor updates and bugfixes:
114
+
115
+ * Bugfix: Fixes to `pbt_plotting_example.py` (thanks Steffen Möllera @smoe)
116
+ * Bugfix: Using `BedTool.saveas()` when a BedTool already points to a compressed file
117
+ correctly saves (`#308 <https://github.com/daler/pybedtools/pull/308>`_)
118
+ * Improvement: Deprecate `pandas.read_table` (thanks André F. Rendeiro
119
+ @afrendeiro)
120
+ * Improvement: overhaul testing on travis-ci
121
+ * Improvement: BedTool objects support either strings or Path objects (`#287
122
+ <https://github.com/daler/pybedtools/pull/287>`_, thanks @drchsl)
123
+ * Improvement: MySQL host can be configured (`#301
124
+ <https://github.com/daler/pybedtools/pull/301>`_, thanks André F. Rendeiro
125
+ @afrendeiro)
126
+ * Improvement: Better version string parsing (`#289
127
+ <https://github.com/daler/pybedtools/pull/289>`_, thanks Steffen Möllera
128
+ @smoe), fixes `#275 <https://github.com/daler/pybedtools/issues/275>`_ and others.
129
+ * Improvement: Proper CRAM support: `#307 <https://github.com/daler/pybedtools/pull/307>`_
130
+ * Improvement: Raise an exception when the `-b` argument to `BedTool.intersect` has more
131
+ than 510 files (`#303 <https://github.com/daler/pybedtools/pull/306>`_)
132
+ * `*.h` files now included in the distribution (thanks @blaiseli)
133
+ * Improvement: Update tests to work with bedtools v2.29.2
134
+
135
+
136
+ Changes in v0.8.0
137
+ -----------------
138
+
139
+ 2018-11-28
140
+
141
+ This version further improves testing, improves the way C++ files are included
142
+ in the package, and fixes many long-standing bugs.
143
+
144
+ * Using pytest framework rather than nose for testing
145
+ * Updated `setup.py` to be more robust and to more clearly separate
146
+ "cythonization" into .cpp files
147
+ * Updated test harness for testing in independent conda environments
148
+ * All issue tests go in their own test module
149
+ * Included Python 3.7 tests (note that at the time of this writing, pysam is
150
+ not yet available on bioconda so that dependency is pip-installed in the
151
+ test) (`#254 <https://github.com/daler/pybedtools/issues/254>`_)
152
+ * Updated tests to reflect BEDTool 2.27.1 output (`#260
153
+ <https://github.com/daler/pybedtools/issues/260>`_`#261
154
+ <https://github.com/daler/pybedtools/issues/261>`_)
155
+ * Removed the `contrib.classifier` module, which has been unsupported for
156
+ a while.
157
+ * More informative error messages for UCSC tools if they're missing (`#227
158
+ <https://github.com/daler/pybedtools/issues/227>`_)
159
+ * BedTool objects that are the result of operations that create files that are
160
+ not BED/GTF/GFF/BAM can be more easily converted to pandas.DataFrame with
161
+ `disable_auto_names=True` arg to `BedTool.to_dataframe()` (`#258
162
+ <https://github.com/daler/pybedtools/issues/258>`_)
163
+ * Added aliases to existing methods to match current BEDTools commands, e.g.
164
+ the `BedTool.nucleotide_content` method can now also be called using
165
+ `BedTool.nuc` which is consistent with the `bedtools nuc` command line name.
166
+ * New wrapper for `bedtools split`. The wrapper method is called `splitbed` to
167
+ maintain backwards compatibility because `pybedtools.BedTool` objects have
168
+ long had a `split` method that splits intervals based on a custom function.
169
+ * New wrapper for `bedtools spacing`.
170
+ * `BedTool.from_dataframe` handles NaN in dataframes by replacing with `"."`,
171
+ and is more explicit about kwargs that are passed to `pandas.DataFrame`
172
+ (`#257 <https://github.com/daler/pybedtools/issues/257>`_)
173
+ * Raise FileNotFoundError when on Python 3 (thanks Gosuke Shibahara, (`#255
174
+ <https://github.com/daler/pybedtools/issues/255>`_)
175
+ * Relocated BEDTools header and .cpp files to the `pybedtools/include`
176
+ directory, so they can more easily be linked to from external packages
177
+ (`#253 <https://github.com/daler/pybedtools/issues/253>`_)
178
+ * Add test for (`#118 <https://github.com/daler/pybedtools/issues/118>`_)
179
+ * `BedTool.tabix_contigs` will list the sequence names indexed by tabix
180
+ (`#180 <https://github.com/daler/pybedtools/issues/180>`_)
181
+ * `BedTool.tabix_intervals` will return an empty generator if the coordinates
182
+ provided are not indexed, unless `check_coordinates=True` in which case the
183
+ previous behavior of raising a ValueError is triggered (`#181
184
+ <https://github.com/daler/pybedtools/issues/181>`_)
185
+ * Bugfix: Avoid "ResourceWarning: unclosed file" in `helpers.isBGZIP` (thanks
186
+ Stephen Bush)
187
+ * Bugfix: Interval objects created directly no longer have their filetype set
188
+ to None (`#217 <https://github.com/daler/pybedtools/issues/217>`_)
189
+ * Bugfix: Fixed the ability to set paths and reload module afterwards (`#218
190
+ <https://github.com/daler/pybedtools/issues/218>`_, `#220
191
+ <https://github.com/daler/pybedtools/issues/220>`_, `#222
192
+ <https://github.com/daler/pybedtools/issues/222>`_)
193
+ * Bugfix: `BedTool.head()` no longer uses an IntervalIterator (which would
194
+ check to make sure lines are valid BED/GTF/GFF/BAM/SAM). Instead, it simply
195
+ prints the first lines of the underlying file.
196
+ * Bugfix: functions passed to `BedTool.filter` and `BedTool.each` no longer
197
+ silently pass ValueErrors (`#231
198
+ <https://github.com/daler/pybedtools/issues/231>`_)
199
+ * Bugfix: Fixed IndexError in IntervalIterator if there was an empty line (`#233
200
+ <https://github.com/daler/pybedtools/issues/233>`_)
201
+ * Bugfix: Add additional constraint to SAM file detection to avoid incorrectly
202
+ detecting a BED file as SAM (`#246
203
+ <https://github.com/daler/pybedtools/issues/246>`_)
204
+ * Bugfix: accessing Interval.fields after accessing Interval.attrs no longer
205
+ raises ValueError (`#246 <https://github.com/daler/pybedtools/issues/246>`_)
206
+
207
+ Changes in v0.7.10
208
+ ------------------
209
+
210
+ 2017-05-31
211
+
212
+ Various bug fixes and some minor feature additions:
213
+
214
+ * Support for comma-separated lists for `mapBed` (thanks Chuan-Sheng Foo)
215
+ * Support many calls to `tabix_intervals` without hitting a "Too many open
216
+ files" error (`#190 <https://github.com/daler/pybedtools/issues/190>`_)
217
+ * Clarify documentation for `genome_coverage` when used with default
218
+ parameters (`#113 <https://github.com/daler/pybedtools/issues/113>`_)
219
+ * Ignore stderr from samtools on older zlib versions (`#209 <https://github.com/daler/pybedtools/issues/209>`_, thanks Gert Hulselmans)
220
+ * Support fetching all regions from a chromosome (`#201 <https://github.com/daler/pybedtools/issues/210>`_, thanks Matt Stone)
221
+ * Add wrapper for `shiftBed` (`#200 <https://github.com/daler/pybedtools/issues/200>`_, thanks Saket Choudhary)
222
+ * Fix `truncate_to_chrom` in Python 3 (`#203 <https://github.com/daler/pybedtools/issues/203>`_, thanks Saulius Lukauskas)
223
+ * When making bigWigs, use `bedSort` to ensure the sort order matches that expected by UCSC tools (`#178 <https://github.com/daler/pybedtools/issues/178>`_)
224
+ * Fix newline handling of `pysam.ctabix.TabixIterator` output (`#196 <https://github.com/daler/pybedtools/issues/196>`_)
225
+
226
+
227
+ Changes in v0.7.9
228
+ -----------------
229
+
230
+ 2017-01-25
231
+
232
+ Minor bugfix release:
233
+
234
+ * add `contrib.bigwig.bigwigtobedgraph` (thanks Justin Fear)
235
+ * fix `BedTool.seq()` in Python 3
236
+ * fix intron creation (`#182 <https://github.com/daler/pybedtools/pull/182>`_, thanks @mmendez12)
237
+ * add `six` as an explicit requirement (`#184 <https://github.com/daler/pybedtools/pull/184>`_, thanks @jrdemasi)
238
+ * improvements to setup (`<https://github.com/daler/pybedtools/issues/185>`_)
239
+ * make pandas fully optional
240
+
241
+ Changes in v0.7.8
242
+ -----------------
243
+
244
+ 2016-07-13
245
+
246
+ * Be more careful about BAM vs bgzipped files (#168)
247
+ * `BedTool.bgzip` now preserves the header when sorting
248
+ * In Python 3, parsed BEDTools help string is decoded properly
249
+ * Ensure integer number of processes in Python 3 (thanks Illa Shamovsky)
250
+ * Add details on IOError messages for broken pipe error
251
+ * Make converting to pandas.DataFrames easier with non-standard BED files (thanks Panos Firmpas)
252
+
253
+ Changes in v0.7.7
254
+ -----------------
255
+
256
+ 2016-03-11
257
+
258
+ * Chromsizes for dm6 and mm10 assemblies added to `genome_registry`
259
+ * Better Python 3 compatibility in the `long_range_interaction` module
260
+ * New `featurefuncs.UniqueID` class, useful for ensuring all features in a file
261
+ have a unique ID in their name field.
262
+ * Fix error message when a specified genome file doesn't exist (thanks Saket Choudhary)
263
+
264
+ Changes in v0.7.6
265
+ -----------------
266
+
267
+ 2016-02-01
268
+
269
+ * New module `pybedtools.contrib.long_range_interaction` for working with
270
+ HiC-like data.
271
+
272
+ Changes in v0.7.5
273
+ -----------------
274
+
275
+ 2016-01-25
276
+
277
+ * When using tabix-indexed files, `tabix` and `bgzip` are no longer required to
278
+ be installed separately. Only `pysam` is needed.
279
+
280
+ * Recent BEDTools releases support multiple files for the `-b` argument of
281
+ `bedtools intersect`. This version of `pybedtools` now supports multiple
282
+ files as well. Note that it is still possible to provide a list of strings
283
+ representing intervals as the `b` argument to `BedTool.intersect`. To
284
+ differentiate between a list of intervals and a list of filenames, the first
285
+ item converted into an `Interval` object; if it fails then consider the items
286
+ to be filenames; otherwise assume strings representing intervals. This check
287
+ only occurs if the `b` argument is a list or tuple; other iterable types are
288
+ always assumed to be intervals.
289
+
290
+ Changes in v0.7.4
291
+ -----------------
292
+
293
+ 2015-10-30
294
+
295
+ Bugfix release.
296
+
297
+ - fix `#147 <https://github.com/daler/pybedtools/issues/147>`_ so that warnings
298
+ are simply passed to the user without raising exceptions
299
+ - in setup.py, allow depedencies to have "loose" versions with suffixes like
300
+ "rc1"
301
+ - fix in `BedTool.cat()` on empty files (thanks Brad Chapman (`PR #149
302
+ <https://github.com/daler/pybedtools/pull/149>`_)
303
+
304
+ Changes in v0.7.1
305
+ -----------------
306
+
307
+ 2015-09-28
308
+
309
+ This is largely a bugfix release with the following changes:
310
+
311
+ - fix for some BAM headers (thanks Gabriel Platt)
312
+ - unified IntervalIterator to address some streaming issues (fixes #143)
313
+ - fix bug where `__add__` was not re-raising exceptions (thanks Brad Chapman
314
+ and Dan Halligan)
315
+
316
+
317
+ Changes in v0.7.0
318
+ -----------------
319
+
320
+ 2015-09-21
321
+
322
+ This release reflects a major upgrade in the underlying code in order to
323
+ support both Python 2 and Python 3 using the same code. Aside from trivial
324
+ things like converting print statements to functions and using `next()` instead
325
+ of `.next()`, this required a substantial rewrite to support the way strings
326
+ are handled in Python 3 (in Cython and wrapped C++) and how relative modules
327
+ work.
328
+
329
+ Importantly, after converting them to Python 2- and 3-compatible syntax *all
330
+ previous tests pass* so to the end user should not notice any differences
331
+ except those noted below.
332
+
333
+ Strings from Interval fields are unicode
334
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335
+ For consistency between Python 2 and 3, all strings from Interval objects are
336
+ now unicode. That is, in Python 2, previously we would get this::
337
+
338
+ >>> a = pybedtools.example_bedtool('a.bed')
339
+ >>> a[0].name
340
+ 'feature1'
341
+
342
+ Now, we get this::
343
+
344
+ >>> a = pybedtools.example_bedtool('a.bed')
345
+ >>> a[0].name
346
+ u'feature1'
347
+
348
+
349
+ samtools no longer a dependency
350
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
351
+ The dependency for samtools has been removed, which simplifies the installation
352
+ process. Instead, `pysam` is used for handling BAM files.
353
+
354
+ In order for existing tests to pass, `pysam.AlignedSegment` objects are
355
+ currently converted to `pybedtools.Interval` objects when iterating over a BAM
356
+ file. This will come at a performance cost if you are iterating over all reads
357
+ in a BAM file using the `pybedtools.BAM` object.
358
+
359
+ In the future, iterating over a BAM file will yield `pysam.AlignedSegment`
360
+ objects directly, but for now you can use the `pybedtools.BAM.pysam_bamfile`
361
+ attribute to access the underlying `pysam.AlignmentFile`
362
+
363
+ Cython no longer a dependency
364
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365
+ The Cythonized ``.cxx`` files are now shipped with the `pybedtools`
366
+ distribution, so Cython is no longer a requirement for installation.
367
+
368
+ You will however need to have Cython installed if you're developing pybedtools.
369
+
370
+ Remote BAM support clarification
371
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372
+ Previously, `pybedtools` was able to support remote BAMs by loosely wrapping
373
+ samtools, but BAM files still needed to be fully downloaded to disk before
374
+ using with BEDTools. This was done automatically, but through an inefficient
375
+ mechanism.
376
+
377
+ Pysam does support remote BAMs, and as before, a BAM file needs to be created
378
+ on disk for use with BEDTools. But now this needs to be explicitly done by the
379
+ user, which should result in better performance.
380
+
381
+
382
+ Iterating over intervals
383
+ ~~~~~~~~~~~~~~~~~~~~~~~~
384
+ Previously, when iterating over a `BedTool` object, different machinery would
385
+ be invoked depending on whether the BedTool was pointing to a file (a
386
+ cbedtools.IntervalFile would be invoked), to another iterator of Interval
387
+ objects, or to a stream like from the stdout of a BEDTools call
388
+ (cbedtools.IntervalIterator in both cases).
389
+
390
+ Everything is now an IntervalIterator, simplifying the path towards
391
+ performance optimization.
392
+
393
+ gzip support
394
+ ~~~~~~~~~~~~
395
+ Thanks to Saulius Lukauskas, gzip handling is now improved, and calling
396
+ `BedTool.saveas()` with a `.gz` extension on the filename will automatically
397
+ compress the output.
398
+
399
+ Docker
400
+ ~~~~~~
401
+ In the github repo there is a `docker` directory containing Dockerfiles to set
402
+ up isolated testing environments. These Dockerfiles also demonstrate how to set
403
+ up a complete environment starting from a base Ubuntu install.
404
+
405
+ Tests
406
+ ~~~~~
407
+ All tests from v0.6.9 (which was Python 2 only) have been made Python 2/3
408
+ compatible and all previous tests pass.
409
+
410
+ If you have docker installed, from the top level directory, you can run the
411
+ full tests like this::
412
+
413
+ cd docker
414
+ ./full-tests.sh
415
+
416
+ This will build docker containers for Python 2 and Python 3 with all
417
+ depedencies, export the parent directory to the container, and run the test
418
+ suite.
419
+
420
+
421
+ Conda packages
422
+ ~~~~~~~~~~~~~~
423
+ You can now install the latest versions of tabix, bedtools, pysam, and
424
+ pybedtools from conda, dramatically speeding up installation time. These
425
+ mechanisms are used for automated testing as well (see the ``condatest.sh``
426
+ script in the github repo).
427
+
428
+ To use these packages in your own environment(s), specify the `daler` conda
429
+ channel like this::
430
+
431
+ conda install -c daler pybedtools
432
+
433
+ Note that this will not install BEDTools or tabix unless you explicitly say
434
+ so::
435
+
436
+ conda install -c daler pybedtools bedtools tabix
437
+
438
+ .. note::
439
+
440
+ This currently only works on Linux; contributions to Mac conda recipes (see
441
+ the `conda` dir in the github repo) would be welcomed.
442
+
443
+ Changes in v0.6.9
444
+ -----------------
445
+
446
+ 2014-12-11
447
+
448
+ Minor bug fix release.
449
+
450
+ * improved the automatic field name handling when converting an interval file to
451
+ a `pandas DataFrame`.
452
+ * fixed a bug in `IntervalFile` methods `all_hits`, `any_hits` and `count_hits`
453
+ where zero-length features were being counted multiple times (thanks Brent
454
+ Pedersen and Kyle Smith)
455
+ * bgzip and tabix paths can now be configured separately (thanks Rob Beagrie)
456
+ * fixed a bug where streaming BAM files were read fully into memory (thanks
457
+ Alexey Sergushichev)
458
+
459
+ Changes in v0.6.8
460
+ -----------------
461
+
462
+ 2014-10-08
463
+
464
+ Bugfix: Thanks to Gabriel Pratt, `pybedtools` is no longer plagued by open filehandles
465
+ in the C code causing the notorious "Too many files open" error.
466
+
467
+ Changes in v0.6.7
468
+ -----------------
469
+
470
+ 2014-06-01
471
+
472
+ Now compatible with BEDTools v2.21.0.
473
+
474
+ The one exception is that the new `bedtools intersect` functionality that
475
+ allows multiple `-b` files is not yet implemented in `pybedtools`.
476
+
477
+ New features:
478
+
479
+ * `BedTool.fisher()` wraps the new BEDTools `fisher` tool. The result is
480
+ an object containing parsed results.
481
+
482
+ * `BedTool.colormap_normalize()` accepts a `percentile` argument, useful when
483
+ applying colormaps to data with a handful of extreme outliers
484
+
485
+ * `BedTool.to_datafame()` converts a `BedTool` object into a `pandas.DataFrame`
486
+ with columns named after the appropriate fields for the filetype (thanks
487
+ Radhouane Aniba for the suggestion)
488
+
489
+ * `BedTool.tail()` to complement `BedTool.head()` (thanks Radhouane Aniba for
490
+ the suggestion)
491
+
492
+ * Add hg38 and hg38.default chromsizes
493
+
494
+ Minor bug fixes:
495
+
496
+ * Ensure tuple-like args to `parallel_apply` (fixes #109)
497
+
498
+ * Temp fix for BEDTools v2.20.0 which required the `-w` arg to come before the
499
+ `-s` arg in `bedtools makewindows` (#81)
500
+
501
+ * Better (i.e., UCSC Genome Browser-compliant) defaults for `featurefuncs.expand_fields`.
502
+
503
+ * Fix for BedTool.all_hits() and any_hits() which will now show hits for
504
+ zero-length features intersecting with other zero-length features with the
505
+ same coordinates.
506
+
507
+
508
+
509
+ Changes in v0.6.6
510
+ -----------------
511
+
512
+ 2014-05-23
513
+
514
+ This is a compatibility release, updated for BEDTools v2.20.0.
515
+
516
+ There is one API change that affects the behavior of overloaded operators (that
517
+ is, using `+` and `-` with BedTool objects) when one of the BedTool objects
518
+ represents an empty file.
519
+
520
+ Assume `a` is a BedTool object representing a regular BED file but `b` is
521
+ empty. Previously:
522
+
523
+ * a + b = a
524
+ * b + a = b
525
+ * a - b = a
526
+ * b - a = a
527
+ * b - b = b
528
+ * a + a = a
529
+
530
+ The following changes have been made (indicated in **bold**), which hopefully
531
+ make more logical sense:
532
+
533
+ * **a + b = b**
534
+ * b + a = b
535
+ * a - b = a
536
+ * **b - a = b**
537
+ * b - b = b
538
+ * a + a = a
539
+
540
+ Changes in v0.6.5
541
+ -----------------
542
+
543
+ 2014-04-24
544
+
545
+ This is a minor bug-fix release:
546
+
547
+ * Fix for BedTool.all_hits() and any_hits() which will now show hits for
548
+ zero-length features with the same coordinates, like the rest of BEDTools.
549
+
550
+ * Improved error-handling to avoid Python interpreter crashing in cases when
551
+ a BED file on the filesystem becomes unavailable after a BedTool object has
552
+ been created for it.
553
+
554
+
555
+ Changes in v0.6.4
556
+ -----------------
557
+
558
+ 2014-01-08
559
+
560
+ * Full integration with BEDTools v2.18. This includes some compatibility fixes
561
+ for the new buffered output capabilities of BEDTool `intersect` and wrapping
562
+ the new `bedtools sample` tool.
563
+
564
+ * Overloaded operators (`+` and `-`) allow empty files as input, even using
565
+ BEDTools v2.18+.
566
+
567
+ * Travis-CI builds now use BEDTools v2.18+ for tests.
568
+
569
+ * Fix for :func:`pybedtools.featurefuncs.midpoint` (thanks ny-shao)
570
+
571
+ * Fix to :meth:`BedTool.randomstats` (thanks Michael Reschen)
572
+
573
+
574
+ Changes in v0.6.3
575
+ -----------------
576
+
577
+ 2013-12-16
578
+
579
+ * New :mod:`pybedtools.parallel` module for working with many operations in
580
+ parallel. See the docs for :func:`pybedtools.parallel.parallel_apply` for
581
+ details.
582
+
583
+ * :func:`pybedtools.contrib.bigbed.bigbed` for converting to bigBed format,
584
+ along with auto-SQL creation as needed.
585
+
586
+ * New function :func:`pybedtools.contrib.bigbed.bigbed_to_bed`, so now bigBed
587
+ -> BED and BED -> bigBed interconversions are trivial.
588
+
589
+ * Support for remote BAMs by passing `remote=True` when creating
590
+ a :class:`BedTool` object
591
+
592
+ * New method :meth:`BedTool.at` for subsetting a BedTool by a set of (sorted)
593
+ indexes.
594
+
595
+ * New functions :func:`featurefuncs.gff2bed` and :func:`featurefuncs.bed2gff`
596
+ for use with :meth:`BedTool.each`, for easy converting GFF/GTF to BED
597
+
598
+ * New function :func:`add_color` for applying matplotlib colormaps to BED
599
+ files; see also new method :meth:`pybedtools.BedTool.colormap_normalize`.
600
+
601
+ * :class:`pybedtools.plotting.BinaryHeatmap` class for working with results
602
+ from :meth:`BedTool.multi_intersect`.
603
+
604
+ * :meth:`BedTool.each` now also has some filter capabilities (if provided
605
+ function's return value evaluates to False, feature will be skipped)
606
+
607
+ * Better detection for samtools (thanks Luca Beltrame)
608
+
609
+ * Expand BEDToolsError (thanks Ryan Layer)
610
+
611
+ * Creating a BedTool from a list of intervals now saves to temp file instead of treating
612
+ like a consume-once iterator (#73)
613
+
614
+ * Various fixes to keyword arg handling to match semantics of BEDTools.
615
+
616
+ * Command line help and improved docs for the `peak_pie.py` script.
617
+
618
+ * Fix to GFF attributes (thanks Libor Mořkovský)
619
+
620
+ * Fix to labels in :mod:`pybedtools.contrib.venn_maker.py` (thanks Luca
621
+ Pinello)
622
+
623
+ * Make the naive scaling (to million mapped reads) in
624
+ :func:`pybedtools.contrib.bigwig.bam_to_bigwiq` optional.
625
+
626
+ * Fix for :meth:`BedTool.cat` to handle cases where at least one input is an
627
+ empty file
628
+
629
+ * Removed SciPy dependency
630
+
631
+ * Every commit is built with Travis-CI for continuous integration testing of
632
+ changes to source code.
633
+
634
+ Changes in v0.6.2
635
+ -----------------
636
+
637
+ 2012-11-05
638
+
639
+ * Wrapped new tools available in BEDTools 2.17: :meth:`BedTool.jaccard` and
640
+ :meth:`BedTool.reldist` wrap the new `bedtools jaccard` and `bedtools
641
+ reldist` respectively.
642
+
643
+ * Initial implementations of building blocks for computing statistics,
644
+ :meth:`BedTool.absolute_distance` and :meth:`BedTool.relative_distance`
645
+
646
+ * :func:`pybedtools.featurefuncs.three_prime`,
647
+ :func:`pybedtools.featurefuncs.five_prime`, and
648
+ :func:`pybedtools.featurefuncs.TSS` modifier functions that can be passed to
649
+ :meth:`BedTool.each`
650
+
651
+ * :func:`pybedtools.contrib.plotting.binary_heatmap` for visualizing results
652
+ from :meth:`BedTool.multi_intersect`
653
+
654
+ * Fixed a long-standing issue where streaming :class:`BedTool` objects did not
655
+ close their open file handles (stdout). When working with many (i.e. tens
656
+ of thousands) files, this caused the operating system to hit its open file
657
+ limit. This is now fixed.
658
+
659
+ * :meth:`BedTool.random_op`, a new mechanism for implementing operations that
660
+ you would like to apply over tens of thousands of shuffled interval files.
661
+ This makes it easy to extend the existing :mod:`pybedtools` multiprocessing
662
+ functionality.
663
+
664
+ * :func:`pybedtools.contrib.bigwig.bam_to_bigwig`, a helper function to create
665
+ a libary-size-scaled bigWig file from an input BAM file.
666
+
667
+ * :class:`pybedtools.contrib.plotting.TrackCollection` class, which handles
668
+ plotting multiple files at once, using a provided "stylesheet" configuration
669
+ to tweak colors etc.
670
+
671
+ * :class:`pybedtools.contrib.plotting.BedToolsDemo` and
672
+ :class:`pybedtools.contrib.plotting.ConfiguredBedToolsDemo`, useful for
673
+ running many graphical demos of BEDTools operations using the same
674
+ "stylesheet" configuration. Run :file:`pybedtools/contrib/plotting.py` for
675
+ a demo.
676
+
677
+ * chromsizes dictionaries for common assemblies now have a `default` attribute,
678
+ which is an OrderedDict of a default set of chromosome. For example,
679
+ ``pybedtools.chromsizes('hg19').default`` contains only the entries for the
680
+ autosomes and X and Y.
681
+
682
+ * :meth:`BedTool.cat` now works better with multiprocessing
683
+
684
+ * added `include_distribution` kwarg to :meth:`BedTool.randomstats`, which will
685
+ attach the full distribution of all the randomized files to the results
686
+ dictionary.
687
+
688
+ * New method implementing Jaccard statistic (with pvalue using randomizations):
689
+ :meth:`BedTool.random_jaccard`
690
+
691
+ * :func:`featurefuncs.extend_fields` helper function to pad fields with `'.'`,
692
+ useful for manipulating features with the :meth:`BedTool.each` method
693
+
694
+ * Fixed a bug where BAM files, when written to disk via :meth:`BedTool.saveas`,
695
+ were saved as SAM files.
696
+
697
+ * Better GTF/GFF detection, and if the input had quoted attribute values, then
698
+ the output will, too
699
+
700
+ * various minor bug fixes and improvments as documented in the github commit
701
+ logs....
702
+
703
+
704
+ Changes in v0.6.1
705
+ -----------------
706
+
707
+ 2012-05-25
708
+
709
+ * New :class:`pybedtools.contrib.plotting.Track` class allows plotting of
710
+ features with matplotlib. The `Track` class subclasses
711
+ `matplotlib.collections.PolyCollection`, making it rather fast for 1000s of
712
+ features.
713
+
714
+ * See the `scripts/pbt_plotting_example.py` script for a way of visually showing
715
+ the results of BEDTools operations . . . great for teaching BEDTools to new
716
+ users.
717
+
718
+ * New :meth:`BedTool.liftover` method (needs a chain file from UCSC and the
719
+ `liftover` program installed)
720
+
721
+ * :class:`BedTool` creation using tuples/lists of values -- everything is
722
+ converted to string before creating an :class:`Interval` object.
723
+
724
+ * bugfix: :meth:`BedTool.window_maker` now handles the `genome` kwarg correctly
725
+
726
+ * bugfix: `pybedtools.cleanup(remove_all=True)` now works correctly when using
727
+ the default temp dir
728
+
729
+
730
+ Changes in v0.6
731
+ ---------------
732
+
733
+ 2012-03-13
734
+
735
+ * Overhaul in online documentation to hopefully make functionality easier to
736
+ find and/or discover. See :ref:`pybedtools reference` for summary tables of
737
+ the different parts of :mod:`pybedtools`; each entry is linked to further
738
+ class/method/function-specific docs. These more detailed docs also have
739
+ links to view the source code from within the HTML docs for more exploration.
740
+
741
+ * :func:`pybedtools.contrib.venn_maker` function that acts as an interface to
742
+ the VennDiagram R package -- just give it some BED files and it'll do the
743
+ rest.
744
+
745
+ * Debug mode -- :func:`pybedtools.debug_mode` -- for verbose logging messages.
746
+
747
+ * Fixed an open file leak (OSError: too many open files) that occured when
748
+ opening thousands of streaming bed files in a single session.
749
+
750
+ * Initial support for tabix files. Useful for extracting features from
751
+ a single region when you don't need a full intersection.
752
+
753
+ * New :mod:`pybedtools.contrib` module (in the spirit of Django's `contrib`)
754
+ where higher-level functionality will be built.
755
+
756
+ * :class:`pybedtools.contrib.Classifier` class for identifying the classes of
757
+ intervals. Useful for making pie charts of intronic/exonic/intergenic etc
758
+ classes of peaks. Note that this is somewhat redundant with the new `mapBed`
759
+ program in BEDTools.
760
+
761
+ * Experimental :class:`pybedtools.contrib.IntersectionMatrix` class for
762
+ handling pairwise intersections of a large number of interval files --
763
+ including a local sqlite3 database to avoid re-computing already up-to-date
764
+ results.
765
+
766
+ * :class:`Interval` objects are now hashable (it's just a hash of the string
767
+ representation) so that you can use them as dictionary keys.
768
+
769
+ * :meth:`BedTool.split` method, which accepts a function returning an iterable
770
+ of :class:`Interval` objects. The function is applied to each interval.
771
+ Useful for, say, splitting each gene into TSS, TTS, upstream and downstream
772
+ features.
773
+
774
+ * :meth:`BedTool.truncate_to_chrom` method, which truncates features to the
775
+ chromosome sizes of the provided genome. Useful for when you try uploading
776
+ a MACS-generated track to the UCSC genome browser, but it complains because
777
+ peak boundaries have been extended outside chromosome boundaries . . . this
778
+ method fixes the problem.
779
+
780
+ * :class:`BedTool` objects now have full functionality of :class:`IntervalFile`
781
+ objects -- that is, they have the methods :meth:`BedTool.any_hits`,
782
+ :meth:`BedTool.all_hits`, and :meth:`BedTool.count_hits` for doing
783
+ single-interval tests. Sometimes this will be faster than using the tabix
784
+ support, sometimes it won't -- it's best to try both, depending on your data.
785
+
786
+ * String representations of :class:`Interval` objects now have a newline at the
787
+ end, just like a raw lines from a BED/GFF/VCF file. Previously, this was
788
+ inconsistent and sometimes led to extra blank lines in "streaming"
789
+ :class:`BedTool` instances . . . which in turn led to problems with BEDTools
790
+ programs using the chromsweep algorithm.
791
+
792
+ * Concatentate multiple files with one call to :meth:`BedTool.cat` (thanks Jake
793
+ Biesinger)
794
+
795
+ * Wrapped previous BEDTools programs:
796
+ * `unionBedGraphs` (:meth:`BedTool.union_bedgraphs`)
797
+ * `pairToBed` (:meth:`BedTool.pair_to_bed`)
798
+ * `pairToPair` (:meth:`BedTool.pair_to_pair`)
799
+ * `bedpeToBam` (:meth:`BedTool.bedpe_to_bam`)
800
+
801
+ * Wrapped new BEDTools programs:
802
+ * `mapBed` (:meth:`BedTool.map`)
803
+ * `clusterBed` (:meth:`BedTool.cluster`)
804
+ * `randomBed` (:meth:`BedTool.random`)
805
+ * `multiIntersectBed` (:meth:`BedTool.multi_intersect`)
806
+ * `expandCols` (:meth:`BedTool.expand`)
807
+ * `windowMaker` (:meth:`BedTool.window_maker`)
808
+ * `bamToFastq` (:meth:`BedTool.bam_to_fastq`)
809
+
810
+ * Made venn_gchart and venn_mpl tests more stable
811
+
812
+ * Automatic documenting of which args are passed implicitly for BedTool method
813
+ calls
814
+
815
+ * More robust mechanisms for specifying custom paths for BEDTools installation
816
+ as well as optional tabix, samtools, and R installations. This makes it
817
+ easier to explicitly specify which versions of the tools to use.
818
+
819
+ * Improvements to GFF attributes: handle unescaped "=" (from sim4db GFFs) and
820
+ make Attribute class properly dict-like (thanks Libor Mořkovský)
821
+
822
+ Changes in v0.5.5
823
+ -----------------
824
+
825
+ 2011-09-17
826
+
827
+ * Use `additional_args` kwarg to pass arguments verbatim to the underlying
828
+ BEDTools programs. This is necessary for arguments like
829
+ `genomeCoverageBed`'s `-5` argument, since `5=True` is not a valid Python
830
+ expression. For example, you can use::
831
+
832
+ import pybedtools
833
+ a = pybedtools.example_bedtool('a.bed')
834
+ a.genome_coverage(bg=True, strand='+', genome='hg19', additional_args='-5')
835
+
836
+ * Brent Pedersen added support for just 2 BED files in the Venn diagram scripts
837
+
838
+ * :meth:`BedTool.all_hits` uses the underlying BEDTools C++ API to get all hits
839
+ in a file for a particular Interval::
840
+
841
+ a = pybedtools.example_bedtool('a.bed')
842
+ interval = Interval('chr1', 1, 5000)
843
+ a.all_hits(interval)
844
+
845
+ * New semantics for comparisons of Interval objects. Visual documentation of
846
+ this coming soon.
847
+
848
+ * More tests for latest BEDTools code
849
+
850
+ * Interval instances are now pickleable; they can now be used across processes
851
+ for parallel code.
852
+
853
+
854
+ Changes in v0.5
855
+ ---------------
856
+
857
+ 2011-05-03
858
+
859
+ * support for running random intersections in parallel. See
860
+ :meth:`BedTool.randomstats` and :meth:`BedTool.randomintersection` (thanks,
861
+ Jake Biesinger)
862
+
863
+ * Cython `Interval.__copy__()` for compatibility with `copy` module
864
+
865
+ * `seek()` and `rewind()` methods for `IntervalFile` class, used for Aaron
866
+ Quinlan's new chromsweep algorithm (https://github.com/arq5x/chrom_sweep)
867
+ (thanks, Aaron)
868
+
869
+ * support and tests for new BEDTools programs `multiBamCov`, `tagBam`, and `nucBed`
870
+
871
+ * `output="out.bed"` kwarg for all wrapped methods for explicitly specifying
872
+ where to save output -- no more moving tempfiles
873
+
874
+ * docs improvements:
875
+ * direct comparison with a shell script to illustrate benefit of
876
+ `pybedtools`; see :ref:`shell_comparison`
877
+ * more installation details
878
+ * 0- and 1-based coordinates discussed early on (the 3 brief examples page,
879
+ :ref:`3examples`)
880
+ * development history and open collaboration model (see :ref:`devmodel`)
pybedtools/source/docs/source/conf.py ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pybedtools documentation build configuration file, created by
4
+ # sphinx-quickstart on Wed Dec 22 17:39:12 2010.
5
+ #
6
+ # This file is execfile()d with the current directory set to its containing dir.
7
+ #
8
+ # Note that not all possible configuration values are present in this
9
+ # autogenerated file.
10
+ #
11
+ # All configuration values have a default; values that are commented out
12
+ # serve to show the default.
13
+
14
+ import sys, os
15
+
16
+ # If extensions (or modules to document with autodoc) are in another directory,
17
+ # add these directories to sys.path here. If the directory is relative to the
18
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
19
+ sys.path.insert(0, os.path.abspath('../..'))
20
+
21
+ from pybedtools import __version__ as version
22
+
23
+ # -- General configuration -----------------------------------------------------
24
+
25
+ # If your documentation needs a minimal Sphinx version, state it here.
26
+ #needs_sphinx = '1.0'
27
+
28
+ # Add any Sphinx extension module names here, as strings. They can be extensions
29
+ # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
30
+ extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary',
31
+ 'sphinx.ext.doctest', 'sphinx.ext.todo',
32
+ 'sphinx.ext.coverage','sphinx.ext.viewcode', 'numpydoc']
33
+
34
+ doctest_test_doctest_blocks = 'default'
35
+
36
+ # From http://stackoverflow.com/questions/12206334/\
37
+ # sphinx-autosummary-toctree-contains-refere\
38
+ # nce-to-nonexisting-document-warnings
39
+ numpydoc_show_class_members = False
40
+
41
+ # this is needed to get the autodoc_source.rst doctests to run
42
+ doctest_global_setup = """
43
+ from pybedtools import *
44
+ import pybedtools
45
+ """
46
+
47
+ autosummary_generate = True
48
+
49
+ # Add any paths that contain templates here, relative to this directory.
50
+ templates_path = ['_templates']
51
+
52
+ # The suffix of source filenames.
53
+ source_suffix = '.rst'
54
+
55
+ # The encoding of source files.
56
+ #source_encoding = 'utf-8-sig'
57
+
58
+ # The master toctree document.
59
+ master_doc = 'index'
60
+
61
+ # General information about the project.
62
+ project = 'pybedtools'
63
+ copyright = '2010-2015, Ryan Dale'
64
+
65
+ # The version info for the project you're documenting, acts as replacement for
66
+ # |version| and |release|, also used in various other places throughout the
67
+ # built documents.
68
+ #
69
+ # The short X.Y version.
70
+ version = version
71
+ # The full version, including alpha/beta/rc tags.
72
+ release = version
73
+
74
+ # The language for content autogenerated by Sphinx. Refer to documentation
75
+ # for a list of supported languages.
76
+ #language = None
77
+
78
+ # There are two options for replacing |today|: either, you set today to some
79
+ # non-false value, then it is used:
80
+ #today = ''
81
+ # Else, today_fmt is used as the format for a strftime call.
82
+ #today_fmt = '%B %d, %Y'
83
+
84
+ # List of patterns, relative to source directory, that match files and
85
+ # directories to ignore when looking for source files.
86
+ exclude_patterns = []
87
+
88
+ # The reST default role (used for this markup: `text`) to use for all documents.
89
+ default_role = 'file'
90
+
91
+ # If true, '()' will be appended to :func: etc. cross-reference text.
92
+ add_function_parentheses = True
93
+
94
+ # If true, the current module name will be prepended to all description
95
+ # unit titles (such as .. function::).
96
+ #add_module_names = True
97
+
98
+ # If true, sectionauthor and moduleauthor directives will be shown in the
99
+ # output. They are ignored by default.
100
+ #show_authors = False
101
+
102
+ # The name of the Pygments (syntax highlighting) style to use.
103
+ #pygments_style = 'sphinx'
104
+ highlight_language = 'python'
105
+ html_use_smartypants = False
106
+
107
+ # A list of ignored prefixes for module index sorting.
108
+ #modindex_common_prefix = []
109
+
110
+
111
+ # -- Options for HTML output ---------------------------------------------------
112
+
113
+ # The theme to use for HTML and HTML Help pages. See the documentation for
114
+ # a list of builtin themes.
115
+ #html_theme = 'nature'
116
+
117
+ # Theme options are theme-specific and customize the look and feel of a theme
118
+ # further. For a list of options available for each theme, see the
119
+ # documentation.
120
+ #html_theme_options = {}
121
+
122
+ # Add any paths that contain custom themes here, relative to this directory.
123
+ #html_theme_path = ['_themes']
124
+
125
+ # The name for this set of Sphinx documents. If None, it defaults to
126
+ # "<project> v<release> documentation".
127
+ #html_title = None
128
+
129
+ # A shorter title for the navigation bar. Default is the same as html_title.
130
+ #html_short_title = None
131
+
132
+ # The name of an image file (relative to this directory) to place at the top
133
+ # of the sidebar.
134
+ #html_logo = None
135
+
136
+ # The name of an image file (within the static path) to use as favicon of the
137
+ # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
138
+ # pixels large.
139
+ #html_favicon = None
140
+
141
+ # Add any paths that contain custom static files (such as style sheets) here,
142
+ # relative to this directory. They are copied after the builtin static files,
143
+ # so a file named "default.css" will overwrite the builtin "default.css".
144
+ html_static_path = ['_static']
145
+
146
+ # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
147
+ # using the given strftime format.
148
+ html_last_updated_fmt = '%b %d, %Y'
149
+
150
+ # If true, SmartyPants will be used to convert quotes and dashes to
151
+ # typographically correct entities.
152
+ #html_use_smartypants = True
153
+
154
+ # Custom sidebar templates, maps document names to template names.
155
+ #html_sidebars = {}
156
+
157
+ # Additional templates that should be rendered to pages, maps page names to
158
+ # template names.
159
+ #html_additional_pages = {}
160
+
161
+ # If false, no module index is generated.
162
+ #html_domain_indices = True
163
+
164
+ # If false, no index is generated.
165
+ #html_use_index = True
166
+
167
+ # If true, the index is split into individual pages for each letter.
168
+ #html_split_index = False
169
+
170
+ # If true, links to the reST sources are added to the pages.
171
+ #html_show_sourcelink = True
172
+
173
+ # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
174
+ #html_show_sphinx = True
175
+
176
+ # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
177
+ #html_show_copyright = True
178
+
179
+ # If true, an OpenSearch description file will be output, and all pages will
180
+ # contain a <link> tag referring to it. The value of this option must be the
181
+ # base URL from which the finished HTML is served.
182
+ #html_use_opensearch = ''
183
+
184
+ # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
185
+ #html_file_suffix = ''
186
+
187
+ # Output file base name for HTML help builder.
188
+ htmlhelp_basename = 'pybedtoolsdoc'
189
+
190
+
191
+ # -- Options for LaTeX output --------------------------------------------------
192
+
193
+ # The paper size ('letter' or 'a4').
194
+ #latex_paper_size = 'letter'
195
+
196
+ # The font size ('10pt', '11pt' or '12pt').
197
+ #latex_font_size = '10pt'
198
+
199
+ # Grouping the document tree into LaTeX files. List of tuples
200
+ # (source start file, target name, title, author, documentclass [howto/manual]).
201
+ latex_documents = [
202
+ ('index', 'pybedtools.tex', 'pybedtools Documentation',
203
+ 'Ryan Dale', 'manual'),
204
+ ]
205
+
206
+ # The name of an image file (relative to this directory) to place at the top of
207
+ # the title page.
208
+ #latex_logo = None
209
+
210
+ # For "manual" documents, if this is true, then toplevel headings are parts,
211
+ # not chapters.
212
+ latex_use_parts = True
213
+
214
+ # If true, show page references after internal links.
215
+ #latex_show_pagerefs = False
216
+
217
+ # If true, show URL addresses after external links.
218
+ #latex_show_urls = False
219
+
220
+ # Additional stuff for the LaTeX preamble.
221
+ #latex_preamble = ''
222
+
223
+ # Documents to append as an appendix to all manuals.
224
+ #latex_appendices = []
225
+
226
+ # If false, no module index is generated.
227
+ #latex_domain_indices = True
228
+
229
+
230
+ # -- Options for manual page output --------------------------------------------
231
+
232
+ # One entry per manual page. List of tuples
233
+ # (source start file, name, description, authors, manual section).
234
+ man_pages = [
235
+ ('index', 'pybedtools', 'pybedtools Documentation',
236
+ ['Ryan Dale'], 1)
237
+ ]
pybedtools/source/docs/source/create-a-bedtool-tutorial.rst ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. include:: includeme.rst
2
+
3
+ Create a :class:`BedTool`
4
+ -------------------------
5
+ First, follow the :ref:`installation` instructions if you haven't already
6
+ done so to install both BEDTools_ and :mod:`pybedtools`.
7
+
8
+ Then import the :mod:`pybedtools` module and make a new :class:`BedTool`. A
9
+ :class:`BedTool` object encapsulates all of the available BEDTools programs and
10
+ makes them easier to use within Python. Most of the time when working with
11
+ :mod:`pybedtools` you'll be using :class:`BedTool` objects. In general, a
12
+ single :class:`BedTool` object points to an interval file (BED, GFF, GTF, VCF,
13
+ SAM, or BAM format).
14
+
15
+ ::
16
+
17
+ >>> import pybedtools
18
+
19
+ >>> # use a BED file that ships with pybedtools...
20
+ >>> a = pybedtools.example_bedtool('a.bed')
21
+
22
+ >>> # ...or use your own by passing a filename
23
+ >>> a = pybedtools.BedTool('peaks.bed')
24
+
25
+ This documentation uses example files that ship with :mod:`pybedtools`. To
26
+ access these files from their installation location, we use the
27
+ :func:`example_bedtool` function. This is convenient because if you copy-paste
28
+ the examples, they will work. When using the :func:`example_bedtool` function,
29
+ the resulting :class:`BedTool` object will point to the corresponding file in
30
+ the `test/data` directory of your :mod:`pybedtools` installation. If you would
31
+ rather learn using your own files, just pass the filename to a new
32
+ :class:`BedTool`, like the above example.
33
+
34
+ You can use any file that BEDTools_ supports -- this includes BED, VCF,
35
+ GFF, and gzipped versions of any of these. See :ref:`Creating a BedTool`
36
+ for more on the different ways of creating a :class:`BedTool`, including
37
+ from iterators and directly from a string.
38
+
39
+ Now, let's see how to do a common task performed on BED files: intersections.
pybedtools/source/docs/source/default-arguments.rst ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. currentmodule:: pybedtools
2
+
3
+
4
+ Default arguments
5
+ =================
6
+ Recall in the earlier :ref:`intersections` section that we passed the `u=True` argument to :meth:`a.intersect`:
7
+
8
+ .. doctest::
9
+
10
+ >>> import pybedtools
11
+ >>> a = pybedtools.example_bedtool('a.bed')
12
+ >>> b = pybedtools.example_bedtool('b.bed')
13
+ >>> a_with_b = a.intersect(b, u=True)
14
+
15
+ Let's do the same thing but use different variable names for the :class:`BedTool` objects so that
16
+ the next section is less confusing:
17
+
18
+ .. doctest::
19
+
20
+ >>> import pybedtools
21
+ >>> exons = pybedtools.example_bedtool('a.bed')
22
+ >>> snps = pybedtools.example_bedtool('b.bed')
23
+ >>> exons_with_snps = exons.intersect(snps, u=True)
24
+
25
+
26
+ While we're on the subject of arguments, note that we didn't have to specify
27
+ `-a` or `-b` arguments, like you would need if calling `intersectBed` from the
28
+ command line. In other words, since `exons` refers to the file `a.bed` and
29
+ `snps` refers to the file `b.bed`, the following line::
30
+
31
+ >>> exons_with_snps = exons.intersect(snps, u=True)
32
+
33
+ is equivalent to the command line usage of::
34
+
35
+ $ intersectBed -a a.bed -b b.bed -u > tmpfile
36
+
37
+ But we didn't have to explicitly pass the argument for `-a` because
38
+ :class:`BedTool` objects make some assumptions for convenience.
39
+
40
+ We're calling a method on the :class:`BedTool` object `exons`, so
41
+ :mod:`pybedtools` assumes that the file `exons` points to (stored in the
42
+ attribute `exons.fn`) is the one we want to use as input. So by default, we
43
+ don't need to explicitly give the keyword argument `a=exons.fn` because the
44
+ :meth:`exons.intersect` method does so automatically.
45
+
46
+ We're also calling a method that takes a second bed file as input -- other
47
+ such methods include :meth:`BedTool.subtract` and :meth:`BedTool.closest`,
48
+ and others. For these methods, in addition to assuming `-a` is taken care
49
+ of by the :attr:`BedTool.fn` attribute, :mod:`pybedtools` also assumes the
50
+ first unnamed argument to these methods are the second file you want to
51
+ operate on (and if you pass a :class:`BedTool`, it'll automatically use the
52
+ file in the `fn` attribute of that :class:`BedTool`).
53
+
54
+ An example may help to illustrate: these different ways of calling
55
+ :meth:`BedTool.intersect` all have the same results, with the first version
56
+ being the most compact (and probably most convenient):
57
+
58
+ .. doctest::
59
+
60
+ >>> # these all have identical results
61
+ >>> x1 = exons.intersect(snps)
62
+ >>> x2 = exons.intersect(a=exons.fn, b=snps.fn)
63
+ >>> x3 = exons.intersect(b=snps.fn)
64
+ >>> x4 = exons.intersect(snps, a=exons.fn)
65
+ >>> x1 == x2 == x3 == x4
66
+ True
67
+
68
+ Note that `a.intersect(a=a.fn, b)` is not a valid Python expression, since
69
+ non-keyword arguments must come before keyword arguments, but
70
+ `a.intersect(b, a=a.fn)` works fine.
71
+
72
+ If you're ever unsure, the docstring for these methods indicates which, if
73
+ any, arguments are used as default. For example, in the
74
+ :meth:`BedTool.intersect` help, it says::
75
+
76
+ For convenience, the file or stream this BedTool points to is implicitly
77
+ passed as the -a argument to intersectBed
78
+
79
+ OK, enough about arguments for now, but you can read more about them in
80
+ :ref:`similarity principle`, :ref:`default args principle` and :ref:`non
81
+ defaults principle`.
pybedtools/source/docs/source/each.rst ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. include:: includeme.rst
2
+
3
+ Each
4
+ ====
5
+ Similar to :meth:`BedTool.filter`, which applies a function to return True
6
+ or False given an :class:`Interval`, the :meth:`BedTool.each` method applies a
7
+ function to return a new, possibly modified :class:`Interval`.
8
+
9
+ The :meth:`BedTool.each` method applies a function to every feature. Like
10
+ :meth:`BedTool.filter`, you can use your own function or some pre-defined
11
+ ones in the :mod:`featurefuncs` module. Also like :meth:`filter`, `*args`
12
+ and `**kwargs` are sent to the function.
13
+
14
+ .. doctest::
15
+ :options: +NORMALIZE_WHITESPACE
16
+
17
+ >>> a = pybedtools.example_bedtool('a.bed')
18
+ >>> b = pybedtools.example_bedtool('b.bed')
19
+
20
+ >>> # The results of an "intersect" with c=True will return features
21
+ >>> # with an additional field representing the counts.
22
+ >>> with_counts = a.intersect(b, c=True)
23
+
24
+ Let's define a function that will take the number of counts in each feature
25
+ as calculated above and divide by the number of bases in that feature. We
26
+ can also supply an optional scalar, like 0.001, to get the results in
27
+ "number of intersections per kb". We then insert that value into the score
28
+ field of the feature. Here's the function:
29
+
30
+ .. doctest::
31
+
32
+ >>> def normalize_count(feature, scalar=0.001):
33
+ ... """
34
+ ... assume feature's last field is the count
35
+ ... """
36
+ ... counts = float(feature[-1])
37
+ ... normalized = round(counts / (len(feature) * scalar), 2)
38
+ ...
39
+ ... # need to convert back to string to insert into feature
40
+ ... feature.score = str(normalized)
41
+ ... return feature
42
+
43
+ And we apply it like this:
44
+
45
+ .. doctest::
46
+ :options: +NORMALIZE_WHITESPACE
47
+
48
+ >>> normalized = with_counts.each(normalize_count)
49
+ >>> print(normalized)
50
+ chr1 1 100 feature1 0.0 + 0
51
+ chr1 100 200 feature2 10.0 + 1
52
+ chr1 150 500 feature3 2.86 - 1
53
+ chr1 900 950 feature4 20.0 + 1
54
+ <BLANKLINE>
55
+
56
+ Similar to :meth:`BedTool.filter`, we could have used the Python built-in
57
+ function `map` to map a function to each :class:`Interval`. In fact, this can
58
+ still be useful if you don't want a :class:`BedTool` object as a result. For
59
+ example::
60
+
61
+ >>> feature_lengths = map(len, a)
62
+
63
+ However, the :meth:`BedTool.each` method returns a :class:`BedTool` object,
64
+ which can be used in a chain of commands, e.g., ::
65
+
66
+ >>> a.intersect(b).each(normalize_count).filter(lamda x: float(x[4]) < 1e-5)
pybedtools/source/docs/source/example-script ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import pybedtools
3
+
4
+ # Create a BedTool for the GFF file of annotations
5
+ g = pybedtools.BedTool('example.gff')
6
+
7
+
8
+ # Set up two functions that will filter and then rename features to set up for
9
+ # merging
10
+
11
+
12
+ def renamer(x):
13
+ """
14
+ *x* is an Interval object representing a GFF feature.
15
+
16
+ Renames the feature after the feature type; this is needed for when
17
+ .merge() combines names together in a later step.
18
+ """
19
+
20
+ # This illustrates setting and getting fields in an Interval object based
21
+ # on attribute or index
22
+ x.name = x[2]
23
+ return x
24
+
25
+
26
+ def filter_func(x):
27
+ """
28
+ *x* is an Interval object representing a GFF feature.
29
+
30
+ This filter function will only pass features of type "intron" or "exon"
31
+ """
32
+ if x[2] in ('intron', 'exon'):
33
+ return True
34
+ return False
35
+
36
+
37
+ # Filter and rename the GFF features by passing the above functions to
38
+ # .filter() and .each(). Note that since each method returns a new BedTool,
39
+ # methods can be chained together
40
+ g2 = g.filter(filter_func).each(renamer)
41
+
42
+ # Save a copy of the new GFF file for later inspection
43
+ g2 = g2.saveas('edited.gff')
44
+
45
+
46
+ # Here we call mergeBed, which operates on the file pointed to by g2
47
+ # (that is, 'edited.gff').
48
+ #
49
+ # We use several options for BEDTools mergeBed:
50
+ #
51
+ # `nms` combines names of merged features (after filtering and renaming, this
52
+ # is either "intron" or "exon") into a semicolon-delimited list;
53
+ #
54
+ # d=-1 does not merge bookended features together;
55
+ #
56
+ # s=True ensures a stranded merge;
57
+ #
58
+ # scores='sum' ensures a valid BED file result, with a score field before the
59
+ # strand field
60
+ #
61
+ merged = g2.merge(nms=True, d=-1, s=False, scores='sum')
62
+
63
+ # Next, we intersect a BAM file with the merged features. Here, we explicitly
64
+ # specify the `abam` and `b` arguments, ensure stranded intersections, use
65
+ # BED-format output, and report the entire a and b features in the output:
66
+ #
67
+ reads_in_features = merged.intersect(abam='example.bam',
68
+ b=merged.fn,
69
+ s=True,
70
+ bed=True,
71
+ wao=True)
72
+
73
+ # Set up a dictionary to hold counts
74
+ from collections import defaultdict
75
+ results = defaultdict(int)
76
+
77
+ # Iterate through the intersected reads, parse out the names of the features
78
+ # they intersected, and increment counts in the dictionary. This illustrates
79
+ # how BedTool objects follow the iterator protocol, each time yielding an
80
+ # Interval object:
81
+ #
82
+ total = 0.0
83
+ for intersected_read in reads_in_features:
84
+ total += 1
85
+
86
+ # Extract the name of the feature this read intersected by indexing into
87
+ # the Interval
88
+ intersected_feature = feature[-4]
89
+
90
+ # Convert names like "intron;intron;intron", which indicates overlapping
91
+ # isoforms or genes all with introns in this region, to the simple class of
92
+ # "intron"
93
+ key = ';'.join(sorted(list(set(intersected_with.split(';')))))
94
+
95
+ # Increment the count for this class
96
+ results[key] += 1
97
+
98
+ # Rename the "." key to something more meaningful
99
+ results['intergenic'] = results.pop('.')
100
+
101
+ # Add the total to the dictionary
102
+ results['total'] = int(total)
103
+
104
+ print results
105
+
106
+ # Delete any temporary files created
107
+ pybedtools.cleanup()
pybedtools/source/docs/source/example-script-nocomments ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pybedtools
2
+
3
+ g = pybedtools.BedTool('example.gff')
4
+
5
+ def renamer(x):
6
+ x.name = x[2]
7
+ return x
8
+
9
+ def filter_func(x):
10
+ if x[2] in ('intron', 'exon'):
11
+ return True
12
+ return False
13
+
14
+
15
+ g2 = g.filter(filter_func).each(renamer)
16
+ g2 = g2.saveas('edited.gff')
17
+ merged = g2.merge(nms=True, d=-1, s=False, scores='sum')
18
+ reads_in_features = merged.intersect(abam='example.bam',
19
+ b=merged.fn,
20
+ s=True,
21
+ bed=True,
22
+ wao=True)
23
+
24
+ from collections import defaultdict
25
+ results = defaultdict(int)
26
+ total = 0.0
27
+ for intersected_read in reads_in_features:
28
+ total += 1
29
+ intersected_feature = feature[-4]
30
+ key = ';'.join(sorted(list(set(intersected_with.split(';')))))
31
+ results[key] += 1
32
+
33
+ results['intergenic'] = results.pop('.')
34
+ results['total'] = int(total)
35
+ print results
36
+
37
+ pybedtools.cleanup()
pybedtools/source/docs/source/example_3 ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ """
4
+ Example from pybedtools documentation: find reads in introns and exons using
5
+ multiple CPUs.
6
+
7
+ Prints a tab-separated file containing class (exon, intron, both) and number of
8
+ reads in each class.
9
+ """
10
+ import pybedtools
11
+ import argparse
12
+ import os
13
+ import sys
14
+ import multiprocessing
15
+
16
+ if __name__ == "__main__":
17
+
18
+ ap = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]), usage=__doc__)
19
+ ap.add_argument(
20
+ "--gff", required=True, help="GFF or GTF file containing annotations"
21
+ )
22
+ ap.add_argument(
23
+ "--bam", required=True, help="BAM file containing reads to be counted"
24
+ )
25
+ ap.add_argument(
26
+ "--stranded",
27
+ action="store_true",
28
+ help="Use strand-specific merging and overlap. " "Default is to ignore strand",
29
+ )
30
+ ap.add_argument(
31
+ "--processes",
32
+ default=1,
33
+ type=int,
34
+ help="Number of processes to use in parallel.",
35
+ )
36
+ ap.add_argument(
37
+ "-v", "--verbose", action="store_true", help="Verbose (goes to stderr)"
38
+ )
39
+ args = ap.parse_args()
40
+
41
+ gff = args.gff
42
+ bam = args.bam
43
+ stranded = args.stranded
44
+
45
+ if args.processes > 3:
46
+ print(
47
+ "Only need 3 processes (one each for exon, intron, both), so "
48
+ "resetting processes from {0} to 3".format(args.processes)
49
+ )
50
+ args.processes = 3
51
+
52
+ def featuretype_filter(feature, featuretype):
53
+ """
54
+ Only passes features with the specified *featuretype*
55
+ """
56
+ if feature[2] == featuretype:
57
+ return True
58
+ return False
59
+
60
+ def subset_featuretypes(featuretype):
61
+ """
62
+ Returns the filename containing only `featuretype` features.
63
+ """
64
+ return g.filter(featuretype_filter, featuretype).saveas().fn
65
+
66
+ def count_reads_in_features(features):
67
+ """
68
+ Callback function to count reads in features
69
+ """
70
+ return (
71
+ pybedtools.BedTool(bam).intersect(
72
+ features, s=stranded, bed=True, stream=True
73
+ )
74
+ ).count()
75
+
76
+ # Some GFF files have invalid entries -- like chromosomes with negative coords
77
+ # or features of length = 0. This line removes them (the `remove_invalid`
78
+ # method) and saves the result in a tempfile
79
+ g = pybedtools.BedTool(gff).remove_invalid().saveas()
80
+
81
+ # Set up pool of workers
82
+ with multiprocessing.Pool(processes=args.processes) as pool:
83
+
84
+ # Get separate files for introns and exons in parallel
85
+ featuretypes = ["intron", "exon"]
86
+ introns, exons = pool.map(subset_featuretypes, featuretypes)
87
+
88
+ # Since `subset_featuretypes` returns filenames, we convert to BedTool objects
89
+ # to do intersections below.
90
+ introns = pybedtools.BedTool(introns)
91
+ exons = pybedtools.BedTool(exons)
92
+
93
+ # Identify unique and shared regions using bedtools commands subtract, merge,
94
+ # and intersect.
95
+ exon_only = exons.subtract(introns).merge()
96
+ intron_only = introns.subtract(exons).merge()
97
+ intron_and_exon = exons.intersect(introns).merge()
98
+
99
+ # Do intersections with BAM file in parallel. Note that we're passing filenames
100
+ # to multiprocessing.Pool rather than BedTool objects.
101
+ features = (exon_only.fn, intron_only.fn, intron_and_exon.fn)
102
+
103
+ # Run count_reads_in_features in parallel over features
104
+ results = pool.map(count_reads_in_features, features)
105
+
106
+ labels = ("exon_only", "intron_only", "intron_and_exon")
107
+
108
+ for label, reads in zip(labels, results):
109
+ print("{0}\t{1}".format(label, reads))
pybedtools/source/docs/source/example_3_no_comments ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import multiprocessing
3
+ import pybedtools
4
+
5
+ gff = pybedtools.example_filename('gdc.gff')
6
+ bam = pybedtools.example_filename('gdc.bam')
7
+
8
+ g = pybedtools.BedTool(gff).remove_invalid().saveas()
9
+
10
+
11
+ def featuretype_filter(feature, featuretype):
12
+ if feature[2] == featuretype:
13
+ return True
14
+ return False
15
+
16
+
17
+ def subset_featuretypes(featuretype):
18
+ result = g.filter(featuretype_filter, featuretype).saveas()
19
+ return pybedtools.BedTool(result.fn)
20
+
21
+
22
+ def count_reads_in_features(features_fn):
23
+ """
24
+ Callback function to count reads in features
25
+ """
26
+
27
+ return pybedtools.BedTool(bam).intersect(
28
+ b=features_fn,
29
+ stream=True).count()
30
+
31
+
32
+ pool = multiprocessing.Pool()
33
+
34
+ featuretypes = ('intron', 'exon')
35
+ introns, exons = pool.map(subset_featuretypes, featuretypes)
36
+
37
+ exon_only = exons.subtract(introns).merge().remove_invalid().saveas().fn
38
+ intron_only = introns.subtract(exons).merge().remove_invalid().saveas().fn
39
+ intron_and_exon = exons.intersect(introns).merge().remove_invalid().saveas().fn
40
+
41
+ features = (exon_only, intron_only, intron_and_exon)
42
+ results = pool.map(count_reads_in_features, features)
43
+
44
+ labels = (' exon only:',
45
+ ' intron only:',
46
+ 'intron and exon:')
47
+
48
+ for label, reads in zip(labels, results):
49
+ sys.stdout.write('%s %s\n' % (label, reads))
pybedtools/source/docs/source/filtering.rst ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .. include:: includeme.rst
3
+
4
+ .. _filtering:
5
+
6
+ Filtering
7
+ ~~~~~~~~~
8
+ The :meth:`BedTool.filter` method lets you pass in a function that accepts an
9
+ :class:`Interval` as its first argument and returns True for False. This
10
+ allows you to perform "grep"-like operations on :class:`BedTool` objects. For
11
+ example, here's how to get a new :class:`BedTool` containing features from `a`
12
+ that are more than 100 bp long:
13
+
14
+ .. doctest::
15
+ :options: +NORMALIZE_WHITESPACE
16
+
17
+ >>> a = pybedtools.example_bedtool('a.bed')
18
+ >>> b = a.filter(lambda x: len(x) > 100)
19
+ >>> print(b)
20
+ chr1 150 500 feature3 0 -
21
+ <BLANKLINE>
22
+
23
+ The :meth:`filter` method will pass its `*args` and `**kwargs` to the function
24
+ provided. So here is a more generic case, where the function is defined once
25
+ and different arguments are passed in for filtering on different lengths:
26
+
27
+ .. doctest::
28
+ :options: +NORMALIZE_WHITESPACE
29
+
30
+ >>> def len_filter(feature, L):
31
+ ... "Returns True if feature is longer than L"
32
+ ... return len(feature) > L
33
+
34
+ Now we can pass different lengths without defining a new function for each
35
+ length of interest, like this:
36
+
37
+ .. doctest::
38
+ :options: +NORMALIZE_WHITESPACE
39
+
40
+ >>> a = pybedtools.example_bedtool('a.bed')
41
+
42
+ >>> print(a.filter(len_filter, L=10))
43
+ chr1 1 100 feature1 0 +
44
+ chr1 100 200 feature2 0 +
45
+ chr1 150 500 feature3 0 -
46
+ chr1 900 950 feature4 0 +
47
+ <BLANKLINE>
48
+
49
+ >>> print(a.filter(len_filter, L=99))
50
+ chr1 100 200 feature2 0 +
51
+ chr1 150 500 feature3 0 -
52
+ <BLANKLINE>
53
+
54
+ >>> print(a.filter(len_filter, L=200))
55
+ chr1 150 500 feature3 0 -
56
+ <BLANKLINE>
57
+
58
+
59
+ See :ref:`BedTools as iterators` for more advanced and space-efficient usage
60
+ of :meth:`filter` using iterators.
61
+
62
+ Note that we could have used the built-in Python function, `filter()`, but that
63
+ would have returned an iterator that we would have to construct a new
64
+ :class:`pybedtools.BedTool` out of. The :meth:`BedTool.filter` method returns
65
+ a ready-to-use :class:`BedTool` object, which allows embedding of
66
+ :meth:`BedTool.filter` calls in a chain of commands, e.g.::
67
+
68
+ >>> a.intersect(b).filter(lambda x: len(x) < 100).merge()
69
+
70
+ Fast filtering functions in Cython
71
+ ----------------------------------
72
+
73
+ The :mod:`featurefuncs` module contains some ready-made functions written
74
+ in Cython that will be faster than pure Python equivalents. For example,
75
+ there are :func:`greater_than` and :func:`less_than` functions, which are
76
+ about 70% faster. In IPython::
77
+
78
+ >>> from pybedtools.featurefuncs import greater_than
79
+
80
+ >>> len(a)
81
+ 310456
82
+
83
+ >>> def L(x,width=100):
84
+ ... return len(x) > 100
85
+
86
+ >>> # The %timeit command is from IPython, and won't work
87
+ >>> # in a regular Python script:
88
+ >>> %timeit a.filter(greater_than, 100)
89
+ 1 loops, best of 3: 1.74 s per loop
90
+
91
+ >>> %timeit a.filter(L, 100)
92
+ 1 loops, best of 3: 2.96 s per loop
93
+
pybedtools/source/docs/source/flow-of-commands.rst ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Under the hood
2
+ ==============
3
+
4
+ This section documents some details about what happens when a :class:`BedTool`
5
+ object is created and exactly what happens when a BEDTools command is called.
6
+ It's mostly useful for developers or for debugging.
7
+
8
+
9
+ There are three kinds of sources/sinks for BedTool objects:
10
+
11
+ * filename
12
+ * open file object
13
+ * iterator of Interval objects
14
+
15
+
16
+ Iterator "protocol"
17
+ -------------------
18
+ BedTool objects yield an Interval object on each `next()` call. Where this
19
+ Interval comes from depends on how the BedTool was created and what format the
20
+ underlying data are in, as follows.
21
+
22
+ Filename-based
23
+ ~~~~~~~~~~~~~~
24
+ If BED/GTF/GFF/VCF format, then use an `IntervalFile` object for Cython/C++
25
+ speed.
26
+
27
+ If SAM format, then use an `IntervalIterator`. This is a Cython object that
28
+ reads individual lines and passes them to `create_interval_from_list`, a Cython
29
+ function. `create_interval_from_list` does a lot of the work to figure out
30
+ what format the line is, and this is how we are able to support SAM Interval
31
+ objects.
32
+
33
+ If BAM format, then first do a Popen call to `samtools view`, and create an
34
+ `IntervalIterator` from subprocess.PIPE similar to SAM format.
35
+
36
+ Open file-based
37
+ ~~~~~~~~~~~~~~~
38
+ All formats are passed to an `IntervalIterator`, which reads one line at
39
+ a time and yields an `Interval` object.
40
+
41
+ If it's a BAM file (specifically, a detected bgzip stream), then it's actually
42
+ first sent to the stdin of a `samtools` Popen call, and then the
43
+ subprocess.PIPE from that Popen's stdout is sent to an `IntervalIterator`.
44
+
45
+ Iterator or generator-based
46
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
+ If it's neither of the above, then the assumption is that it's already an
48
+ iterable of `Interval` objects. This is the case if a `BedTool` is created
49
+ with something like::
50
+
51
+ a = pybedtools.example_bedtool('a.bed')
52
+ b = pybedtools.BedTool((i for i in a))
53
+
54
+
55
+ In this case, the `(i for i in a)` creates a generator of intervals from an
56
+ `IntervalFile` -- since `a` is a filename-based BedTool. Since the first
57
+ argument to the BedTool constructor is neither a filename nor an open file, the
58
+ new BedTool `b`'s `.fn` attribute is directly set to this generator . . . so we
59
+ have a generator-based BedTool.
60
+
61
+ Calling BEDTools programs
62
+ -------------------------
63
+ Depending on the type of BedTool (filename, open file, or iterator), the method
64
+ of calling BEDTools programs differs.
65
+
66
+ In all cases, BEDTools commands are called via a `subprocess.Popen` call
67
+ (hereafter called "the Popen" for convenience). Depending on the type of
68
+ BedTool objects being operated on, the Popen will be passed different objects
69
+ as stdin and/or stdout.
70
+
71
+ In general, using a filename as input is the most straightforward -- nothing is
72
+ passed to the Popen's stdin because the filenames are embedded in the BEDTools
73
+ command.
74
+
75
+ Using non-filename-based BedTools means that they are passed, one line at
76
+ a time, to the stdin of the Popen. The commands for the BEDTools call
77
+ will specify "stdin" in these cases, as is standard for the BEDTools suite.
78
+
79
+ The default is for the output to be file-based. In this case, an open tempfile
80
+ object is provided as the Popen's stdout.
81
+
82
+ If the returned BedTool is requested to be a "streaming" BedTool, then the
83
+ Popen's stdout will be subprocess.PIPE, and the new BedTool object will be
84
+ open-file based (which is what subprocess.PIPE acts like).
85
+
86
+ Specifically, here is the information flow of stdin/stdout for various
87
+ interconversions of BedTool types . . . .
88
+
89
+
90
+ :filename -> filename:
91
+ The calling BedTool is filename-based and `stream=False`.
92
+
93
+ * `stdin`: `None` (the filenames are provided in the BEDTools command)
94
+ * `stdout`: open tempfile object
95
+ * new BedTool: filename-based BedTool pointing to the tempfile's filename
96
+
97
+ :filename -> open file object:
98
+ The calling BedTool is filename-based and `stream=True` is requested.
99
+
100
+ * `stdin`: None (provided in the cmds)
101
+ * `stdout`: open file object -- specifically, subprocess.PIPE
102
+ * new BedTool: iterator-based BedTool. Each `next()` call retrieves the
103
+ next line in subprocess.PIPE
104
+
105
+ :open file object -> filename:
106
+ The calling BedTool is from, e.g., subprocess.PIPE and there's
107
+ a saveas() call to "render" to file.
108
+
109
+ * `stdin`: each line in the open file object is written to subprocess.PIPE
110
+ * `stdout`: open file object -- either a tempfile or new file created from
111
+ supplied filename
112
+ * new BedTool: filename-based BedTool
113
+
114
+ :open file object -> iterator:
115
+ The calling BedTool is usually based on subprocess.PIPE, and the output
116
+ will *also* come from subprocess.PIPE.
117
+
118
+ * `stdin`: each line from the open file is written to subprocess.PIPE
119
+ * `stdout`: open file object, subprocess.PIPE
120
+ * new BedTool: filename based on subprocess.PIPE
pybedtools/source/docs/source/history.rst ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. include:: includeme.rst
2
+
3
+ .. _`working with history`:
4
+
5
+ Using the history and tags
6
+ --------------------------
7
+ `BEDTools`_ makes it very easy to do rather complex genomic algebra. Sometimes
8
+ when you're doing some exploratory work, you'd like to rewind back to a
9
+ previous step, or clean up temporary files that have been left on disk over the
10
+ course of some experimentation.
11
+
12
+ To assist this sort of workflow, :class:`BedTool` instances keep track of
13
+ their history in the :attr:`BedTool.history` attribute. Let's make an
14
+ example :class:`BedTool`, `c`, that has some history:
15
+
16
+ .. doctest::
17
+ :options: +NORMALIZE_WHITESPACE
18
+
19
+ >>> a = pybedtools.example_bedtool('a.bed')
20
+ >>> b = pybedtools.example_bedtool('b.bed')
21
+ >>> c = a.intersect(b, u=True)
22
+
23
+
24
+ `c` now has a history which tells you all sorts of useful things (described
25
+ in more detail below)::
26
+
27
+ >>> print c.history
28
+ [<HistoryStep> bedtool("/home/ryan/pybedtools/pybedtools/test/a.bed").intersect("/home/ryan/pybedtools/pybedtools/test/b.bed", u=True), parent tag: klkreuay, result tag: egzgnrvj]
29
+
30
+
31
+ There are several things to note here. First, the history describes the full
32
+ commands, including all the names of the temp files and all the arguments that
33
+ you would need to run in order to re-create it. Since :class:`BedTool` objects
34
+ are fundamentally file-based, the command refers to the underlying filenames
35
+ (i.e., :file:`a.bed` and :file:`b.bed`) instead of the :class:`BedTool`
36
+ instances (i.e., `a` and `b`). A simple copy-paste of the command will be
37
+ enough re-run the command. While this may be useful in some situations, be
38
+ aware that if you do run the command again you'll get *another* temp file that
39
+ has the same contents as `c`'s temp file.
40
+
41
+ To avoid such cluttering of your temp dir, the history also reports
42
+ **tags**. :class:`BedTool` objects, when created, get a random tag assigned
43
+ to them. You can get get the :class:`BedTool` associated with tag with the
44
+ :func:`pybedtools.find_tagged` function. These tags are used to keep track
45
+ of instances during this session.
46
+
47
+ So in this case, we could get a reference to the `a` instance with::
48
+
49
+ >>> should_be_a = pybedtools.find_tagged('klkreuay')
50
+
51
+ Here's confirmation that the parent of the first step of `c`'s history is
52
+ `a` (note that :class:`HistoryStep` objects have a
53
+ :attr:`HistoryStep.parent_tag` and :attr:`HistoryStep.result_tag`):
54
+
55
+ .. doctest::
56
+
57
+ >>> pybedtools.find_tagged(c.history[0].parent_tag) == a
58
+ True
59
+
60
+ Let's make something with a more complicated history:
61
+
62
+ .. doctest::
63
+
64
+ >>> a = pybedtools.example_bedtool('a.bed')
65
+ >>> b = pybedtools.example_bedtool('b.bed')
66
+ >>> c = a.intersect(b)
67
+ >>> d = c.slop(g=pybedtools.chromsizes('hg19'), b=1)
68
+ >>> e = d.merge()
69
+
70
+ >>> # this step adds complexity!
71
+ >>> f = e.subtract(b)
72
+
73
+ Let's see what the history of `f` (the last :class:`BedTool` created) looks
74
+ like . . . note that here I'm formatting the results to make it easier to
75
+ see::
76
+
77
+ >>> print f.history
78
+ [
79
+ | [
80
+ | | [
81
+ | | | [
82
+ | | | |<HistoryStep> BedTool("/usr/local/lib/python2.6/dist-packages/pybedtools/test/data/a.bed").intersect(
83
+ | | | | "/usr/local/lib/python2.6/dist-packages/pybedtools/test/data/b.bed",
84
+ | | | | ),
85
+ | | | | parent tag: rzrztxlw,
86
+ | | | | result tag: ifbsanqk
87
+ | | | ],
88
+ | | |
89
+ | | |<HistoryStep> BedTool("/tmp/pybedtools.BgULVj.tmp").slop(
90
+ | | | b=1,genome="hg19"
91
+ | | | ),
92
+ | | | parent tag: ifbsanqk,
93
+ | | | result tag: omfrkwjp
94
+ | | ],
95
+ | |
96
+ | |<HistoryStep> BedTool("/tmp/pybedtools.SFmbYc.tmp").merge(),
97
+ | | parent tag: omfrkwjp,
98
+ | | result tag: zlwqblvk
99
+ | ],
100
+ |
101
+ |<HistoryStep> BedTool("/tmp/pybedtools.wlBiMo.tmp").subtract(
102
+ | "/usr/local/lib/python2.6/dist-packages/pybedtools/test/data/b.bed",
103
+ | ),
104
+ | parent tag: zlwqblvk,
105
+ | result tag: reztxhen
106
+ ]
107
+
108
+ Those first three history steps correspond to `c`, `d`, and `e`
109
+ respectively, as we can see by comparing the code snippet above with the
110
+ commands in each history step. In other words, `e` can be described by the
111
+ sequence of 3 commands in the first three history steps. In fact, if we
112
+ checked `e.history`, we'd see exactly those same 3 steps.
113
+
114
+ When `f` was created above, it operated both on `e`, which had its own
115
+ history, as well as `b` -- note the nesting of the list. You can do
116
+ arbitrarily complex "genome algebra" operations, and the history of the
117
+ :class:`BEDTools` will keep track of this. It may not be useful in every
118
+ situtation, but the ability to backtrack and have a record of what you've
119
+ done can sometimes be helpful.
120
+
121
+ Deleting temp files specific to a single :class:`BedTool`
122
+ ---------------------------------------------------------
123
+ You can delete temp files that have been created over the history of a
124
+ :class:`BedTool` with :meth:`BedTool.delete_temporary_history`. This method
125
+ will inspect the history, figure out which items point to files in the temp dir
126
+ (which you can see with :func:`get_tempdir`), and prompt you for their
127
+ deletion::
128
+
129
+ >>> f.delete_temporary_history()
130
+ Delete these files?
131
+ /tmp/pybedtools..BgULVj.tmp
132
+ /tmp/pybedtools.SFmbYc.tmp
133
+ /tmp/pybedtools.wlBiMo.tmp
134
+ (y/N) y
135
+
136
+ Note that the file that `f` points to is left alone. To clarify, the
137
+ :meth:`BedTool.delete_temporary_history` will only delete temp files that match
138
+ the pattern ``<TEMP_DIR>/pybedtools.*.tmp`` from the history of `f`, up to but
139
+ not including the file for `f` itself. Any :class:`BedTool` instances that do
140
+ not match the pattern are left alone. Use the kwarg `ask=False` to disable
141
+ the prompt.
pybedtools/source/docs/source/images/downloads.png ADDED
pybedtools/source/docs/source/images/gchart.png ADDED
pybedtools/source/docs/source/images/mpl.png ADDED
pybedtools/source/docs/source/includeme.rst ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .. currentmodule:: pybedtools
3
+
4
+ .. _Tabix: http://samtools.sourceforge.net/tabix.shtml
5
+
6
+ .. _download page: http://sourceforge.net/projects/samtools/files/
7
+
8
+ .. _samtools: http://samtools.sourceforge.net/
9
+
10
+ .. _tempdir: http://docs.python.org/library/tempfile.html#tempfile.tempdir
11
+
12
+ .. _filo: https://github.com/arq5x/filo
13
+
14
+ .. _R: http://www.r-project.org/
15
+
16
+ .. _BEDTools: http://github.com/arq5x/bedtools
17
+
18
+ .. _BEDTools documentation: http://code.google.com/p/bedtools/#Documentation
19
+
20
+ .. _Learn Python the Hard Way: http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf
21
+
22
+ .. _IPython: http://ipython.scipy.org/moin/
23
+
24
+ .. _BED format: http://genome.ucsc.edu/FAQ/FAQformat#format1
25
+
26
+ .. _pip: http://www.pip-installer.org/en/latest/installing.html
27
+
28
+ .. _easy_install: http://pypi.python.org/pypi/setuptools
29
+
30
+ .. _Python Package Index: http://pypi.python.org/pypi
31
+
32
+ .. _Cython: http://cython.org/
33
+
34
+ .. _Python: http://www.python.org/
35
+
36
+ .. _nosetests: http://somethingaboutorange.com/mrl/projects/nose/
37
+
38
+ .. _PyYAML: http://pyyaml.org/wiki/PyYAMLDocumentation
39
+
40
+ .. _Sphinx: http://sphinx.pocoo.org/
41
+
42
+ .. _Cygwin: http://www.cygwin.com
43
+
44
+ .. _argparse: http://pypi.python.org/pypi/argparse
45
+
46
+ .. _nose: http://pypi.python.org/pypi/nose
47
+
48
+ .. _scipy: http://www.scipy.org/
49
+
50
+ .. _matplotlib: http://matplotlib.sourceforge.net/
pybedtools/source/docs/source/index.rst ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. pybedtools documentation master file, created by
2
+ sphinx-quickstart on Wed Dec 22 17:39:12 2010.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ .. include:: includeme.rst
7
+
8
+ `pybedtools` documentation
9
+ ==========================
10
+
11
+ .. include:: ../../README.rst
12
+
13
+
14
+
15
+ As of 2022, `pybedtools` is released under the MIT license; see LICENSE.txt for
16
+ more info.
17
+
18
+
19
+ .. note::
20
+
21
+ If you use :mod:`pybedtools` in your work, please cite the `pybedtools
22
+ manuscript <http://bioinformatics.oxfordjournals.org/content/27/24/3423>`_
23
+ and the `BEDTools manuscript
24
+ <http://bioinformatics.oxfordjournals.org/content/26/6/841.short>`_:
25
+
26
+ Dale RK, Pedersen BS, and Quinlan AR. 2011. *Pybedtools: a flexible
27
+ Python library for manipulating genomic datasets and annotations*.
28
+ Bioinformatics 27(24):3423-3424.
29
+
30
+ Quinlan AR and Hall IM, 2010. *BEDTools: a flexible suite of utilities
31
+ for comparing genomic features*. Bioinformatics 26(6):841–842.
32
+
33
+
34
+ Getting started
35
+ ---------------
36
+
37
+ The documentation is separated into 4 main parts, depending on the depth you'd
38
+ like to cover:
39
+
40
+ * Lazy, or just want to jump in? Check out :ref:`3examples` to
41
+ get a feel for the package.
42
+ * Want a guided tour? Give the :ref:`tutorial` a shot.
43
+ * More advanced features are described in the :ref:`topical` section.
44
+ * Finally, doctested module documentation can be found in :ref:`autodoc`.
45
+
46
+
47
+ Contents:
48
+ ---------
49
+
50
+ .. toctree::
51
+ :maxdepth: 2
52
+
53
+ main
54
+ 3-brief-examples
55
+ tutorial-contents
56
+ topical-documentation-contents
57
+ FAQs
58
+ scripts
59
+ autodoc_source
60
+ changes
61
+
62
+
63
+ Indices and tables
64
+ ==================
65
+ * :ref:`genindex`
66
+ * :ref:`modindex`
67
+ * :ref:`search`
68
+