Skip to content

Commit

Permalink
Merge pull request #244 from DendrouLab/fc_scviseeds
Browse files Browse the repository at this point in the history
adding seeds to each scvi-tool script
  • Loading branch information
bio-la authored Apr 23, 2024
2 parents ebf9d59 + 79b4be8 commit 0498f1b
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### dependencies
- All the dependencies have been updated.
- Python>=3.10 required
- added seeds to all scvi tasks for reproducibility

## v0.4.1

Expand Down
1 change: 1 addition & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### dependencies
- All the dependencies have been updated.
- Python>=3.10 required
- added seeds to all scvi tasks for reproducibility

## v0.4.1

Expand Down
15 changes: 13 additions & 2 deletions docs/yaml_docs/useful_info_on_yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,23 @@ Therefore, `PARAMS['prot']['neighbors']` is the equivalent of `prot_params['neig

You can read the `pipeline.yml` configuration file in python and check how the commands are parsed using

```python
import yaml
with open('pipeline.yml', 'r') as file:
PARAMS = yaml.safe_load(file)
```
from panpipes.funcs.io import read_yaml

PARAMS = read_yaml("pipeline.yml")
in `panpipes` we read the yaml configuration file at the beginning of each workflow with:

```python
from cgatcore import pipeline as P
PARAMS = P.get_parameters(
["%s/pipeline.yml" % os.path.splitext(__file__)[0],
"pipeline.yml"])
```


### Anchors and Scalars

YAML files offer a lot of functionalities to fill and parse blocks of text avoiding to repeat entire sections.
Expand Down
14 changes: 12 additions & 2 deletions panpipes/panpipes/pipeline_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def run_scvi(outfile):
--figdir figures/rna/
"""
# cannot use the normal method for importing params from yaml, because it only works up to depth 2
# fetch seeds
scvi_params = PARAMS['rna']['scvi']
cmd += " --scvi_seed %i" % scvi_params['seed']
neighbor_params = PARAMS['rna']['neighbors']
if neighbor_params['method'] is not None:
cmd += " --neighbors_method %s" % neighbor_params['method']
Expand Down Expand Up @@ -550,8 +553,12 @@ def run_totalvi(outfile):
--output_csv %(outfile)s
--figdir figures/
"""
scvi_params = PARAMS['multimodal']['totalvi']
cmd += " --scvi_seed %i" % scvi_params['seed']


if PARAMS['multimodal_column_categorical'] is not None:
cmd += "--integration_col_categorical %(multimodal_column_categorical)s "
cmd += " --integration_col_categorical %(multimodal_column_categorical)s "
neighbor_params = PARAMS['multimodal']['neighbors']
if neighbor_params['method'] is not None:
cmd += " --neighbors_method %s" % neighbor_params['method']
Expand Down Expand Up @@ -587,9 +594,12 @@ def run_multivi(outfile):
--output_csv %(outfile)s
--figdir figures/
"""
scvi_params = PARAMS['multimodal']['MultiVI']
cmd += " --scvi_seed %i" % scvi_params['seed']


if PARAMS['multimodal_column_categorical'] is not None:
cmd += "--integration_col_categorical %(multimodal_column_categorical)s "
cmd += " --integration_col_categorical %(multimodal_column_categorical)s "

if PARAMS['multimodal_column_continuous'] is not None:
cmd += "--integration_col_continuous %(multimodal_column_continuous)s "
Expand Down
8 changes: 6 additions & 2 deletions panpipes/panpipes/pipeline_integration/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ queues:
# --------------------------------

# ----------------------------
# Data format
# Data input
# ----------------------------
sample_prefix: test
preprocessed_obj: ../preprocess/test.h5mu


#-----------------
# Batch correction
# ----------------
# Batch correction is done unimodal, meaning each modality is batch corrected independently
# Batch correction, unimodal correction: meaning each modality is batch corrected independently.

# ------------
# RNA modality
Expand All @@ -55,6 +56,7 @@ rna:

# SCVI args
scvi:
seed: 1492
exclude_mt_genes: True
mt_column: mt
model_args:
Expand Down Expand Up @@ -144,6 +146,7 @@ multimodal:

# TotalVI arguments
totalvi:
seed: 1492
modalities: rna,prot
exclude_mt_genes: True
mt_column: mt
Expand All @@ -159,6 +162,7 @@ multimodal:

# MultiVI arguments
MultiVI:
seed: 1492
lowmem: True
model_args:
n_hidden :
Expand Down
7 changes: 6 additions & 1 deletion panpipes/python_scripts/batch_correct_multivi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
help="neighbors k")
parser.add_argument('--neighbors_metric',default="euclidean",
help="neighbor metric, e.g. euclidean or cosine")
parser.add_argument('--scvi_seed',default=None,
help="set explicitly seed to make runs reproducible")



Expand All @@ -57,7 +59,10 @@
sc.settings.autoshow = False
sc.settings.figdir = args.figdir

scvi.settings.seed = 1492
if args.scvi_seed is not None:
scvi.settings.seed = int(args.scvi_seed)
else:
scvi.settings.seed = 1492
# load parameters

threads_available = multiprocessing.cpu_count()
Expand Down
9 changes: 9 additions & 0 deletions panpipes/python_scripts/batch_correct_scvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
help="neighbors k")
parser.add_argument('--neighbors_metric',
help="neighbor metric, e.g. euclidean or cosine")
parser.add_argument('--scvi_seed',default=None,
help="set explicitly seed to make runs reproducible")



args, opt = parser.parse_known_args()
Expand All @@ -61,6 +64,12 @@
sc.settings.autoshow = False
sc.settings.figdir = args.figdir

if args.scvi_seed is not None:
scvi.settings.seed = int(args.scvi_seed)
else:
scvi.settings.seed = 1492



# test_script=params['rna']['scvi']['testrun']
test_script=False
Expand Down
10 changes: 10 additions & 0 deletions panpipes/python_scripts/batch_correct_totalvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
help="neighbors k")
parser.add_argument('--neighbors_metric',default="euclidean",
help="neighbor metric, e.g. euclidean or cosine")
parser.add_argument('--scvi_seed',default=None,
help="set explicitly seed to make runs reproducible")




args, opt = parser.parse_known_args()
L.info(args)
Expand All @@ -55,6 +60,11 @@
sc.settings.figdir = args.figdir


if args.scvi_seed is not None:
scvi.settings.seed = int(args.scvi_seed)
else:
scvi.settings.seed = 1492

# load parameters

threads_available = multiprocessing.cpu_count()
Expand Down
4 changes: 2 additions & 2 deletions panpipes/python_scripts/plot_qc_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

figdir = args.figdir

if not os.path.exists(figdir):
os.mkdir(figdir)
# if not os.path.exists(figdir):
# os.mkdir(figdir)

sc.settings.figdir = figdir
sc.set_figure_params(scanpy=True, fontsize=14, dpi=300, facecolor='white', figsize=(5,5))
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_1/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ multimodal:
column_categorical: dataset
# extra params:
totalvi:
seed: 1492
# this is a minimal set of parameters that will be expected
# you can add any other param from the tutorials and they will
# be parsed alongside the others
Expand All @@ -234,6 +235,7 @@ multimodal:
early_stopping: True
training_plan: None
MultiVI:
seed: 1492
# this is a minimal set of parameters that will be expected
# you can add any other param from the tutorials and they will
# be parsed alongside the others
Expand Down Expand Up @@ -375,6 +377,7 @@ plotqc:
# Choose the integration results you want to merge in the final object
# For unimodal integration: to pick the uncorrected version use "no_correction"
# then run

# panpipes integration make merge_integration
final_obj:
rna:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_2/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ multimodal:
column_categorical: dataset
# extra params:
totalvi:
seed: 1492
# this is a minimal set of parameters that will be expected
# you can add any other param from the tutorials and they will
# be parsed alongside the others
Expand All @@ -234,6 +235,7 @@ multimodal:
early_stopping: True
training_plan: None
MultiVI:
seed: 1492
# this is a minimal set of parameters that will be expected
# you can add any other param from the tutorials and they will
# be parsed alongside the others
Expand Down

0 comments on commit 0498f1b

Please sign in to comment.