Skip to content

Commit

Permalink
v1.3.2pr
Browse files Browse the repository at this point in the history
  • Loading branch information
shitohana committed Nov 12, 2023
1 parent 433597c commit 6a70292
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,29 @@ clustered = metagene.clustering(
# Heatmap with optimized distances between genes will be drawn
clustered.draw().savefig("path/to/clustered_hm.pdf")
```
Output for _Brachypodium distachyon_
Output for _Brachypodium distachyon_ - CHG

<p align="middle">
<img width="300" src="https://user-images.githubusercontent.com/43905117/280022981-d6d4ffff-7f3d-4e33-8e42-05b98ca28161.png">
<img width="300" src="https://user-images.githubusercontent.com/43905117/282321746-baf97da1-6a35-4a17-9772-5a2f4d67e6a4.png">
</p>

### Genes dynamicTreeCut

To shrink clustered heat-map and capture main patterns genes can be split into modules using
[dynamicTreeCut algorithm](https://github.com/kylessmith/dynamicTreeCut/tree/master) by Peter Langfelder and Bin Zhang.
Then genes can be plotted as heat-map as previous example:

```python
# Parameters are the same as for cutreeHybrid (see dynamicTreeCut)
modules = clustered.modules(deepSplit = 1)

modules.draw().savefig("path/to/modules_hm.pdf")
```

Output for _Brachypodium distachyon_ - CHG

<p align="middle">
<img width="300" src="https://user-images.githubusercontent.com/43905117/282321739-df4486f6-9b1f-467e-87ea-cfd441f80e0a.png">
</p>

### Smoothing the line plot
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "bismarkplot"
version = "1.3.2a"
version = "1.3.2pr"
authors = [
{ name="shitohana", email="kyudytskiy@gmail.com" },
]
Expand Down
8 changes: 6 additions & 2 deletions src/bismarkplot/BismarkPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def __init__(self, bismark_df: pl.DataFrame, count_threshold=5, dist_method="euc

self.gene_labels = unpivot.with_columns(pl.col("label").cast(pl.Utf8))["label"].to_numpy()
self.matrix = unpivot[list(map(str, range(self.total_windows)))].to_numpy()

self.gene_labels = self.gene_labels[~np.isnan(self.matrix).any(axis=1)]
self.matrix = self.matrix[~np.isnan(self.matrix).any(axis=1), :]

# dist matrix
Expand Down Expand Up @@ -597,7 +599,7 @@ def draw(
show_size=False
) -> Figure:
"""
Method for visualiztion of moduled genes. Every row of heat-map represents an average methylation
Method for visualization of moduled genes. Every row of heat-map represents an average methylation
profile of genes of the module.
:param fig_axes: tuple(Fig, Axes) to plot
Expand Down Expand Up @@ -1622,8 +1624,10 @@ def draw(
else:
subplots_y = 1

if len(self.samples) > 1:
if len(self.samples) > 1 and subplots_y > 1:
subplots_x = (len(self.samples) + len(self.samples) % 2) // subplots_y
elif len(self.samples) > 1:
subplots_x = len(self.samples)
else:
subplots_x = 1

Expand Down

0 comments on commit 6a70292

Please sign in to comment.