-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
384 additions
and
37 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,24 @@ | ||
__merge__: ../../api/comp_method.yaml | ||
|
||
functionality: | ||
name: pearson_corr | ||
namespace: control_methods | ||
info: | ||
label: pearson_corr | ||
summary: "Baseline based on correlation" | ||
|
||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
platforms: | ||
- type: docker | ||
image: ghcr.io/openproblems-bio/base_python:1.0.4 | ||
setup: | ||
- type: python | ||
# packages: [ magic-impute ] | ||
packages: [ ] | ||
- type: native | ||
- type: nextflow | ||
directives: | ||
label: [midtime, midmem, midcpu] |
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,76 @@ | ||
import os | ||
import pandas as pd | ||
import numpy as np | ||
import anndata as ad | ||
import scanpy as sc | ||
from tqdm import tqdm | ||
from scipy.stats import spearmanr | ||
from sklearn.preprocessing import StandardScaler | ||
|
||
## VIASH START | ||
par = { | ||
'multiomics_rna': 'resources/grn-benchmark/multiomics_rna_0.h5ad', | ||
'tf_all': 'resources/prior/tf_all.csv', | ||
'causal': False, | ||
'cell_type_specific': True, | ||
'max_n_links': 50000, | ||
'prediction': 'resources/grn_models/donor_0_default/pearson.csv', | ||
"seed": 32 | ||
} | ||
## VIASH END | ||
print(par) | ||
|
||
def process_links(net, par): | ||
net = net[net.source!=net.target] | ||
net_sorted = net.reindex(net['weight'].abs().sort_values(ascending=False).index) | ||
net = net_sorted.head(par['max_n_links']).reset_index(drop=True) | ||
return net | ||
|
||
def corr_net(X, gene_names, par): | ||
X = StandardScaler().fit_transform(X) | ||
net = np.dot(X.T, X) / X.shape[0] | ||
net = pd.DataFrame(net, index=gene_names, columns=gene_names) | ||
net = net.sample(len(tf_all), axis=1, random_state=par['seed']) | ||
net = net.reset_index() | ||
index_name = net.columns[0] | ||
net = net.melt(id_vars=index_name, var_name='source', value_name='weight') | ||
|
||
net.rename(columns={index_name: 'target'}, inplace=True) | ||
net = process_links(net, par) | ||
|
||
return net | ||
|
||
def create_corr_net(X, gene_names, groups, par): | ||
if par['cell_type_specific']: | ||
i = 0 | ||
for group in tqdm(np.unique(groups), desc="Processing groups"): | ||
X_sub = X[groups == group, :] | ||
net = corr_net(X_sub, gene_names, par) | ||
net['cell_type'] = group | ||
if i==0: | ||
grn = net | ||
else: | ||
grn = pd.concat([grn, net], axis=0).reset_index(drop=True) | ||
i += 1 | ||
else: | ||
grn = corr_net(X, gene_names, par) | ||
return grn | ||
print('Read data') | ||
multiomics_rna = ad.read_h5ad(par["multiomics_rna"]) | ||
|
||
|
||
gene_names = multiomics_rna.var_names.to_numpy() | ||
tf_all = np.loadtxt(par['tf_all'], dtype=str) | ||
groups = multiomics_rna.obs.cell_type | ||
tf_all = np.intersect1d(tf_all, gene_names) | ||
|
||
print('Noramlize data') | ||
sc.pp.normalize_total(multiomics_rna) | ||
sc.pp.log1p(multiomics_rna) | ||
sc.pp.scale(multiomics_rna) | ||
|
||
print('Create corr net') | ||
net = create_corr_net(multiomics_rna.X, multiomics_rna.var_names, groups, par) | ||
|
||
print('Output GRN') | ||
net.to_csv(par['prediction']) |
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,5 @@ | ||
viash run src/control_methods/baseline_corr/config.vsh.yaml -- \ | ||
--prediction output/baseline_corr.csv \ | ||
--multiomics_rna resources/grn-benchmark/multiomics_rna.h5ad \ | ||
--tf_all resources/prior/tf_all.csv \ | ||
--causal true |
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,24 @@ | ||
__merge__: ../../api/comp_method.yaml | ||
|
||
functionality: | ||
name: pearson_causal | ||
namespace: control_methods | ||
info: | ||
label: pearson_causal | ||
summary: "Baseline based on correlation" | ||
|
||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
platforms: | ||
- type: docker | ||
image: ghcr.io/openproblems-bio/base_python:1.0.4 | ||
setup: | ||
- type: python | ||
# packages: [ magic-impute ] | ||
packages: [ ] | ||
- type: native | ||
- type: nextflow | ||
directives: | ||
label: [midtime, midmem, midcpu] |
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,77 @@ | ||
import os | ||
import pandas as pd | ||
import numpy as np | ||
import anndata as ad | ||
import scanpy as sc | ||
from tqdm import tqdm | ||
from scipy.stats import spearmanr | ||
from sklearn.preprocessing import StandardScaler | ||
|
||
## VIASH START | ||
par = { | ||
'multiomics_rna': 'resources/grn-benchmark/multiomics_rna_0.h5ad', | ||
'tf_all': 'resources/prior/tf_all.csv', | ||
'causal': True, | ||
'cell_type_specific': True, | ||
'max_n_links': 50000, | ||
'prediction': 'resources/grn_models/donor_0_default/pearson_causal.csv', | ||
"seed": 32 | ||
} | ||
## VIASH END | ||
print(par) | ||
|
||
def process_links(net, par): | ||
net = net[net.source!=net.target] | ||
net_sorted = net.reindex(net['weight'].abs().sort_values(ascending=False).index) | ||
net = net_sorted.head(par['max_n_links']).reset_index(drop=True) | ||
return net | ||
|
||
def corr_net(X, gene_names, par): | ||
X = StandardScaler().fit_transform(X) | ||
net = np.dot(X.T, X) / X.shape[0] | ||
net = pd.DataFrame(net, index=gene_names, columns=gene_names) | ||
|
||
net = net[tf_all] | ||
net = net.reset_index() | ||
index_name = net.columns[0] | ||
net = net.melt(id_vars=index_name, var_name='source', value_name='weight') | ||
|
||
net.rename(columns={index_name: 'target'}, inplace=True) | ||
net = process_links(net, par) | ||
|
||
return net | ||
|
||
def create_corr_net(X, gene_names, groups, par): | ||
if par['cell_type_specific']: | ||
i = 0 | ||
for group in tqdm(np.unique(groups), desc="Processing groups"): | ||
X_sub = X[groups == group, :] | ||
net = corr_net(X_sub, gene_names, par) | ||
net['cell_type'] = group | ||
if i==0: | ||
grn = net | ||
else: | ||
grn = pd.concat([grn, net], axis=0).reset_index(drop=True) | ||
i += 1 | ||
else: | ||
grn = corr_net(X, gene_names, par) | ||
return grn | ||
print('Read data') | ||
multiomics_rna = ad.read_h5ad(par["multiomics_rna"]) | ||
|
||
|
||
gene_names = multiomics_rna.var_names.to_numpy() | ||
tf_all = np.loadtxt(par['tf_all'], dtype=str) | ||
groups = multiomics_rna.obs.cell_type | ||
tf_all = np.intersect1d(tf_all, gene_names) | ||
|
||
print('Noramlize data') | ||
sc.pp.normalize_total(multiomics_rna) | ||
sc.pp.log1p(multiomics_rna) | ||
sc.pp.scale(multiomics_rna) | ||
|
||
print('Create corr net') | ||
net = create_corr_net(multiomics_rna.X, multiomics_rna.var_names, groups, par) | ||
|
||
print('Output GRN') | ||
net.to_csv(par['prediction']) |
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,5 @@ | ||
viash run src/control_methods/baseline_corr/config.vsh.yaml -- \ | ||
--prediction output/baseline_corr.csv \ | ||
--multiomics_rna resources/grn-benchmark/multiomics_rna.h5ad \ | ||
--tf_all resources/prior/tf_all.csv \ | ||
--causal true |
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,29 @@ | ||
__merge__: ../../api/comp_method.yaml | ||
|
||
functionality: | ||
name: positive_control | ||
namespace: control_methods | ||
info: | ||
label: positive_control | ||
summary: "Baseline based on correlation" | ||
arguments: | ||
- name: --perturbation_data | ||
type: file | ||
required: true | ||
direction: input | ||
example: resources_test/grn-benchmark/perturbation_data.h5ad | ||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
platforms: | ||
- type: docker | ||
image: ghcr.io/openproblems-bio/base_python:1.0.4 | ||
setup: | ||
- type: python | ||
# packages: [ magic-impute ] | ||
packages: [ ] | ||
- type: native | ||
- type: nextflow | ||
directives: | ||
label: [midtime, midmem, midcpu] |
Oops, something went wrong.