File size: 1,111 Bytes
c6a4629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import polars as pl
concentrations = pl.read_csv("concentrations.csv")
import scanpy as sc
from joblib import Parallel, delayed
import gc 

drug_to_concentration = {
    row[0]: row[1]
    for row in concentrations.iter_rows()
}

def reduce(plate: int):
    try:
        print(f"Plate: {plate}")
        X = sc.read_h5ad(f"../Data/h5ad/h5ad/plate{plate}_filt_Vevo_Tahoe100M_WServicesFrom_ParseGigalab.h5ad", backed="r")
        print(f"Loaded: {plate}")
        X = X[(X.obs["pass_filter"] == "full") & (X.obs["drugname_drugconc"].astype(str) == X.obs["drug"].map(lambda x: drug_to_concentration[x]).astype(str))]
        print(f"Filtered: {plate}")
        X.write_h5ad(f"../Data/h5ad/reduced/plate{plate}.h5ad")
        print(f"Wrote: {plate}")
        cells = X.n_vars
        del X
        gc.collect()
        return cells
    except Exception as e:
        print(f"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
        print(f"ERROR loading {plate}")
        print(f"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

results = Parallel(n_jobs=4)(delayed(reduce)(i) for i in range(1, 14 + 1))
print(results)