Skip to content

Commit

Permalink
Merge pull request #132 from nf-core/scvi-parameters
Browse files Browse the repository at this point in the history
Add scVI parameters
  • Loading branch information
nictru authored Dec 9, 2024
2 parents 6da26ba + 15a57cf commit 4045b22
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 8 deletions.
14 changes: 14 additions & 0 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ process {
// Integration

withName: SCVITOOLS_SCVI {
ext.n_hidden = { params.scvi_n_hidden }
ext.n_layers = { params.scvi_n_layers }
ext.n_latent = { params.scvi_n_latent }
ext.dispersion = { params.scvi_dispersion }
ext.gene_likelihood = { params.scvi_gene_likelihood }
ext.max_epochs = { params.scvi_max_epochs }

publishDir = [
path: { "${params.outdir}/combine/integrate/scvi" },
mode: params.publish_dir_mode,
Expand All @@ -255,6 +262,13 @@ process {
}

withName: SCVITOOLS_SCANVI {
ext.n_hidden = { params.scvi_n_hidden }
ext.n_layers = { params.scvi_n_layers }
ext.n_latent = { params.scvi_n_latent }
ext.dispersion = { params.scvi_dispersion }
ext.gene_likelihood = { params.scvi_gene_likelihood }
ext.max_epochs = { params.scvi_max_epochs }

publishDir = [
path: { "${params.outdir}/combine/integrate/scanvi" },
mode: params.publish_dir_mode,
Expand Down
6 changes: 6 additions & 0 deletions modules/local/scvitools/scanvi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ process SCVITOOLS_SCANVI {

script:
prefix = task.ext.prefix ?: "${meta.id}"
n_hidden = task.ext.n_hidden ?: 128
n_layers = task.ext.n_layers ?: 2
n_latent = task.ext.n_latent ?: 30
dispersion = task.ext.dispersion ?: 'gene'
gene_likelihood = task.ext.gene_likelihood ?: 'zinb'
max_epochs = task.ext.max_epochs ?: null
template 'scanvi.py'
}
10 changes: 8 additions & 2 deletions modules/local/scvitools/scanvi/templates/scanvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ def format_yaml_like(data: dict, indent: int = 0) -> str:
)
else:
SCANVI.setup_anndata(adata, batch_key="batch", labels_key="label", unlabeled_category="unknown")
model = SCANVI(adata)
model = SCANVI(adata,
n_hidden=int("${n_hidden}"),
n_layers=int("${n_layers}"),
n_latent=int("${n_latent}"),
dispersion="${dispersion}",
gene_likelihood="${gene_likelihood}")

if "${task.ext.use_gpu}" == "true":
model.to_device(0)

model.train(early_stopping=True)
model.train(early_stopping=True,
max_epochs=int("${max_epochs}") if "${max_epochs?:''}" else None)
adata.obsm["X_emb"] = model.get_latent_representation()
adata.obs["label:scANVI"] = model.predict()

Expand Down
6 changes: 6 additions & 0 deletions modules/local/scvitools/scvi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ process SCVITOOLS_SCVI {

script:
prefix = task.ext.prefix ?: "${meta.id}"
n_hidden = task.ext.n_hidden ?: 128
n_layers = task.ext.n_layers ?: 2
n_latent = task.ext.n_latent ?: 30
dispersion = task.ext.dispersion ?: 'gene'
gene_likelihood = task.ext.gene_likelihood ?: 'zinb'
max_epochs = task.ext.max_epochs ?: null
template 'scvi.py'
}
10 changes: 8 additions & 2 deletions modules/local/scvitools/scvi/templates/scvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ def format_yaml_like(data: dict, indent: int = 0) -> str:
model = SCVI.load_query_data(adata, reference_model_path)
else:
SCVI.setup_anndata(adata, batch_key = "batch")
model = SCVI(adata)
model = SCVI(adata,
n_hidden=int("${n_hidden}"),
n_layers=int("${n_layers}"),
n_latent=int("${n_latent}"),
dispersion="${dispersion}",
gene_likelihood="${gene_likelihood}")

if "${task.ext.use_gpu}" == "true":
model.to_device(0)

model.train(early_stopping=True)
model.train(early_stopping=True,
max_epochs=int("${max_epochs}") if "${max_epochs?:''}" else None)

adata.obsm["X_emb"] = model.get_latent_representation()

Expand Down
8 changes: 8 additions & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ params {
use_gpu = false
prep_cellxgene = false

// scVI options
scvi_n_latent = 30
scvi_n_hidden = 128
scvi_n_layers = 2
scvi_dispersion = 'gene'
scvi_gene_likelihood = 'zinb'
scvi_max_epochs = null

// MultiQC options
multiqc_config = null
multiqc_title = null
Expand Down
48 changes: 44 additions & 4 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,47 @@
}
}
},
"scVI_options": {
"title": "scVI/scANVI options",
"type": "object",
"fa_icon": "fas fa-microscope",
"description": "Options for the scVI and scANVI integration methods",
"properties": {
"scvi_n_latent": {
"type": "integer",
"default": 30,
"description": "Number of latent dimensions for scVI/scANVI"
},
"scvi_n_hidden": {
"type": "integer",
"default": 128,
"description": "Number of hidden units in the neural network for scVI/scANVI"
},
"scvi_n_layers": {
"type": "integer",
"default": 2,
"description": "Number of layers in the neural network for scVI/scANVI"
},
"scvi_dispersion": {
"type": "string",
"default": "gene",
"enum": ["gene", "gene-batch", "gene-label", "gene-cell"],
"description": "Dispersion parameter for scVI/scANVI",
"help_text": "Dispersion parameter for scVI/scANVI. Can be 'gene', 'gene-batch', 'gene-label', or 'gene-cell'."
},
"scvi_gene_likelihood": {
"type": "string",
"default": "zinb",
"enum": ["zinb", "nb", "poisson", "normal"],
"description": "Gene likelihood for scVI/scANVI",
"help_text": "Gene likelihood for scVI/scANVI. Can be 'zinb', 'nb', 'poisson', or 'normal'."
},
"scvi_max_epochs": {
"type": "integer",
"description": "Maximum number of epochs for training scVI/scANVI. If not set, a heuristic provided by scVI/scANVI will be used."
}
}
},
"institutional_config_options": {
"title": "Institutional config options",
"type": "object",
Expand Down Expand Up @@ -349,16 +390,15 @@
{
"$ref": "#/$defs/input_output_options"
},

{
"$ref": "#/$defs/institutional_config_options"
},
{
"$ref": "#/$defs/reference_mapping_options"
},
{
"$ref": "#/$defs/pipeline_options"
},
{
"$ref": "#/$defs/scVI_options"
},
{
"$ref": "#/$defs/institutional_config_options"
},
Expand Down

0 comments on commit 4045b22

Please sign in to comment.