annotate decoupler_aucell_score.py @ 8:3c18dda2ea3f draft

planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit f6c6b8e014c99101232dc75aa972a12fc640a4de
author ebi-gxa
date Fri, 25 Oct 2024 15:12:14 +0000
parents c9aaac87c583
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
1 import argparse
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
2
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
3 import anndata
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
4 import decoupler as dc
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
5 import numba as nb
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
6 import pandas as pd
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
7
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
8
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
9 def read_gmt_long(gmt_file):
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
10 r"""
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
11 Reads a GMT file and produce a Pandas DataFrame in long format, ready to
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
12 be passed to the AUCell method.
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
13
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
14 Parameters
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
15 ----------
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
16 gmt_file : str
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
17 Path to the GMT file.
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
18
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
19 Returns
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
20 -------
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
21 pd.DataFrame
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
22 A DataFrame with the gene sets. Each row represents a gene set to gene
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
23 assignment, and the columns are "gene_set_name" and "genes".
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
24 >>> import os
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
25 >>> import tempfile
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
26 >>> line = "HALLMARK_NOTCH_SIGNALING\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
27 ... \thttp://www.gsea-msigdb.org/\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
28 ... gsea/msigdb/human/geneset/HALLMARK_NOTCH_SIGNALING\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
29 ... \tJAG1\tNOTCH3\tNOTCH2\tAPH1A\tHES1\tCCND1\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
30 ... \tFZD1\tPSEN2\tFZD7\tDTX1\tDLL1\tFZD5\tMAML2\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
31 ... \tNOTCH1\tPSENEN\tWNT5A\tCUL1\tWNT2\tDTX4\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
32 ... \tSAP30\tPPARD\tKAT2A\tHEYL\tSKP1\tRBX1\tTCF7L2\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
33 ... \tARRB1\tLFNG\tPRKCA\tDTX2\tST3GAL6\tFBXW11\n"
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
34 >>> line2 = "HALLMARK_APICAL_SURFACE\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
35 ... \thttp://www.gsea-msigdb.org/\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
36 ... gsea/msigdb/human/geneset/HALLMARK_APICAL_SURFACE\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
37 ... \tB4GALT1\tRHCG\tMAL\tLYPD3\tPKHD1\tATP6V0A4\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
38 ... \tCRYBG1\tSHROOM2\tSRPX\tMDGA1\tTMEM8B\tTHY1\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
39 ... \tPCSK9\tEPHB4\tDCBLD2\tGHRL\tLYN\tGAS1\tFLOT2\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
40 ... \tPLAUR\tAKAP7\tATP8B1\tEFNA5\tSLC34A3\tAPP\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
41 ... \tGSTM3\tHSPB1\tSLC2A4\tIL2RB\tRTN4RL1\tNCOA6\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
42 ... \tSULF2\tADAM10\tBRCA1\tGATA3\tAFAP1L2\tIL2RG\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
43 ... \tCD160\tADIPOR2\tSLC22A12\tNTNG1\tSCUBE1\tCX3CL1\
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
44 ... \tCROCC\n"
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
45 >>> temp_dir = tempfile.gettempdir()
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
46 >>> temp_gmt = os.path.join(temp_dir, "temp_file.gmt")
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
47 >>> with open(temp_gmt, "w") as f:
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
48 ... f.write(line)
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
49 ... f.write(line2)
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
50 288
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
51 380
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
52 >>> df = read_gmt_long(temp_gmt)
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
53 >>> df.shape[0]
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
54 76
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
55 >>> len(df.loc[df["gene_set"] == "HALLMARK_APICAL_SURFACE"].gene.tolist())
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
56 44
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
57 """
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
58 # Create a list of dictionaries, where each dictionary represents a
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
59 # gene set
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
60 gene_sets = {}
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
61
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
62 # Read the GMT file into a list of lines
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
63 with open(gmt_file, "r") as f:
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
64 while True:
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
65 line = f.readline()
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
66 if not line:
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
67 break
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
68 fields = line.strip().split("\t")
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
69 gene_sets[fields[0]] = fields[2:]
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
70
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
71 return pd.concat(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
72 pd.DataFrame({"gene_set": k, "gene": v}) for k, v in gene_sets.items()
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
73 )
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
74
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
75
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
76 def score_genes_aucell_mt(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
77 adata: anndata.AnnData,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
78 gene_set_gene: pd.DataFrame,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
79 use_raw=False,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
80 min_n_genes=5,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
81 var_gene_symbols_field=None,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
82 ):
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
83 """Score genes using Aucell.
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
84
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
85 Parameters
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
86 ----------
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
87 adata : anndata.AnnData
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
88 gene_set_gene: pd.DataFrame with columns gene_set and gene
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
89 use_raw : bool, optional, False by default.
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
90 min_n_genes : int, optional, 5 by default.
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
91 var_gene_symbols_field : str, optional, None by default. The field in var
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
92 where gene symbols are stored
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
93
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
94 >>> import scanpy as sc
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
95 >>> import decoupler as dc
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
96 >>> adata = sc.datasets.pbmc68k_reduced()
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
97 >>> r_gene_list = adata.var[
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
98 ... adata.var.index.str.startswith("RP")].index.tolist()
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
99 >>> m_gene_list = adata.var[
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
100 ... adata.var.index.str.startswith("M")].index.tolist()
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
101 >>> gene_set = {}
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
102 >>> gene_set["m"] = m_gene_list
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
103 >>> gene_set["r"] = r_gene_list
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
104 >>> gene_set_df = pd.concat(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
105 ... pd.DataFrame(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
106 ... {'gene_set':k, 'gene':v}
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
107 ... ) for k, v in gene_set.items())
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
108 >>> score_genes_aucell_mt(adata, gene_set_df, use_raw=False)
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
109 >>> "AUCell_m" in adata.obs.columns
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
110 True
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
111 >>> "AUCell_r" in adata.obs.columns
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
112 True
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
113 """
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
114
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
115 # if var_gene_symbols_fiels is provided, transform gene_set_gene df so
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
116 # that gene contains gene ids instead of gene symbols
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
117 if var_gene_symbols_field:
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
118 # merge the index of var to gene_set_gene df based on
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
119 # var_gene_symbols_field
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
120 var_id_symbols = adata.var[[var_gene_symbols_field]]
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
121 var_id_symbols["gene_id"] = var_id_symbols.index
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
122
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
123 gene_set_gene = gene_set_gene.merge(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
124 var_id_symbols,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
125 left_on="gene",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
126 right_on=var_gene_symbols_field,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
127 how="left",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
128 )
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
129 # this will still produce some empty gene_ids (genes in the
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
130 # gene_set_gene df that are not in the var df), fill those
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
131 # with the original gene symbol from the gene_set to avoid
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
132 # deforming the AUCell calculation
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
133 gene_set_gene["gene_id"] = gene_set_gene["gene_id"].fillna(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
134 gene_set_gene["gene"]
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
135 )
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
136 gene_set_gene["gene"] = gene_set_gene["gene_id"]
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
137
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
138 # run decoupler's run_aucell
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
139 dc.run_aucell(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
140 adata,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
141 net=gene_set_gene,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
142 source="gene_set",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
143 target="gene",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
144 use_raw=use_raw,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
145 min_n=min_n_genes,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
146 )
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
147 for gs in gene_set_gene.gene_set.unique():
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
148 if gs in adata.obsm["aucell_estimate"].keys():
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
149 adata.obs[f"AUCell_{gs}"] = adata.obsm["aucell_estimate"][gs]
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
150
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
151
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
152 def run_for_genelists(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
153 adata,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
154 gene_lists,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
155 score_names,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
156 use_raw=False,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
157 gene_symbols_field=None,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
158 min_n_genes=5,
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
159 ):
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
160 if len(gene_lists) == len(score_names):
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
161 for gene_list, score_names in zip(gene_lists, score_names):
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
162 genes = gene_list.split(",")
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
163 gene_sets = {}
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
164 gene_sets[score_names] = genes
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
165 gene_set_gene_df = pd.concat(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
166 pd.DataFrame({"gene_set": k, "gene": v})
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
167 for k, v in gene_sets.items()
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
168 )
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
169
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
170 score_genes_aucell_mt(
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
171 adata,
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
172 gene_set_gene_df,
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
173 use_raw,
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
174 min_n_genes,
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
175 var_gene_symbols_field=gene_symbols_field,
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
176 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
177 else:
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
178 raise ValueError(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
179 "The number of gene lists (separated by :) and score names \
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
180 (separated by :) must be the same"
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
181 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
182
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
183
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
184 if __name__ == "__main__":
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
185 # Create command-line arguments parser
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
186 parser = argparse.ArgumentParser(description="Score genes using Aucell")
1
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
187 parser.add_argument(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
188 "--input_file",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
189 type=str,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
190 help="Path to input AnnData file",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
191 required=True,
1
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
192 )
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
193 parser.add_argument(
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
194 "--output_file", type=str, help="Path to output file", required=True
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
195 )
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
196 parser.add_argument(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
197 "--gmt_file", type=str, help="Path to GMT file", required=False
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
198 )
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
199 # add argument for gene sets to score
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
200 parser.add_argument(
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
201 "--gene_sets_to_score",
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
202 type=str,
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
203 required=False,
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
204 help="Optional comma separated list of gene sets to score \
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
205 (the need to be in the gmt file)",
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
206 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
207 # add argument for gene list (comma separated) to score
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
208 parser.add_argument(
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
209 "--gene_lists_to_score",
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
210 type=str,
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
211 required=False,
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
212 help="Comma separated list of genes to score. You can have more \
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
213 than one set of genes, separated by colon :",
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
214 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
215 # argument for the score name when using the gene list
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
216 parser.add_argument(
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
217 "--score_names",
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
218 type=str,
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
219 required=False,
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
220 help="Name of the score column when using the gene list. You can \
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
221 have more than one set of score names, separated by colon :. \
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
222 It should be the same length as the number of gene lists.",
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
223 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
224 parser.add_argument(
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
225 "--gene_symbols_field",
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
226 type=str,
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
227 help="Name of the gene symbols field in the AnnData object",
1
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
228 required=True,
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
229 )
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
230 # argument for min_n Minimum of targets per source. If less, sources
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
231 # are removed.
3
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
232 parser.add_argument(
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
233 "--min_n",
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
234 type=int,
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
235 required=False,
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
236 default=5,
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
237 help="Minimum of targets per source. If less, sources are removed.",
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
238 )
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
239 parser.add_argument("--use_raw", action="store_true", help="Use raw data")
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
240 parser.add_argument(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
241 "--write_anndata",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
242 action="store_true",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
243 help="Write the modified AnnData object",
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
244 )
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
245 # argument for number of max concurrent processes
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
246 parser.add_argument(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
247 "--max_threads",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
248 type=int,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
249 required=False,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
250 default=1,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
251 help="Number of max concurrent threads",
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
252 )
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
253
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
254 # Parse command-line arguments
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
255 args = parser.parse_args()
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
256
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
257 nb.set_num_threads(n=args.max_threads)
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
258
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
259 # Load input AnnData object
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
260 adata = anndata.read_h5ad(args.input_file)
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
261
1
e024d8280886 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 56273bcfbc0de8f6ab093f1131a7d22c05a70f25
ebi-gxa
parents: 0
diff changeset
262 if args.gmt_file is not None:
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
263 # Load MSigDB file in GMT format
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
264 # msigdb = read_gmt(args.gmt_file)
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
265 msigdb = read_gmt_long(args.gmt_file)
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
266
3
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
267 gene_sets_to_score = (
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
268 args.gene_sets_to_score.split(",")
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
269 if args.gene_sets_to_score
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
270 else []
3
e887a7e8c5b4 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 11fb36a94b8262ef8e78f1c6dd46c4146eb59341
ebi-gxa
parents: 1
diff changeset
271 )
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
272 if gene_sets_to_score:
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
273 # we limit the GMT file read to the genesets specified in the
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
274 # gene_sets_to_score argument
4
515ac51db6e5 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit b01245159f9cb67101497bb974b2c13bcee019b7
ebi-gxa
parents: 3
diff changeset
275 msigdb = msigdb[msigdb["gene_set"].isin(gene_sets_to_score)]
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
276
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
277 score_genes_aucell_mt(
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
278 adata,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
279 msigdb,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
280 args.use_raw,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
281 args.min_n,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
282 var_gene_symbols_field=args.gene_symbols_field,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
283 )
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
284 elif args.gene_lists_to_score is not None and args.score_names is not None:
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
285 gene_lists = args.gene_lists_to_score.split(":")
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
286 score_names = args.score_names.split(",")
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
287 run_for_genelists(
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
288 adata,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
289 gene_lists,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
290 score_names,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
291 args.use_raw,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
292 args.gene_symbols_field,
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
293 args.min_n,
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
294 )
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
295
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
296 # Save the modified AnnData object or generate a file with cells as rows
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
297 # and the new score_names columns
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
298 if args.write_anndata:
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
299 adata.write_h5ad(args.output_file)
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
300 else:
5
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
301 new_columns = [
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
302 col for col in adata.obs.columns if col.startswith("AUCell_")
c9aaac87c583 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
ebi-gxa
parents: 4
diff changeset
303 ]
0
1e8697931d73 planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit c8c39f14eeee6e7a6d097fd0cb9430b12793eb8b
ebi-gxa
parents:
diff changeset
304 adata.obs[new_columns].to_csv(args.output_file, sep="\t", index=True)