Datasets:

Languages:
English
License:
gabrielaltay commited on
Commit
cea5f07
·
1 Parent(s): e7f7784

upload hubscripts/geokhoj_v1_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. geokhoj_v1.py +159 -0
geokhoj_v1.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """
17
+ GEOKhoj v1 contains metadata for 30,000 samples with their respective labels (control/perturbed),
18
+ which were labelled using the information available in the metadata.
19
+ Metadata has been extracted for samples from Microarray, Transcriptomics
20
+ and Single cell experiments which are available on the GEO (Gene Expression Omnibus) database.
21
+ """
22
+
23
+ import os
24
+ from typing import Dict, Tuple
25
+
26
+ import datasets
27
+ import pandas as pd
28
+
29
+ from .bigbiohub import text_features
30
+ from .bigbiohub import BigBioConfig
31
+ from .bigbiohub import Tasks
32
+
33
+ _LANGUAGES = ['English']
34
+ _PUBMED = False
35
+ _LOCAL = False
36
+ _CITATION = """\
37
+ @misc{geokhoj_v1,
38
+ author = {Elucidata, Inc.},
39
+ title = {GEOKhoj v1},
40
+ howpublished = {\\url{https://github.com/ElucidataInc/GEOKhoj-datasets/tree/main/geokhoj_v1}},
41
+ }
42
+ """
43
+
44
+ _DATASETNAME = "geokhoj_v1"
45
+ _DISPLAYNAME = "GEOKhoj v1"
46
+
47
+ _DESCRIPTION = """\
48
+ GEOKhoj v1 is a annotated corpus of control/perturbation labels for 30,000 samples
49
+ from Microarray, Transcriptomics and Single cell experiments which are available on
50
+ the GEO (Gene Expression Omnibus) database
51
+ """
52
+
53
+ _HOMEPAGE = "https://github.com/ElucidataInc/GEOKhoj-datasets/tree/main/geokhoj_v1"
54
+
55
+ _LICENSE = 'Creative Commons Attribution Non Commercial 4.0 International'
56
+
57
+ _URLS = {
58
+ "source": "https://github.com/ElucidataInc/GEOKhoj-datasets/blob/main/geokhoj_v1/geokhoj_V1.zip?raw=True",
59
+ "bigbio_text": "https://github.com/ElucidataInc/GEOKhoj-datasets/blob/main/geokhoj_v1/geokhoj_V1.zip?raw=True",
60
+ }
61
+
62
+ _SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]
63
+
64
+ _SOURCE_VERSION = "1.0.0"
65
+
66
+ _BIGBIO_VERSION = "1.0.0"
67
+
68
+
69
+ class Geokhojv1Dataset(datasets.GeneratorBasedBuilder):
70
+ """
71
+ GEOKhoj v1 text classification dataset
72
+ """
73
+
74
+ DEFAULT_CONFIG_NAME = "geokhoj_v1_source"
75
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
76
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
77
+
78
+ BUILDER_CONFIGS = [
79
+ BigBioConfig(
80
+ name="geokhoj_v1_source",
81
+ version=SOURCE_VERSION,
82
+ description="GEOKhoj v1 source schema",
83
+ schema="source",
84
+ subset_id="geokhoj_v1",
85
+ ),
86
+ BigBioConfig(
87
+ name="geokhoj_v1_bigbio_text",
88
+ version=BIGBIO_VERSION,
89
+ description="GEOKhoj v1 BigBio schema",
90
+ schema="bigbio_text",
91
+ subset_id="geokhoj_v1",
92
+ ),
93
+ ]
94
+
95
+ def _info(self):
96
+
97
+ if self.config.schema == "source":
98
+ features = datasets.Features(
99
+ {
100
+ "id": datasets.Value("string"),
101
+ "label": datasets.features.ClassLabel(
102
+ names={0: "control", 1: "perturbation"}
103
+ ),
104
+ "text": datasets.Value("string"),
105
+ }
106
+ )
107
+
108
+ elif self.config.schema == "bigbio_text":
109
+ features = text_features
110
+
111
+ return datasets.DatasetInfo(
112
+ description=_DESCRIPTION,
113
+ features=features,
114
+ homepage=_HOMEPAGE,
115
+ license=str(_LICENSE),
116
+ citation=_CITATION,
117
+ )
118
+
119
+ def _split_generators(self, dl_manager):
120
+ """Returns SplitGenerators."""
121
+ urls = _URLS[self.config.schema]
122
+ data_dir = dl_manager.download_and_extract(urls)
123
+ return [
124
+ datasets.SplitGenerator(
125
+ name=datasets.Split.TRAIN,
126
+ gen_kwargs={
127
+ "filepath": os.path.join(
128
+ data_dir, "geokhoj_v1/data/train/geo_samples_train.csv"
129
+ ),
130
+ "split": "train",
131
+ },
132
+ ),
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TEST,
135
+ gen_kwargs={
136
+ "filepath": os.path.join(
137
+ data_dir, "geokhoj_v1/data/test/geo_samples_test.csv"
138
+ ),
139
+ "split": "test",
140
+ },
141
+ ),
142
+ ]
143
+
144
+ def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
145
+ """Yields examples as (key, example) tuples."""
146
+ df = pd.read_csv(filepath, encoding="utf-8", header=None)
147
+
148
+ if self.config.schema == "source":
149
+ for id_, row in df.iterrows():
150
+ yield id_, {"id": row[0], "label": row[1], "text": row[2]}
151
+
152
+ elif self.config.schema == "bigbio_text":
153
+ for id_, row in df.iterrows():
154
+ yield id_, {
155
+ "id": id_ + 1,
156
+ "document_id": row[0],
157
+ "text": row[2],
158
+ "labels": [row[1]],
159
+ }