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