NASA_OSDR / NASA_OSDR.py
anz2's picture
fix data access issues
7ca8ff6
# coding=utf-8
# Copyright 2020 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.
"""NASA_OSDR dataset"""
import json
import os
import datasets
import pandas as pd
_CITATION = """
@inproceedings{singh2019towards,
title={},
author={},
booktitle={},
pages={},
year={}
}
"""
_DESCRIPTION = """
TODO: write description
"""
_HOMEPAGE = "https://"
_LICENSE = ""
_SPLITS = ["train"]
_FIFTYONE_DATASET_URL = ""
class NasaOsdr(datasets.GeneratorBasedBuilder):
"""NASA OSDR dataset."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="NASA_OSDR",
version=datasets.Version("1.0.0"),
description=_DESCRIPTION,
)
]
DEFAULT_CONFIG_NAME = "NASA_OSDR"
def _info(self):
ASSAY_COLUMNS = ['Sample Name', 'Protocol REF', 'Parameter Value: DNA Fragmentation',
'Parameter Value: DNA Fragment Size', 'Extract Name', 'Protocol REF.1',
'Parameter Value: Library Strategy',
'Parameter Value: Library Selection', 'Parameter Value: Library Layout',
'Protocol REF.2', 'Parameter Value: Sequencing Instrument',
'Assay Name', 'Parameter Value: Read Length', 'Raw Data File',
'Protocol REF.3', 'Parameter Value: Read Depth',
'Parameter Value: MultiQC File Names']
# SAMPLE_COLUMNS = ['Source Name', 'Sample Name', 'Characteristics: Organism',
# 'Characteristics: Strain', 'Characteristics: Genotype',
# 'Characteristics: Material Type', 'Factor Value: Ionizing Radiation',
# 'Factor Value: Generation', 'Protocol REF', 'Protocol REF.1',
# 'Parameter Value: ionizing radiation energy',
# 'Parameter Value: exposure duration',
# 'Parameter Value: absorbed radiation dose',
# 'Parameter Value: absorbed radiation dose rate',
# 'Parameter Value: ionizing radiation categorized by source',
# 'Protocol REF.2', 'Parameter Value: Sample Preservation Method',
# 'Parameter Value: Sample Storage Temperature',
# 'Parameter Value: Age at time of sample collection',
# 'Comment: Animal Source', 'Comment: Parental Treatment']
features = datasets.Features(
{
column_name: datasets.Value("string")
for column_name in ASSAY_COLUMNS
# for column_name in sorted(list(set(ASSAY_COLUMNS + SAMPLE_COLUMNS)))
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
_URL = "https://raw.githubusercontent.com/AnzorGozalishvili/NASA_ODSR_DATA/main"
_ASSAYS_FILE = "assays.csv"
_SAMPLES_FILE = "samples.csv"
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(
{
"train": {
"assays": os.path.join(self._URL, self._ASSAYS_FILE),
"samples": os.path.join(self._URL, self._ASSAYS_FILE)
},
}
)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"assays_file": downloaded_files['train']['assays'],
"samples_file": downloaded_files['train']['samples'],
},
),
]
def _generate_examples(self, assays_file: str, samples_file):
# assays = os.path.join(dataset_root, "assays.csv")
# samples = os.path.join(dataset_root, "samples.csv")
# there can be other metadata tables merged
assays_df = pd.read_csv(assays_file)
samples_df = pd.read_csv(samples_file)
for (idx, assay_row), (_, sample_row) in zip(assays_df.iterrows(), samples_df.iterrows()):
_item = {**assay_row.to_dict()}
# _item = {**assay_row.to_dict(), **sample_row.to_dict()}
yield idx, _item