Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- data/mmusculus_gastrulation.h5ad +3 -0
- gastrulation_mmusculus.py +128 -0
.gitattributes
CHANGED
@@ -56,3 +56,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
56 |
# Video files - compressed
|
57 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
58 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
56 |
# Video files - compressed
|
57 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
58 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
59 |
+
data/mmusculus_gastrulation.h5ad filter=lfs diff=lfs merge=lfs -text
|
data/mmusculus_gastrulation.h5ad
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5ed6453ff6ff540871b627784b50d4f0a219110f3da702caa92304020b729d10
|
3 |
+
size 5841195942
|
gastrulation_mmusculus.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
"""The RNA Expression Baseclass."""
|
18 |
+
|
19 |
+
|
20 |
+
import json
|
21 |
+
import os
|
22 |
+
import anndata as ad
|
23 |
+
import pyarrow as pa
|
24 |
+
import pandas as pd
|
25 |
+
import numpy as np
|
26 |
+
|
27 |
+
import datasets
|
28 |
+
CITATION = """
|
29 |
+
Test
|
30 |
+
"""
|
31 |
+
|
32 |
+
DESCRIPTION = """
|
33 |
+
Test
|
34 |
+
"""
|
35 |
+
|
36 |
+
class RNAExpConfig(datasets.BuilderConfig):
|
37 |
+
"""BuilderConfig for RNAExpConfig."""
|
38 |
+
|
39 |
+
def __init__(self, features, data_url, citation, url, raw_counts="X", **kwargs):
|
40 |
+
"""BuilderConfig for RNAExpConfig.
|
41 |
+
Args:
|
42 |
+
features: `list[string]`, list of the features that will appear in the
|
43 |
+
feature dict. Should not include "label".
|
44 |
+
data_url: `string`, url to download the zip file from.
|
45 |
+
citation: `string`, citation for the data set.
|
46 |
+
url: `string`, url for information about the data set.
|
47 |
+
|
48 |
+
**kwargs: keyword arguments forwarded to super.
|
49 |
+
"""
|
50 |
+
# Version history:
|
51 |
+
# 0.0.1: Initial version.
|
52 |
+
super(RNAExpConfig, self).__init__(version=datasets.Version("0.0.1"), **kwargs)
|
53 |
+
self.features = features
|
54 |
+
self.data_url = data_url
|
55 |
+
self.citation = citation
|
56 |
+
self.url = url
|
57 |
+
self.raw_counts = raw_counts # Could be raw.X
|
58 |
+
self.batch = 1000
|
59 |
+
self.species = None
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
class RNAExp(datasets.ArrowBasedBuilder):
|
64 |
+
"""RNA Expression Baseclass."""
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
self.config = RNAExpConfig(
|
68 |
+
name = "mmusculus",
|
69 |
+
description = DESCRIPTION,
|
70 |
+
features = ["raw_counts",'cell_type'],
|
71 |
+
raw_counts = "X",
|
72 |
+
data_url = "./data/mmusculus_gastrulation.h5ad",
|
73 |
+
citation = CITATION,
|
74 |
+
url = "https://www.ebi.ac.uk/biostudies/arrayexpress/studies/E-MTAB-6967")
|
75 |
+
|
76 |
+
return datasets.DatasetInfo(
|
77 |
+
description= self.config.description,
|
78 |
+
features=None, #datasets.Features(features),
|
79 |
+
homepage=self.config.url,
|
80 |
+
citation=self.config.citation,
|
81 |
+
)
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager):
|
84 |
+
self.anndata_file = dl_manager.download_and_extract(self.config.data_url)
|
85 |
+
|
86 |
+
|
87 |
+
return [
|
88 |
+
datasets.SplitGenerator(
|
89 |
+
name=datasets.Split.TRAIN,
|
90 |
+
gen_kwargs={"split": "train","expression_file": self.anndata_file,"batch_size":self.config.batch},#,"gene_names_file": self.gene_names_file},
|
91 |
+
)
|
92 |
+
]
|
93 |
+
|
94 |
+
def _generate_tables(self, expression_file,batch_size,split):
|
95 |
+
idx = 0
|
96 |
+
adata = ad.read_h5ad(expression_file, backed = "r")
|
97 |
+
genes = adata.var_names.str.lower().to_list()
|
98 |
+
|
99 |
+
features = {"raw_counts": datasets.features.Sequence(datasets.features.Value("int32"),id = ",".join(adata.var.index.str.lower().tolist()))}
|
100 |
+
for feature in self.config.features:
|
101 |
+
if features.get(feature,None) is None:
|
102 |
+
features[feature] = datasets.Value("string")
|
103 |
+
|
104 |
+
self.info.features = datasets.Features(features)
|
105 |
+
|
106 |
+
|
107 |
+
# self.info.features['gene_names'] = datasets.features.ClassLabel(names = genes)
|
108 |
+
|
109 |
+
# self.info.description = adata.var.index.str.lower().tolist() #"+".join(adata.var.index.str.lower().tolist())
|
110 |
+
for batch in range(0,adata.shape[0],batch_size):
|
111 |
+
chunk = adata.X[batch:batch+batch_size].todense().astype('int32')
|
112 |
+
df = pd.DataFrame(chunk,columns=adata.var.index.str.lower())
|
113 |
+
df["raw_counts"] = [x for x in df.to_numpy()]
|
114 |
+
df = df[["raw_counts"]]
|
115 |
+
## We create a dummy column with all the names of the genes as list. We don't use this as value since this would unnecessarily increase the size of the dataset
|
116 |
+
## Another option would be to replace the description with the list of genes
|
117 |
+
# df[",".join(adata.var.index.str.lower().tolist())] = True
|
118 |
+
# df['gene_names'] = True
|
119 |
+
|
120 |
+
for feature in self.config.features:
|
121 |
+
if feature != "raw_counts":
|
122 |
+
df[feature] = adata.obs[feature][batch:batch+batch_size].tolist()
|
123 |
+
|
124 |
+
# df['gene_names'] = [adata.var.index.str.lower().tolist()]*batch_size
|
125 |
+
# print(df)
|
126 |
+
pa_table = pa.Table.from_pandas(df)
|
127 |
+
yield idx, pa_table
|
128 |
+
idx += 1
|