-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from nf-core/microshifts
Add parameter for grouping detected circRNAs that are very close
- Loading branch information
Showing
15 changed files
with
232 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- conda-forge::polars=1.8.2 | ||
- conda-forge::upsetplot=0.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
process COMBINE_BEDS { | ||
tag "$meta.id" | ||
label "process_low" | ||
|
||
conda "${moduleDir}/environment.yml" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'oras://community.wave.seqera.io/library/polars_upsetplot:0fc26c37f7821606' : | ||
'community.wave.seqera.io/library/polars_upsetplot:3382b69d3c1f6bf1' }" | ||
|
||
input: | ||
tuple val(meta), path(beds) | ||
val(max_shift) | ||
val(min_tools) | ||
val(min_samples) | ||
|
||
output: | ||
tuple val(meta), path("${prefix}.${suffix}"), emit: combined | ||
path "*.png" , emit: plots, optional: true | ||
path "*.json" , emit: multiqc, optional: true | ||
path "versions.yml" , emit: versions | ||
|
||
script: | ||
prefix = task.ext.prefix ?: "${meta.id}" | ||
suffix = task.ext.suffix ?: "bed" | ||
template "combine.py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env python | ||
|
||
import platform | ||
import base64 | ||
import json | ||
|
||
import polars as pl | ||
import upsetplot | ||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
|
||
def format_yaml_like(data: dict, indent: int = 0) -> str: | ||
"""Formats a dictionary to a YAML-like string. | ||
Args: | ||
data (dict): The dictionary to format. | ||
indent (int): The current indentation level. | ||
Returns: | ||
str: A string formatted as YAML. | ||
""" | ||
yaml_str = "" | ||
for key, value in data.items(): | ||
spaces = " " * indent | ||
if isinstance(value, dict): | ||
yaml_str += f"{spaces}{key}:\\n{format_yaml_like(value, indent + 1)}" | ||
else: | ||
yaml_str += f"{spaces}{key}: {value}\\n" | ||
return yaml_str | ||
|
||
max_shift = int("${max_shift}") | ||
min_tools = int("${min_tools}") | ||
min_samples = int("${min_samples}") | ||
meta_id = "{meta_id}" | ||
prefix = "${prefix}" | ||
|
||
df = pl.scan_csv("*.bed", | ||
separator="\\t", | ||
has_header=False, | ||
new_columns=["chr", "start", "end", "name", "score", "strand", "sample", "tool"]) | ||
|
||
for col in ["end", "start"]: | ||
df = df.sort(["chr", col]) | ||
df = df.with_columns(**{f"{col}_group": pl.col(col).diff().fill_null(0).gt(max_shift).cum_sum()}) | ||
|
||
df = (df.group_by(["chr", "start_group", "end_group"]) | ||
.agg( pl.col("start").median().round().cast(int), | ||
pl.col("end").median().round().cast(int), | ||
pl.col("sample").unique().alias("samples"), | ||
pl.col("tool").unique().alias("tools"), | ||
pl.col("sample").n_unique().alias("n_samples"), | ||
pl.col("tool").n_unique().alias("n_tools")) | ||
.with_columns(name=pl.col("chr").cast(str) + ":" + pl.col("start").cast(str) + "-" + pl.col("end").cast(str), | ||
score=pl.lit("."), | ||
strand=pl.lit("."))) | ||
|
||
for col in ["samples", "tools"]: | ||
series = pl.Series(df.select(col).collect()) | ||
if series.explode().n_unique() == 1: | ||
continue | ||
memberships = series.to_list() | ||
dataset = upsetplot.from_memberships(memberships) | ||
upsetplot.plot(dataset, | ||
orientation='horizontal', | ||
show_counts=True, | ||
subset_size="count") | ||
plot_file = f"{prefix}_{col}.upset.png" | ||
plt.savefig(plot_file) | ||
|
||
image_string = base64.b64encode(open(plot_file, "rb").read()).decode("utf-8") | ||
image_html = f'<div class="mqc-custom-content-image"><img src="data:image/png;base64,{image_string}" /></div>' | ||
|
||
multiqc = { | ||
'id': f"{meta_id}_upset_{col}", | ||
'parent_id': "upset_plots", | ||
'parent_name': 'UpSet Plots', | ||
'parent_description': 'UpSet plots showing the overlap between tools for each sample', | ||
'section_name': f'UpSet {col}: {meta_id} ', | ||
'description': f'UpSet plot showing the overlap between {col} for {meta_id}', | ||
'plot_type': 'image', | ||
'data': image_html | ||
} | ||
|
||
with open(f"{prefix}_{col}.upset_mqc.json", "w") as f: | ||
f.write(json.dumps(multiqc, indent=4)) | ||
|
||
|
||
df = (df.filter((pl.col("n_tools") >= min_tools) & (pl.col("n_samples") >= min_samples)) | ||
.select(["chr", "start", "end", "name", "score", "strand"])) | ||
|
||
df.collect().write_csv("${prefix}.${suffix}", separator="\\t", include_header=False) | ||
|
||
# Versions | ||
|
||
versions = { | ||
"${task.process}": { | ||
"python": platform.python_version(), | ||
"polars": pl.__version__, | ||
"upsetplot": upsetplot.__version__, | ||
"matplotlib": matplotlib.__version__ | ||
} | ||
} | ||
|
||
with open("versions.yml", "w") as f: | ||
f.write(format_yaml_like(versions)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.