Skip to content

Commit 0e38868

Browse files
committed
Implemented API
1 parent 73ade70 commit 0e38868

4 files changed

Lines changed: 300 additions & 40 deletions

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,48 @@ gcnvplot plot \
5151
--output plot.svg
5252
```
5353

54+
## Python API
55+
56+
`gcnvplot` can also be used from Python code, for example when generating reports. Use `TranscriptIndex` to keep the SQLite transcript database open while rendering multiple plots.
57+
58+
Use `render_plot_svg` when you want the SVG as a string, for example for embedding the plot directly into an HTML report or notebook:
59+
60+
```python
61+
from pathlib import Path
62+
63+
import gcnvplot
64+
65+
with gcnvplot.TranscriptIndex(Path("annotations.sqlite")) as transcript_index:
66+
svg = gcnvplot.render_plot_svg(
67+
Path("sample.tsv"),
68+
Path("background.tsv"),
69+
transcript_id="NM_007294.4",
70+
transcript_index=transcript_index,
71+
sample_name="SAMPLE_01",
72+
highlight="chr17:43070928-43076614",
73+
)
74+
```
75+
76+
77+
Use `write_plot` when you just want the finished SVG saved to disk. It is a convenience wrapper around `render_plot_svg`.
78+
79+
```python
80+
from pathlib import Path
81+
82+
import gcnvplot
83+
84+
with gcnvplot.TranscriptIndex(Path("annotations.sqlite")) as transcript_index:
85+
gcnvplot.write_plot(
86+
Path("sample.tsv"),
87+
Path("background.tsv"),
88+
Path("plot.svg"),
89+
transcript_id="NM_007294.4",
90+
transcript_index=transcript_index,
91+
sample_name="SAMPLE_01",
92+
highlight="chr17:43070928-43076614",
93+
)
94+
```
95+
5496
## Synthetic example
5597

5698
A tiny synthetic BRCA1 transcript example is available in [`examples/brca1_synthetic`](examples/brca1_synthetic). It demonstrates a highlighted multi-exon deletion, filled and open sample dots, and an uncovered-exon marker.

src/gcnvplot/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
"""Top-level package for gcnvplot."""
22

3+
from .core import (
4+
BackgroundSummary,
5+
Interval,
6+
TranscriptAnnotation,
7+
TranscriptExon,
8+
TranscriptIndex,
9+
index_gtf,
10+
load_background,
11+
parse_read_counts,
12+
parse_region,
13+
render_plot_svg,
14+
write_plot,
15+
)
16+
317
__version__ = "0.4.0"
18+
19+
__all__ = [
20+
"BackgroundSummary",
21+
"Interval",
22+
"TranscriptAnnotation",
23+
"TranscriptExon",
24+
"TranscriptIndex",
25+
"__version__",
26+
"index_gtf",
27+
"load_background",
28+
"parse_read_counts",
29+
"parse_region",
30+
"render_plot_svg",
31+
"write_plot",
32+
]

0 commit comments

Comments
 (0)