biodataome / biodataome.py
Witold Wydmański
fix: download metadata from mensxmachina
e2fbb9b
#%%
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]
# %%