File size: 2,460 Bytes
18b1614
 
 
 
 
 
 
 
 
 
e2fbb9b
18b1614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#%%
import datasets
import pandas as pd
import csv
import os

_ORIGIN = "http://dataome.mensxmachina.org/"
_CITATION = """ """

class BioDataome(datasets.GeneratorBasedBuilder):
    METADATA = pd.read_csv(f"http://dataome.mensxmachina.org/biodataome_data.csv")
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=i, 
                               version=datasets.Version("1.0.0"), 
                               description=d)
        for i, d in zip(
            METADATA["GSE"], 
            METADATA["Disease"],
            )
    ]

    def _info(self) -> datasets.DatasetInfo:
        return datasets.DatasetInfo(
            description="",
            citation=_CITATION,
            homepage=_ORIGIN,
            license="",
        )

    def _split_generators(self, dl_manager):
        gse = self.config.name
        url = self.METADATA[self.METADATA["GSE"] == gse]["Datapath"].values[0]
        metadata_url = self.METADATA[self.METADATA["GSE"] == gse]["DataAnnot"].values[0] 
        data: datasets.download.DownloadManager = dl_manager.download(url)
        metadata: datasets.download.DownloadManager = dl_manager.download(metadata_url)

        new_name = os.path.dirname(data) + "/" + os.path.basename(data).split(".")[0] + "_processed.csv"

        df = pd.read_csv(data, index_col=0)
        df = df.T
        df.to_csv(new_name, index=False)

        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": new_name, "metadata": metadata}),
        ]
    
    def _generate_examples(self, filepath, metadata):
        print(filepath)
        with open(filepath, "r") as f:
            f_header = f.readline()
            with open(metadata, "r") as m:
                m_header = m.readline()
                for key, (row, meta) in enumerate(zip(f, m)):
                    metadata = csv.reader([meta], quotechar='"').__next__()
                    row = row.split(",")
                    yield key, {
                        "data":
                        {
                            i.strip(): j for i, j in zip(f_header.split(","), row)
                        },
                        "metadata":
                        {
                            i.strip(): j for i, j in zip(m_header.split(","), metadata)
                        }
                    }

#%%
if __name__ == "__main__":
    ds = datasets.load_dataset("./load_script.py", "GSE17933")
    ds['train'][0]

# %%