Skip to content

Commit

Permalink
scglue prog
Browse files Browse the repository at this point in the history
  • Loading branch information
janursa committed Sep 18, 2024
1 parent e7a9781 commit d11df98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
10 changes: 4 additions & 6 deletions src/control_methods/baseline_corr/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

## VIASH START
par = {
'multiomics_rna': 'resources/grn-benchmark/multiomics_rna.h5ad',
'multiomics_rna': 'resources/grn-benchmark/multiomics_rna_0.h5ad',
'tf_all': 'resources/prior/tf_all.csv',
'causal': False,
'causal': True,
'metacell': False,
'cell_type_specific': False,
'impute': False,
'max_n_links': 50000,
'corr_method': 'pearson',
'prediction': 'resources/grn_models/alldonors_default/pearson.csv',
'prediction': 'resources/grn_models/donor_0_default/pearson_causal.csv',
"seed": 32
}
## VIASH END
Expand Down Expand Up @@ -96,9 +96,7 @@ def create_meta_cells(df, n_cells=15):
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)
multiomics_rna.X = multiomics_rna.layers['lognorm']

if par['impute']:
print("imputing")
Expand Down
39 changes: 15 additions & 24 deletions src/methods/multi_omics/scglue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,23 @@ def run_grn(par):
np.savetxt(f"{par['temp_dir']}/tfs.txt", tfs, fmt="%s")

#Construct the command
command = ['pyscenic', 'grn', f"{par['temp_dir']}/rna.loom",
f"{par['temp_dir']}/tfs.txt", '-o', f"{par['temp_dir']}/draft_grn.csv",
'--seed', '0', '--num_workers', f"{par['num_workers']}",
'--cell_id_attribute', 'obs_id', '--gene_attribute', 'name']
print('Run grn')
result = subprocess.run(command, check=True)
# command = ['pyscenic', 'grn', f"{par['temp_dir']}/rna.loom",
# f"{par['temp_dir']}/tfs.txt", '-o', f"{par['temp_dir']}/draft_grn.csv",
# '--seed', '0', '--num_workers', f"{par['num_workers']}",
# '--cell_id_attribute', 'obs_id', '--gene_attribute', 'name']
# print('Run grn')
# result = subprocess.run(command, check=True)

print("Output:")
print(result.stdout)
print("Error:")
print(result.stderr)
# print("Output:")
# print(result.stdout)
# print("Error:")
# print(result.stderr)

if result.returncode == 0:
print("Command executed successfully")
else:
print("Command failed with return code", result.returncode)
def create_prior(par):
atac = ad.read_h5ad(f"{par['temp_dir']}/atac-emb.h5ad")
rna = ad.read_h5ad(f"{par['temp_dir']}/rna-emb.h5ad")
motif_bed = scglue.genomics.read_bed(par['motif_file'])
fs = pd.Index(motif_bed["name"]).intersection(rna.var_names)
# if result.returncode == 0:
# print("Command executed successfully")
# else:
# print("Command failed with return code", result.returncode)

atac.var["name"] = atac.var_names

peaks = atac.var.index

print("Generate TF cis-regulatory ranking bridged by ATAC peaks", flush=True)
peak_bed = scglue.genomics.Bed(atac.var.loc[peaks])
Expand Down Expand Up @@ -311,8 +303,7 @@ def main(par):
# preprocess(rna, atac, par)
# print('Train a model', flush=True)
# training(par)
# run_grn(par)
create_prior(par)
run_grn(par)
prune_grn(par)
print('Curate predictions', flush=True)
pruned_grn = pd.read_csv(
Expand Down
8 changes: 4 additions & 4 deletions src/metrics/regression_1/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
par = {
"perturbation_data": "resources/grn-benchmark/perturbation_data.h5ad",
"tf_all": "resources/prior/tf_all.csv",
"prediction": "resources/grn_models/donor_0_celltype/grnboost2.csv",
"prediction": "resources/grn_models/donor_0_default/pearson_causal.csv",
"method_id": "scenic",
"min_tf": False,
"max_n_links": 50000,
Expand All @@ -19,9 +19,9 @@
'max_workers': 4,
}
## VIASH END
# meta = {
# "resources_dir":'src/metrics/regression_1/'
# }
meta = {
"resources_dir":'src/metrics/regression_1/'
}
sys.path.append(meta["resources_dir"])
from main import main

Expand Down

0 comments on commit d11df98

Please sign in to comment.