File size: 1,497 Bytes
ab2bc10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import datasets

CSV_PATH = "./biovdb_1000.csv"

CITATION = """
"""

class CustomDataset(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")
    BUILDER_CONFIGS = []

    def _info(self):
        return datasets.DatasetInfo(
            description="Test set of ~1000 samples from GEO",
            citation=CITATION,
            homepage="",
        )
    
    def _split_generators(self, dl_manager):
        data = pd.read_csv(CSV_PATH)
        unique_series_ids = data['series_id'].unique()

        for series_id in unique_series_ids:
            self.BUILDER_CONFIGS.append(
                datasets.BuilderConfig(
                    name=str(series_id),
                    version=datasets.Version("1.0.0"),
                    description=f"Dataset for series_id {series_id}"
                )
            )
        
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={
                "data": data[data['series_id'] == self.config.name]
            }),
        ]

    def _generate_examples(self, data):
        metadata_columns = data.columns[:40]
        expression_columns = data.columns[40:]

        for idx, row in data.iterrows():
            yield idx, {
                "data": row[expression_columns].values.tolist(),
                "metadata": row[metadata_columns].to_dict()
            }

if __name__ == '__main__':
    ds = datasets.load_dataset("./biovdb_1000.py", "GSE52", split='train')