annotate decoupler_pseudobulk.py @ 12:4523224b53ce draft default tip

planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
author ebi-gxa
date Fri, 13 Jun 2025 09:08:13 +0000
parents db14ac3f6b43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
1 import argparse
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
2
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
3 import anndata
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
4 import decoupler
11
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
5 import numpy as np
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
6 import pandas as pd
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
7
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
8
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
9 def get_pseudobulk(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
10 adata,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
11 sample_col,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
12 groups_col,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
13 layer=None,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
14 mode="sum",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
15 min_cells=10,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
16 min_counts=1000,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
17 use_raw=False,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
18 ):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
19 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
20 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
21 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
22 >>> adata.X = abs(adata.X).astype(int)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
23 >>> pseudobulk = get_pseudobulk(adata, "bulk_labels", "louvain")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
24 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
25
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
26 return decoupler.get_pseudobulk(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
27 adata,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
28 sample_col=sample_col,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
29 groups_col=groups_col,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
30 layer=layer,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
31 mode=mode,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
32 use_raw=use_raw,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
33 min_cells=min_cells,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
34 min_counts=min_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
35 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
36
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
37
11
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
38 def create_pseudo_replicates(adata, sample_key, num_replicates, seed=None):
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
39 """
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
40 Create pseudo replicates for each sample in the sample_key groups.
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
41
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
42 Parameters
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
43 ----------
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
44 adata : anndata.AnnData
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
45 The AnnData object.
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
46 sample_key : str
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
47 The column in adata.obs that defines the samples.
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
48 num_replicates : int
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
49 Number of pseudo replicates to create per sample.
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
50
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
51 Returns
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
52 -------
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
53 anndata.AnnData
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
54 The AnnData object with pseudo replicates.
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
55
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
56 Examples
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
57 --------
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
58 >>> import anndata
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
59 >>> import pandas as pd
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
60 >>> import numpy as np
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
61 >>> data = {
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
62 ... 'obs': pd.DataFrame({'sample': ['A', 'A', 'B', 'B']}),
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
63 ... 'X': np.array([[1, 0], [0, 1], [1, 1], [0, 0]])
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
64 ... }
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
65 >>> adata = anndata.AnnData(X=data['X'], obs=data['obs'])
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
66 >>> adata = create_pseudo_replicates(adata, 'sample', 2)
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
67 >>> adata.obs['sample_pseudo'].tolist()
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
68 ['A_rep1', 'A_rep2', 'B_rep1', 'B_rep2']
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
69 """
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
70 if seed is not None:
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
71 np.random.seed(seed)
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
72
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
73 new_sample_key = f"{sample_key}_pseudo"
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
74 adata.obs[new_sample_key] = adata.obs[sample_key].astype(str)
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
75
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
76 for sample in adata.obs[sample_key].unique():
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
77 sample_indices = adata.obs[
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
78 adata.obs[sample_key] == sample].index.to_numpy()
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
79 np.random.shuffle(sample_indices) # Shuffle the indices to randomize
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
80 replicate_size = int(len(sample_indices) / num_replicates)
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
81 for i in range(num_replicates):
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
82 start_idx = i * replicate_size
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
83 end_idx = start_idx + replicate_size
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
84 replicate_indices = sample_indices[start_idx:end_idx]
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
85 adata.obs.loc[replicate_indices, new_sample_key] = (
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
86 adata.obs.loc[replicate_indices, new_sample_key] + f"_rep{i+1}"
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
87 )
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
88
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
89 return adata
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
90
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
91
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
92 def prepend_c_to_index(index_value):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
93 if index_value and index_value[0].isdigit():
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
94 return "C" + index_value
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
95 return index_value
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
96
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
97
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
98 def genes_to_ignore_per_contrast_field(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
99 count_matrix_df,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
100 samples_metadata,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
101 sample_metadata_col_contrasts,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
102 min_counts_per_sample=5,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
103 use_cpms=False,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
104 ):
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
105 """
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
106 # This function calculates the genes to ignore per contrast field
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
107 # (e.g., bulk_labels, louvain).
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
108 # It does this by first getting the count matrix for each group,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
109 # then identifying genes with a count below a specified threshold.
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
110 # The genes to ignore are those that are present in more than a specified
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
111 # number of groups.
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
112
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
113 >>> import pandas as pd
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
114 >>> samples_metadata = pd.DataFrame({'sample':
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
115 ... ['S1', 'S2', 'S3',
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
116 ... 'S4', 'S5', 'S6'],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
117 ... 'contrast_field':
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
118 ... ['A', 'A', 'A', 'B', 'B', 'B']})
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
119 >>> count_matrix_df = pd.DataFrame(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
120 ... {'S1':
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
121 ... [30, 1, 40, 50, 30],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
122 ... 'S2':
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
123 ... [40, 2, 60, 50, 80],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
124 ... 'S3':
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
125 ... [80, 1, 60, 50, 50],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
126 ... 'S4': [1, 50, 50, 50, 2],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
127 ... 'S5': [3, 40, 40, 40, 2],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
128 ... 'S6': [0, 50, 50, 50, 1]})
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
129 >>> count_matrix_df.index = ['Gene1', 'Gene2', 'Gene3', 'Gene4', 'Gene5']
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
130 >>> df = genes_to_ignore_per_contrast_field(count_matrix_df,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
131 ... samples_metadata, min_counts_per_sample=5,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
132 ... sample_metadata_col_contrasts='contrast_field')
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
133 >>> df[df['contrast_field'] == 'A'].genes_to_ignore.tolist()[0]
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
134 'Gene2'
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
135 >>> df[df['contrast_field'] == 'B'].genes_to_ignore.tolist()[0]
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
136 'Gene1'
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
137 >>> df[df['contrast_field'] == 'B'].genes_to_ignore.tolist()[1]
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
138 'Gene5'
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
139 """
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
140
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
141 # Initialize a dictionary to store the genes to ignore per contrast field
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
142 contrast_fields = []
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
143 genes_to_ignore = []
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
144
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
145 # Iterate over the contrast fields
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
146 for contrast_field in samples_metadata[
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
147 sample_metadata_col_contrasts
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
148 ].unique():
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
149 # Get the count matrix for the current contrast field
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
150 count_matrix_field = count_matrix_df.loc[
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
151 :,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
152 (
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
153 samples_metadata[sample_metadata_col_contrasts]
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
154 == contrast_field
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
155 ).tolist(),
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
156 ]
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
157
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
158 # We derive min_counts from the number of samples with that
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
159 # contrast_field value
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
160 min_counts = count_matrix_field.shape[1] * min_counts_per_sample
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
161
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
162 if use_cpms:
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
163 # Convert counts to counts per million (CPM)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
164 count_matrix_field = (
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
165 count_matrix_field.div(count_matrix_field.sum(axis=1), axis=0)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
166 * 1e6
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
167 )
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
168 min_counts = 1 # use 1 CPM
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
169
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
170 # Calculate the total number of cells in the current contrast field
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
171 # (this produces a vector of counts per gene)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
172 total_counts_per_gene = count_matrix_field.sum(axis=1)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
173
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
174 # Identify genes with a count below the specified threshold
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
175 genes = total_counts_per_gene[
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
176 total_counts_per_gene < min_counts
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
177 ].index.tolist()
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
178 if len(genes) > 0:
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
179 # genes_to_ignore[contrast_field] = " ".join(genes)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
180 for gene in genes:
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
181 genes_to_ignore.append(gene)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
182 contrast_fields.append(contrast_field)
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
183 # transform gene_to_ignore to a DataFrame
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
184 # genes_to_ignore_df = pd.DataFrame(genes_to_ignore.items(),
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
185 # columns=["contrast_field", "genes_to_ignore"])
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
186 genes_to_ignore_df = pd.DataFrame(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
187 {"contrast_field": contrast_fields, "genes_to_ignore": genes_to_ignore}
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
188 )
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
189 return genes_to_ignore_df
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
190
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
191
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
192 # write results for loading into DESeq2
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
193 def write_DESeq2_inputs(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
194 pdata,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
195 layer=None,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
196 output_dir="",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
197 factor_fields=None,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
198 min_counts_per_sample_marking=20,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
199 ):
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
200 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
201 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
202 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
203 >>> adata.X = abs(adata.X).astype(int)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
204 >>> pseudobulk = get_pseudobulk(adata, "bulk_labels", "louvain")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
205 >>> write_DESeq2_inputs(pseudobulk)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
206 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
207 # add / to output_dir if is not empty or if it doesn't end with /
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
208 if output_dir != "" and not output_dir.endswith("/"):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
209 output_dir = output_dir + "/"
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
210 obs_for_deseq = pdata.obs.copy()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
211 # replace any index starting with digits to start with C instead.
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
212 obs_for_deseq.rename(index=prepend_c_to_index, inplace=True)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
213 # avoid dash that is read as point on R colnames.
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
214 obs_for_deseq.index = obs_for_deseq.index.str.replace("-", "_")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
215 obs_for_deseq.index = obs_for_deseq.index.str.replace(" ", "_")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
216 col_metadata_file = f"{output_dir}col_metadata.tsv"
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
217 # write obs to a col_metadata file
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
218 if factor_fields:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
219 # only output the index plus the columns in factor_fields in that order
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
220 obs_for_deseq[factor_fields].to_csv(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
221 col_metadata_file, sep="\t", index=True
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
222 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
223 else:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
224 obs_for_deseq.to_csv(col_metadata_file, sep="\t", index=True)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
225 # write var to a gene_metadata file
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
226 pdata.var.to_csv(f"{output_dir}gene_metadata.tsv", sep="\t", index=True)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
227 # write the counts matrix of a specified layer to file
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
228 if layer is None:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
229 # write the X numpy matrix transposed to file
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
230 df = pd.DataFrame(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
231 pdata.X.T, index=pdata.var.index, columns=obs_for_deseq.index
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
232 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
233 else:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
234 df = pd.DataFrame(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
235 pdata.layers[layer].T,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
236 index=pdata.var.index,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
237 columns=obs_for_deseq.index,
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
238 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
239 df.to_csv(f"{output_dir}counts_matrix.tsv", sep="\t", index_label="")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
240
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
241 if factor_fields:
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
242 df_genes_ignore = genes_to_ignore_per_contrast_field(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
243 count_matrix_df=df,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
244 samples_metadata=obs_for_deseq,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
245 sample_metadata_col_contrasts=factor_fields[0],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
246 min_counts_per_sample=min_counts_per_sample_marking,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
247 )
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
248 df_genes_ignore.to_csv(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
249 f"{output_dir}genes_to_ignore_per_contrast_field.tsv", sep="\t"
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
250 )
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
251
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
252
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
253 def plot_pseudobulk_samples(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
254 pseudobulk_data,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
255 groupby,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
256 figsize=(10, 10),
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
257 save_path=None,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
258 ):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
259 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
260 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
261 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
262 >>> adata.X = abs(adata.X).astype(int)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
263 >>> pseudobulk = get_pseudobulk(adata, "bulk_labels", "louvain")
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
264 >>> plot_pseudobulk_samples(pseudobulk,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
265 ... groupby=["bulk_labels", "louvain"],
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
266 ... figsize=(10, 10))
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
267 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
268 fig = decoupler.plot_psbulk_samples(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
269 pseudobulk_data, groupby=groupby, figsize=figsize, return_fig=True
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
270 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
271 if save_path:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
272 fig.savefig(f"{save_path}/pseudobulk_samples.png")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
273 else:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
274 fig.show()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
275
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
276
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
277 def plot_filter_by_expr(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
278 pseudobulk_data,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
279 group,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
280 min_count=None,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
281 min_total_count=None,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
282 save_path=None,
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
283 ):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
284 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
285 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
286 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
287 >>> adata.X = abs(adata.X).astype(int)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
288 >>> pseudobulk = get_pseudobulk(adata, "bulk_labels", "louvain")
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
289 >>> plot_filter_by_expr(pseudobulk, group="bulk_labels",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
290 ... min_count=10, min_total_count=200)
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
291 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
292 fig = decoupler.plot_filter_by_expr(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
293 pseudobulk_data,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
294 group=group,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
295 min_count=min_count,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
296 min_total_count=min_total_count,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
297 return_fig=True,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
298 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
299 if save_path:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
300 fig.savefig(f"{save_path}/filter_by_expr.png")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
301 else:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
302 fig.show()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
303
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
304
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
305 def filter_by_expr(pdata, min_count=None, min_total_count=None):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
306 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
307 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
308 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
309 >>> adata.X = abs(adata.X).astype(int)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
310 >>> pseudobulk = get_pseudobulk(adata, "bulk_labels", "louvain")
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
311 >>> pdata_filt = filter_by_expr(pseudobulk,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
312 ... min_count=10, min_total_count=200)
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
313 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
314 genes = decoupler.filter_by_expr(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
315 pdata, min_count=min_count, min_total_count=min_total_count
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
316 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
317 return pdata[:, genes].copy()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
318
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
319
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
320 def check_fields(fields, adata, obs=True, context=None):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
321 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
322 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
323 >>> adata = sc.datasets.pbmc68k_reduced()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
324 >>> check_fields(["bulk_labels", "louvain"], adata, obs=True)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
325 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
326
12
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
327 # Fields that will be created during the pseudobulking process
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
328 pseudobulk_generated_fields = ['psbulk_n_cells', 'psbulk_counts']
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
329
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
330 # Filter out the pseudobulk-generated fields from checking
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
331 fields_to_check = [field for field in fields
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
332 if field not in pseudobulk_generated_fields]
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
333
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
334 legend = ""
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
335 if context:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
336 legend = f", passed in {context},"
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
337 if obs:
12
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
338 if not set(fields_to_check).issubset(set(adata.obs.columns)):
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
339 raise ValueError(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
340 f"Some of the following fields {legend} are not present \
12
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
341 in adata.obs: {fields_to_check}. \
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
342 Possible fields are: {list(set(adata.obs.columns))}"
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
343 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
344 else:
12
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
345 if not set(fields_to_check).issubset(set(adata.var.columns)):
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
346 raise ValueError(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
347 f"Some of the following fields {legend} are not present \
12
4523224b53ce planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 626c1018b662202de10ce77f123fc27f584beb9c
ebi-gxa
parents: 11
diff changeset
348 in adata.var: {fields_to_check}. \
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
349 Possible fields are: {list(set(adata.var.columns))}"
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
350 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
351
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
352
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
353 def main(args):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
354 # Load AnnData object from file
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
355 adata = anndata.read_h5ad(args.adata_file)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
356
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
357 # Merge adata.obs fields specified in args.adata_obs_fields_to_merge
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
358 if args.adata_obs_fields_to_merge:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
359 # first split potential groups by ":" and iterate over them
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
360 for group in args.adata_obs_fields_to_merge.split(":"):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
361 fields = group.split(",")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
362 check_fields(fields, adata)
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
363 merge_adata_obs_fields(fields, adata)
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
364
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
365 check_fields([args.groupby, args.sample_key], adata)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
366
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
367 factor_fields = None
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
368 if args.factor_fields:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
369 factor_fields = args.factor_fields.split(",")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
370 check_fields(factor_fields, adata)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
371
11
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
372 # Create pseudo replicates if specified
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
373 if args.num_pseudo_replicates:
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
374 adata = create_pseudo_replicates(
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
375 adata, args.sample_key, args.num_pseudo_replicates, seed=args.seed
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
376 )
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
377 args.sample_key = f"{args.sample_key}_pseudo"
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
378
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
379 print(f"Using mode: {args.mode}")
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
380 # Perform pseudobulk analysis
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
381 pseudobulk_data = get_pseudobulk(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
382 adata,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
383 sample_col=args.sample_key,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
384 groups_col=args.groupby,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
385 layer=args.layer,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
386 mode=args.mode,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
387 use_raw=args.use_raw,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
388 min_cells=args.min_cells,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
389 min_counts=args.min_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
390 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
391
4
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
392 print("Created pseudo-bulk AnnData, checking if fields still make sense.")
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
393 print(
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
394 "If this fails this check, it might mean that you asked for factors \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
395 that are not compatible with you sample identifiers (ie. asked for \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
396 phase in the factors, but each sample contains more than one phase,\
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
397 try joining fields)."
4
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
398 )
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
399 if factor_fields:
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
400 check_fields(
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
401 factor_fields,
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
402 pseudobulk_data,
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
403 context=" after creation of pseudo-bulk AnnData",
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
404 )
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
405 print("Factors requested are adequate for the pseudo-bulked AnnData!")
6c30272fb587 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 54818daabaf1251642a267e5766f13741cb7faeb
ebi-gxa
parents: 3
diff changeset
406
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
407 # Plot pseudobulk samples
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
408 plot_pseudobulk_samples(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
409 pseudobulk_data,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
410 args.groupby,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
411 save_path=args.save_path,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
412 figsize=args.plot_samples_figsize,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
413 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
414
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
415 plot_filter_by_expr(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
416 pseudobulk_data,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
417 group=args.groupby,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
418 min_count=args.min_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
419 min_total_count=args.min_total_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
420 save_path=args.save_path,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
421 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
422
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
423 # Filter by expression if enabled
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
424 if args.filter_expr:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
425 filtered_adata = filter_by_expr(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
426 pseudobulk_data,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
427 min_count=args.min_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
428 min_total_count=args.min_total_counts,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
429 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
430
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
431 pseudobulk_data = filtered_adata
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
432
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
433 # Save the pseudobulk data
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
434 if args.anndata_output_path:
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
435 pseudobulk_data.write_h5ad(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
436 args.anndata_output_path, compression="gzip"
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
437 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
438
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
439 write_DESeq2_inputs(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
440 pseudobulk_data,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
441 output_dir=args.deseq2_output_path,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
442 factor_fields=factor_fields,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
443 min_counts_per_sample_marking=args.min_counts_per_sample_marking,
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
444 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
445
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
446 # if contrasts file is provided, produce a file with genes that should be
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
447 # filtered for each contrasts
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
448 if args.contrasts_file:
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
449 contrast_genes_df = identify_genes_to_filter_per_contrast(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
450 contrast_file=args.contrasts_file,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
451 min_perc_cells_expression=args.min_gene_exp_perc_per_cell,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
452 adata=adata,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
453 obs_field=args.groupby
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
454 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
455 contrast_genes_df.to_csv(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
456 f"{args.save_path}/genes_to_filter_by_contrast.tsv",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
457 sep="\t",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
458 index=False,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
459 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
460
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
461
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
462 def merge_adata_obs_fields(obs_fields_to_merge, adata):
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
463 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
464 Merge adata.obs fields specified in args.adata_obs_fields_to_merge
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
465
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
466 Parameters
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
467 ----------
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
468 obs_fields_to_merge : str
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
469 Fields in adata.obs to merge, comma separated
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
470 adata : anndata.AnnData
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
471 The AnnData object
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
472
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
473 Returns
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
474 -------
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
475 anndata.AnnData
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
476 The merged AnnData object
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
477
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
478 docstring tests:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
479 >>> import scanpy as sc
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
480 >>> ad = sc.datasets.pbmc68k_reduced()
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
481 >>> merge_adata_obs_fields(["bulk_labels","louvain"], ad)
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
482 >>> ad.obs.columns
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
483 Index(['bulk_labels', 'n_genes', 'percent_mito', 'n_counts', 'S_score',
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
484 'G2M_score', 'phase', 'louvain', 'bulk_labels_louvain'],
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
485 dtype='object')
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
486 """
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
487 field_name = "_".join(obs_fields_to_merge)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
488 for field in obs_fields_to_merge:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
489 if field not in adata.obs.columns:
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
490 raise ValueError(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
491 f"The '{field}' column is not present in adata.obs."
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
492 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
493 if field_name not in adata.obs.columns:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
494 adata.obs[field_name] = adata.obs[field].astype(str)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
495 else:
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
496 adata.obs[field_name] = (
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
497 adata.obs[field_name] + "_" + adata.obs[field].astype(str)
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
498 )
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
499
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
500
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
501 def identify_genes_to_filter_per_contrast(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
502 contrast_file, min_perc_cells_expression, adata, obs_field
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
503 ):
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
504 """
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
505 Identify genes to filter per contrast based on expression percentage.
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
506 We need those genes to be under the threshold for all conditions
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
507 in a contrast to be identified for further filtering. If
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
508 one condition has the gene expressed above the threshold, the gene
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
509 becomes of interest (it can be highly up or down regulated).
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
510
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
511 Parameters
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
512 ----------
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
513 contrast_file : str
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
514 Path to the contrasts file.
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
515 min_perc_cells_expression : float
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
516 Minimum percentage of cells that should express a gene.
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
517 adata: adata
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
518 Original AnnData file
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
519 obs_field: str
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
520 Field in the AnnData observations where the contrasts are defined.
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
521
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
522 Returns
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
523 -------
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
524 None
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
525
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
526 Examples
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
527 --------
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
528 >>> import anndata
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
529 >>> import pandas as pd
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
530 >>> import numpy as np
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
531 >>> import os
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
532 >>> from io import StringIO
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
533 >>> contrast_file = StringIO(f"contrast{os.linesep}condition1-\
7
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
534 condition2{os.linesep}\
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
535 2*(condition1)-condition2{os.linesep}")
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
536 >>> min_perc_cells_expression = 30.0
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
537 >>> data = {
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
538 ... 'obs': pd.DataFrame({'condition': ['condition1', 'condition1',
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
539 ... 'condition2', 'condition2']}),
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
540 ... 'X': np.array([[1, 0, 0, 0, 0], [0, 0, 2, 2, 0],
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
541 ... [0, 0, 1, 1, 0], [0, 0, 0, 2, 0]]),
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
542 ... }
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
543 >>> adata = anndata.AnnData(X=data['X'], obs=data['obs'])
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
544 >>> df = identify_genes_to_filter_per_contrast(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
545 ... contrast_file, min_perc_cells_expression, adata, 'condition'
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
546 ... ) # doctest:+ELLIPSIS
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
547 Identifying genes to filter using ...
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
548 >>> df.head() # doctest:+ELLIPSIS
7
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
549 contrast gene
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
550 0 condition1-condition2...
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
551 1 condition1-condition2...
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
552 2 2*(condition1)-condition2...
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
553 3 2*(condition1)-condition2...
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
554 """
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
555 import re
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
556
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
557 # Implement the logic to identify genes to filter per contrast
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
558 # This is a placeholder implementation
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
559 print(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
560 f"Identifying genes to filter using {contrast_file} "
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
561 f"with min expression {min_perc_cells_expression}%"
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
562 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
563 sides_regex = re.compile(r"[\+\-\*\/\(\)\^]+")
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
564
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
565 contrasts = pd.read_csv(contrast_file, sep="\t")
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
566 # Iterate over each line in the contrast file
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
567 genes_filter_for_contrast = dict()
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
568 for contrast in contrasts.iloc[:, 0]:
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
569 conditions = set(sides_regex.split(contrast))
7
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
570
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
571 selected_conditions = []
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
572 failed_conditions = []
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
573 for condition in conditions:
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
574 # remove any starting or trailing whitespaces from condition
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
575 condition = condition.strip()
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
576 if len(condition) == 0:
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
577 continue
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
578 # check if the condition is simply a number, then skip it
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
579 if condition.isnumeric():
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
580 continue
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
581 if condition not in adata.obs[obs_field].unique():
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
582 # add condition to failed_conditions
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
583 failed_conditions.append(condition)
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
584 continue
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
585 # append to selected_conditions
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
586 selected_conditions.append(condition)
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
587
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
588 if len(failed_conditions) > 0:
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
589 raise ValueError(
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
590 f"Condition(s) '{failed_conditions}' "
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
591 f"from contrast {contrast} "
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
592 f"is/are not present in the "
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
593 f"obs_field '{obs_field}' from the AnnData object."
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
594 f"Possible values are: "
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
595 f"{', '.join(adata.obs[obs_field].unique())}.")
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
596 # we want to find the genes that are below the threshold
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
597 # of % of cells expressed for ALL the conditions in the
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
598 # contrast. It is enough for one of the conditions
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
599 # of the contrast to have the genes expressed above
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
600 # the threshold of % of cells to be of interest.
7
2c5686d627c0 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1efa285536ea940b459fd07f452a6eeb0cf0ffb9
ebi-gxa
parents: 6
diff changeset
601 for condition in selected_conditions:
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
602 # check the percentage of cells that express each gene
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
603 # Filter the AnnData object based on the obs_field value
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
604 adata_filtered = adata[adata.obs[obs_field] == condition]
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
605 # Calculate the percentage of cells expressing each gene
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
606 gene_expression = (adata_filtered.X > 0).mean(axis=0) * 100
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
607 genes_to_filter = set(adata_filtered.var[
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
608 gene_expression.transpose() < min_perc_cells_expression
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
609 ].index.tolist())
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
610 # Update the genes_filter_for_contrast dictionary
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
611 if contrast in genes_filter_for_contrast.keys():
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
612 genes_filter_for_contrast[contrast].intersection_update(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
613 genes_to_filter
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
614 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
615 else:
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
616 genes_filter_for_contrast[contrast] = genes_to_filter
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
617
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
618 # write the genes_filter_for_contrast to pandas dataframe of two columns:
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
619 # contrast and gene
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
620
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
621 # Initialize an empty list to store the expanded pairs
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
622 expanded_pairs = []
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
623
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
624 # Iterate over the dictionary
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
625 for contrast, genes in genes_filter_for_contrast.items():
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
626 for gene in genes:
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
627 expanded_pairs.append((contrast, gene))
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
628
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
629 # Create the DataFrame
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
630 contrast_genes_df = pd.DataFrame(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
631 expanded_pairs, columns=["contrast", "gene"]
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
632 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
633
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
634 return contrast_genes_df
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
635
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
636
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
637 if __name__ == "__main__":
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
638 # Create argument parser
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
639 parser = argparse.ArgumentParser(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
640 description="Perform pseudobulk analysis on an AnnData object"
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
641 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
642
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
643 # Add arguments
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
644 parser.add_argument(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
645 "adata_file", type=str, help="Path to the AnnData file"
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
646 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
647 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
648 "-m",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
649 "--adata_obs_fields_to_merge",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
650 type=str,
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
651 help="Fields in adata.obs to merge, comma separated. \
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
652 You can have more than one set of fields, \
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
653 separated by semi-colon ;",
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
654 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
655 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
656 "--groupby",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
657 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
658 required=True,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
659 help="The column in adata.obs that defines the groups",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
660 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
661 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
662 "--sample_key",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
663 required=True,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
664 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
665 help="The column in adata.obs that defines the samples",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
666 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
667 # add argument for layer
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
668 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
669 "--layer",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
670 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
671 default=None,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
672 help="The name of the layer of the AnnData object to use",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
673 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
674 # add argument for mode
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
675 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
676 "--mode",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
677 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
678 default="sum",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
679 help="The mode for Decoupler pseudobulk analysis",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
680 choices=["sum", "mean", "median"],
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
681 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
682 # add boolean argument for use_raw
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
683 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
684 "--use_raw",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
685 action="store_true",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
686 default=False,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
687 help="Whether to use the raw part of the AnnData object",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
688 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
689 # add argument for min_cells
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
690 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
691 "--min_cells",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
692 type=int,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
693 default=10,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
694 help="Minimum number of cells for pseudobulk analysis",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
695 )
5
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
696 # add argument for min percentage of cells that should express a gene
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
697 parser.add_argument(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
698 "--min_gene_exp_perc_per_cell",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
699 type=float,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
700 default=50,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
701 help="If all the conditions of one side of a contrast express a \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
702 gene in less than this percentage of cells, then the genes \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
703 will be added to a list of genes to ignore for that contrast.\
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
704 Requires the contrast file to be provided.",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
705 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
706 parser.add_argument(
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
707 "--contrasts_file",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
708 type=str,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
709 required=False,
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
710 help="Contrasts file, a one column tsv with a header, each line \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
711 represents a contrast as a combination of conditions at each \
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
712 side of a substraction.",
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
713 )
87f1eaa410cc planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit dea8a066ccf04e241457719bf5162f9d39fe6c48
ebi-gxa
parents: 4
diff changeset
714
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
715 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
716 "--save_path", type=str, help="Path to save the plot (optional)"
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
717 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
718 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
719 "--min_counts",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
720 type=int,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
721 help="Minimum count threshold for filtering by expression",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
722 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
723 parser.add_argument(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
724 "--min_counts_per_sample_marking",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
725 type=int,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
726 default=20,
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
727 help="Minimum count threshold per sample for \
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
728 marking genes to be ignored after DE",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
729 )
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
730 parser.add_argument(
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
731 "--min_total_counts",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
732 type=int,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
733 help="Minimum total count threshold for filtering by expression",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
734 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
735 parser.add_argument(
11
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
736 "--num_pseudo_replicates",
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
737 type=int,
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
738 choices=range(3, 1000),
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
739 help="Number of pseudo replicates to create per sample (at least 3)",
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
740 required=False
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
741 )
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
742 parser.add_argument(
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
743 "--seed",
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
744 type=int,
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
745 default=None,
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
746 help="Random seed for pseudo replicate sampling",
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
747 )
db14ac3f6b43 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 487508282bda9dbb68138d5c7091f46ef54fe52a
ebi-gxa
parents: 7
diff changeset
748 parser.add_argument(
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
749 "--anndata_output_path",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
750 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
751 help="Path to save the filtered AnnData object or pseudobulk data",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
752 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
753 parser.add_argument(
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
754 "--filter_expr",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
755 action="store_true",
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
756 help="Enable filtering by expression",
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
757 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
758 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
759 "--factor_fields",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
760 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
761 help="Comma separated list of fields for the factors",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
762 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
763 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
764 "--deseq2_output_path",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
765 type=str,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
766 help="Path to save the DESeq2 inputs",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
767 required=True,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
768 )
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
769 parser.add_argument(
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
770 "--plot_samples_figsize",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
771 type=int,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
772 default=[10, 10],
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
773 nargs=2,
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
774 help="Size of the samples plot as a tuple (two arguments)",
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
775 )
3
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
776 parser.add_argument(
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
777 "--plot_filtering_figsize", type=int, default=[10, 10], nargs=2
c6787c2aee46 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 0
diff changeset
778 )
0
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
779
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
780 # Parse the command line arguments
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
781 args = parser.parse_args()
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
782
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
783 # Call the main function
77d680b36e23 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 1034a450c97dcbb77871050cf0c6d3da90dac823
ebi-gxa
parents:
diff changeset
784 main(args)