ctheodoris commited on
Commit
ef094b2
1 Parent(s): bedb3b7

edit docs formatting

Browse files
docs/source/api.rst CHANGED
@@ -18,7 +18,7 @@ Classifier
18
  geneformer.classifier
19
 
20
  Multitask Classifier
21
- ----------
22
 
23
  .. toctree::
24
  :maxdepth: 1
 
18
  geneformer.classifier
19
 
20
  Multitask Classifier
21
+ --------------------
22
 
23
  .. toctree::
24
  :maxdepth: 1
docs/source/geneformer.mtl_classifier.rst CHANGED
@@ -1,5 +1,5 @@
1
  geneformer.mtl_classifier
2
- =====================
3
 
4
  .. automodule:: geneformer.mtl_classifier
5
  :members:
 
1
  geneformer.mtl_classifier
2
+ =========================
3
 
4
  .. automodule:: geneformer.mtl_classifier
5
  :members:
docs/source/geneformer.tokenizer.rst CHANGED
@@ -11,4 +11,5 @@ geneformer.tokenizer
11
  tokenize_files,
12
  tokenize_loom,
13
  rank_genes,
14
- tokenize_cell
 
 
11
  tokenize_files,
12
  tokenize_loom,
13
  rank_genes,
14
+ tokenize_cell,
15
+ sum_ensembl_ids
geneformer/mtl_classifier.py CHANGED
@@ -93,7 +93,9 @@ class MTLClassifier:
93
  ):
94
  """
95
  Initialize Geneformer multi-task classifier.
 
96
  **Parameters:**
 
97
  task_columns : list
98
  | List of tasks for cell state classification
99
  | Input data columns are labeled with corresponding task names
 
93
  ):
94
  """
95
  Initialize Geneformer multi-task classifier.
96
+
97
  **Parameters:**
98
+
99
  task_columns : list
100
  | List of tasks for cell state classification
101
  | Input data columns are labeled with corresponding task names
geneformer/tokenizer.py CHANGED
@@ -1,26 +1,41 @@
1
  """
2
  Geneformer tokenizer.
 
3
  **Input data:**
 
4
  | *Required format:* raw counts scRNAseq data without feature selection as .loom or anndata file.
5
  | *Required row (gene) attribute:* "ensembl_id"; Ensembl ID for each gene.
6
  | *Required col (cell) attribute:* "n_counts"; total read counts in that cell.
 
7
  | *Optional col (cell) attribute:* "filter_pass"; binary indicator of whether cell should be tokenized based on user-defined filtering criteria.
8
  | *Optional col (cell) attributes:* any other cell metadata can be passed on to the tokenized dataset as a custom attribute dictionary as shown below.
 
9
  **Usage:**
 
10
  .. code-block :: python
 
11
  >>> from geneformer import TranscriptomeTokenizer
12
  >>> tk = TranscriptomeTokenizer({"cell_type": "cell_type", "organ_major": "organ"}, nproc=4)
13
  >>> tk.tokenize_data("data_directory", "output_directory", "output_prefix")
 
14
  **Description:**
 
15
  | Input data is a directory with .loom or .h5ad files containing raw counts from single cell RNAseq data, including all genes detected in the transcriptome without feature selection. The input file type is specified by the argument file_format in the tokenize_data function.
 
16
  | The discussion below references the .loom file format, but the analagous labels are required for .h5ad files, just that they will be column instead of row attributes and vice versa due to the transposed format of the two file types.
 
17
  | Genes should be labeled with Ensembl IDs (loom row attribute "ensembl_id"), which provide a unique identifer for conversion to tokens. Other forms of gene annotations (e.g. gene names) can be converted to Ensembl IDs via Ensembl Biomart. Cells should be labeled with the total read count in the cell (loom column attribute "n_counts") to be used for normalization.
 
18
  | No cell metadata is required, but custom cell attributes may be passed onto the tokenized dataset by providing a dictionary of custom attributes to be added, which is formatted as loom_col_attr_name : desired_dataset_col_attr_name. For example, if the original .loom dataset has column attributes "cell_type" and "organ_major" and one would like to retain these attributes as labels in the tokenized dataset with the new names "cell_type" and "organ", respectively, the following custom attribute dictionary should be provided: {"cell_type": "cell_type", "organ_major": "organ"}.
 
19
  | Additionally, if the original .loom file contains a cell column attribute called "filter_pass", this column will be used as a binary indicator of whether to include these cells in the tokenized data. All cells with "1" in this attribute will be tokenized, whereas the others will be excluded. One may use this column to indicate QC filtering or other criteria for selection for inclusion in the final tokenized dataset.
 
20
  | If one's data is in other formats besides .loom or .h5ad, one can use the relevant tools (such as Anndata tools) to convert the file to a .loom or .h5ad format prior to running the transcriptome tokenizer.
21
- | OF NOTE: Take care that the correct token dictionary and gene median file is used for the correct model.
22
- | OF NOTE: For 95M model series, special_token should be True and model_input_size should be 4096.
23
- | OF NOTE: For 30M model series, special_token should be False and model_input_size should be 2048.
 
 
24
  """
25
 
26
  from __future__ import annotations
@@ -267,7 +282,9 @@ class TranscriptomeTokenizer:
267
  ):
268
  """
269
  Initialize tokenizer.
 
270
  **Parameters:**
 
271
  custom_attr_name_dict : None, dict
272
  | Dictionary of custom attributes to be added to the dataset.
273
  | Keys are the names of the attributes in the loom file.
@@ -291,6 +308,7 @@ class TranscriptomeTokenizer:
291
  | Path to pickle file containing token dictionary (Ensembl IDs:token).
292
  gene_mapping_file : None, Path
293
  | Path to pickle file containing dictionary for collapsing gene IDs.
 
294
  """
295
  # dictionary of custom attributes {output dataset column name: input .loom column name}
296
  self.custom_attr_name_dict = custom_attr_name_dict
@@ -366,7 +384,9 @@ class TranscriptomeTokenizer:
366
  ):
367
  """
368
  Tokenize .loom files in data_directory and save as tokenized .dataset in output_directory.
 
369
  **Parameters:**
 
370
  data_directory : Path
371
  | Path to directory containing loom files or anndata files
372
  output_directory : Path
@@ -377,6 +397,7 @@ class TranscriptomeTokenizer:
377
  | Format of input files. Can be "loom" or "h5ad".
378
  use_generator : bool
379
  | Whether to use generator or dict for tokenization.
 
380
  """
381
  tokenized_cells, cell_metadata = self.tokenize_files(
382
  Path(data_directory), file_format
 
1
  """
2
  Geneformer tokenizer.
3
+
4
  **Input data:**
5
+
6
  | *Required format:* raw counts scRNAseq data without feature selection as .loom or anndata file.
7
  | *Required row (gene) attribute:* "ensembl_id"; Ensembl ID for each gene.
8
  | *Required col (cell) attribute:* "n_counts"; total read counts in that cell.
9
+
10
  | *Optional col (cell) attribute:* "filter_pass"; binary indicator of whether cell should be tokenized based on user-defined filtering criteria.
11
  | *Optional col (cell) attributes:* any other cell metadata can be passed on to the tokenized dataset as a custom attribute dictionary as shown below.
12
+
13
  **Usage:**
14
+
15
  .. code-block :: python
16
+
17
  >>> from geneformer import TranscriptomeTokenizer
18
  >>> tk = TranscriptomeTokenizer({"cell_type": "cell_type", "organ_major": "organ"}, nproc=4)
19
  >>> tk.tokenize_data("data_directory", "output_directory", "output_prefix")
20
+
21
  **Description:**
22
+
23
  | Input data is a directory with .loom or .h5ad files containing raw counts from single cell RNAseq data, including all genes detected in the transcriptome without feature selection. The input file type is specified by the argument file_format in the tokenize_data function.
24
+
25
  | The discussion below references the .loom file format, but the analagous labels are required for .h5ad files, just that they will be column instead of row attributes and vice versa due to the transposed format of the two file types.
26
+
27
  | Genes should be labeled with Ensembl IDs (loom row attribute "ensembl_id"), which provide a unique identifer for conversion to tokens. Other forms of gene annotations (e.g. gene names) can be converted to Ensembl IDs via Ensembl Biomart. Cells should be labeled with the total read count in the cell (loom column attribute "n_counts") to be used for normalization.
28
+
29
  | No cell metadata is required, but custom cell attributes may be passed onto the tokenized dataset by providing a dictionary of custom attributes to be added, which is formatted as loom_col_attr_name : desired_dataset_col_attr_name. For example, if the original .loom dataset has column attributes "cell_type" and "organ_major" and one would like to retain these attributes as labels in the tokenized dataset with the new names "cell_type" and "organ", respectively, the following custom attribute dictionary should be provided: {"cell_type": "cell_type", "organ_major": "organ"}.
30
+
31
  | Additionally, if the original .loom file contains a cell column attribute called "filter_pass", this column will be used as a binary indicator of whether to include these cells in the tokenized data. All cells with "1" in this attribute will be tokenized, whereas the others will be excluded. One may use this column to indicate QC filtering or other criteria for selection for inclusion in the final tokenized dataset.
32
+
33
  | If one's data is in other formats besides .loom or .h5ad, one can use the relevant tools (such as Anndata tools) to convert the file to a .loom or .h5ad format prior to running the transcriptome tokenizer.
34
+
35
+ | OF NOTE: Take care that the correct token dictionary and gene median file is used for the correct model.
36
+
37
+ | OF NOTE: For 95M model series, special_token should be True and model_input_size should be 4096. For 30M model series, special_token should be False and model_input_size should be 2048.
38
+
39
  """
40
 
41
  from __future__ import annotations
 
282
  ):
283
  """
284
  Initialize tokenizer.
285
+
286
  **Parameters:**
287
+
288
  custom_attr_name_dict : None, dict
289
  | Dictionary of custom attributes to be added to the dataset.
290
  | Keys are the names of the attributes in the loom file.
 
308
  | Path to pickle file containing token dictionary (Ensembl IDs:token).
309
  gene_mapping_file : None, Path
310
  | Path to pickle file containing dictionary for collapsing gene IDs.
311
+
312
  """
313
  # dictionary of custom attributes {output dataset column name: input .loom column name}
314
  self.custom_attr_name_dict = custom_attr_name_dict
 
384
  ):
385
  """
386
  Tokenize .loom files in data_directory and save as tokenized .dataset in output_directory.
387
+
388
  **Parameters:**
389
+
390
  data_directory : Path
391
  | Path to directory containing loom files or anndata files
392
  output_directory : Path
 
397
  | Format of input files. Can be "loom" or "h5ad".
398
  use_generator : bool
399
  | Whether to use generator or dict for tokenization.
400
+
401
  """
402
  tokenized_cells, cell_metadata = self.tokenize_files(
403
  Path(data_directory), file_format