Witold Wydmański commited on
Commit
7f403fc
·
1 Parent(s): 68c44ad

fix: fix dataset errors

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. metagenomic_curated.py +23 -20
README.md CHANGED
@@ -9,8 +9,8 @@ Please refer to the [study list](https://experimenthub.bioconductor.org/package/
9
 
10
  ## Sample usage
11
  ```python
12
- ds = datasets.load_dataset("wwydmanski/metagenomic_curated", "EH1914")
13
- X = np.array(ds['train']['features'])
14
  y = np.array([x['study_condition'] for x in ds['train']['metadata']])
15
  ```
16
 
 
9
 
10
  ## Sample usage
11
  ```python
12
+ ds = datasets.load_dataset("./metagenomic_curated.py", "EH1726")
13
+ X = np.array([list(i.values()) for i in ds['train']['features']])
14
  y = np.array([x['study_condition'] for x in ds['train']['metadata']])
15
  ```
16
 
metagenomic_curated.py CHANGED
@@ -1,4 +1,5 @@
1
  #%%
 
2
  import pyreadr
3
  import pandas as pd
4
  import numpy as np
@@ -8,6 +9,7 @@ import datasets
8
  import tempfile
9
  import rdata
10
  import json
 
11
 
12
  #%%
13
  sqlite_url = "https://experimenthub.bioconductor.org/metadata/experimenthub.sqlite3"
@@ -19,22 +21,6 @@ Pasolli E, Schiffer L, Manghi P, Renson A, Obenchain V, Truong D, Beghini F, Mal
19
  """
20
 
21
  # %%
22
- # def get_metadata():
23
- # with tempfile.NamedTemporaryFile(delete=False) as tmpfname:
24
- # r = requests.get(sqlite_url, allow_redirects=True)
25
- # open(tmpfname.name, 'wb').write(r.content)
26
-
27
- # db = sqlite3.connect(tmpfname.name)
28
- # cursor = db.cursor()
29
- # cur = cursor.execute("""SELECT * FROM resources""")
30
-
31
- # ehid = []
32
- # descriptions = []
33
- # for row in cur.fetchall():
34
- # if "curatedMetagenomicData" in str(row[-1]):
35
- # ehid.append(row[1])
36
- # descriptions.append(row[7])
37
- # return ehid, descriptions
38
 
39
  def get_metadata():
40
  ehids = []
@@ -62,12 +48,22 @@ class MetagenomicCurated(datasets.GeneratorBasedBuilder):
62
  for ehid, d in zip(ehids, descriptions)
63
  ]
64
 
 
 
 
65
  def _info(self):
 
 
 
 
 
 
66
  return datasets.DatasetInfo(
67
  description=self.config.description,
68
  citation=CITATION,
69
  homepage="https://waldronlab.io/curatedMetagenomicData/index.html",
70
  license="https://www.r-project.org/Licenses/Artistic-2.0",
 
71
  )
72
 
73
  def _split_generators(self, dl_manager):
@@ -87,22 +83,29 @@ class MetagenomicCurated(datasets.GeneratorBasedBuilder):
87
  parsed = rdata.parser.parse_file(filepath)
88
  converted = rdata.conversion.convert(parsed)
89
  expressions = list(converted.values())[0].assayData['exprs']
 
90
  data_df = expressions.to_pandas().T
 
 
91
  study_name = list(converted.keys())[0].split(".")[0]
92
 
93
  meta = pyreadr.read_r(rdata_path)['sampleMetadata']
94
  metadata = meta.loc[meta['study_name'] == study_name].set_index('sample_id')
95
 
96
  for idx, (i, row) in enumerate(data_df.iterrows()):
 
 
 
 
97
  yield idx, {
98
- "features": row.values,
99
- "metadata": {i: str(j) for i, j in metadata.loc[i].to_dict().items()}
100
  }
101
 
102
  # %%
103
  if __name__=="__main__":
104
- ds = datasets.load_dataset("./metagenomic_curated.py", "EH1914")
105
- X = np.array(ds['train']['features'])
106
  y = np.array([x['study_condition'] for x in ds['train']['metadata']])
107
 
108
  # %%
 
1
  #%%
2
+ from typing import Any
3
  import pyreadr
4
  import pandas as pd
5
  import numpy as np
 
9
  import tempfile
10
  import rdata
11
  import json
12
+ from typing import Any
13
 
14
  #%%
15
  sqlite_url = "https://experimenthub.bioconductor.org/metadata/experimenthub.sqlite3"
 
21
  """
22
 
23
  # %%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def get_metadata():
26
  ehids = []
 
48
  for ehid, d in zip(ehids, descriptions)
49
  ]
50
 
51
+ def __call__(self, *args: Any, **kwds: Any) -> Any:
52
+ return super().__call__(*args, **kwds)
53
+
54
  def _info(self):
55
+ try:
56
+ features = {
57
+ i: datasets.Value("float32") for i in self.features
58
+ }
59
+ except:
60
+ features = {}
61
  return datasets.DatasetInfo(
62
  description=self.config.description,
63
  citation=CITATION,
64
  homepage="https://waldronlab.io/curatedMetagenomicData/index.html",
65
  license="https://www.r-project.org/Licenses/Artistic-2.0",
66
+ # features=features
67
  )
68
 
69
  def _split_generators(self, dl_manager):
 
83
  parsed = rdata.parser.parse_file(filepath)
84
  converted = rdata.conversion.convert(parsed)
85
  expressions = list(converted.values())[0].assayData['exprs']
86
+
87
  data_df = expressions.to_pandas().T
88
+ self.features = data_df.columns
89
+
90
  study_name = list(converted.keys())[0].split(".")[0]
91
 
92
  meta = pyreadr.read_r(rdata_path)['sampleMetadata']
93
  metadata = meta.loc[meta['study_name'] == study_name].set_index('sample_id')
94
 
95
  for idx, (i, row) in enumerate(data_df.iterrows()):
96
+ try:
97
+ md = {i: str(j) for i, j in metadata.loc[i].to_dict().items()}
98
+ except KeyError:
99
+ md = {}
100
  yield idx, {
101
+ "features": row.to_dict(),
102
+ "metadata": md
103
  }
104
 
105
  # %%
106
  if __name__=="__main__":
107
+ ds = datasets.load_dataset("./metagenomic_curated.py", "EH1726")
108
+ X = np.array([list(i.values()) for i in ds['train']['features']])
109
  y = np.array([x['study_condition'] for x in ds['train']['metadata']])
110
 
111
  # %%