trying yet again to make work for both streaming settings
Browse files- merfish.py +14 -16
merfish.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import datasets
|
| 2 |
import os
|
| 3 |
import pandas as pd
|
| 4 |
-
import pyarrow.parquet as pq
|
| 5 |
-
|
| 6 |
|
| 7 |
class MERFISHConfig(datasets.BuilderConfig):
|
| 8 |
def __init__(self, **kwargs):
|
|
@@ -11,7 +9,7 @@ class MERFISHConfig(datasets.BuilderConfig):
|
|
| 11 |
|
| 12 |
class MERFISH(datasets.GeneratorBasedBuilder):
|
| 13 |
BUILDER_CONFIGS = [
|
| 14 |
-
MERFISHConfig(name="raw", description="Raw MERFISH
|
| 15 |
MERFISHConfig(name="processed", description="Processed MERFISH data"),
|
| 16 |
]
|
| 17 |
|
|
@@ -27,20 +25,20 @@ class MERFISH(datasets.GeneratorBasedBuilder):
|
|
| 27 |
)
|
| 28 |
|
| 29 |
def _split_generators(self, dl_manager):
|
| 30 |
-
base_path =
|
| 31 |
|
| 32 |
if dl_manager.is_streaming:
|
| 33 |
expression_files = list(dl_manager.iter_files(base_path))
|
| 34 |
else:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
for
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
gene_metadata = dl_manager.download(
|
| 43 |
-
cell_metadata = dl_manager.download(
|
| 44 |
|
| 45 |
return [
|
| 46 |
datasets.SplitGenerator(
|
|
@@ -56,8 +54,8 @@ class MERFISH(datasets.GeneratorBasedBuilder):
|
|
| 56 |
|
| 57 |
def _generate_examples(self, expression_files, gene_metadata_path, cell_metadata_path, fs):
|
| 58 |
if fs is not None:
|
| 59 |
-
gene_df = pd.read_parquet(fs.open(gene_metadata_path))
|
| 60 |
-
cell_df = pd.read_parquet(fs.open(cell_metadata_path))
|
| 61 |
else:
|
| 62 |
gene_df = pd.read_parquet(gene_metadata_path)
|
| 63 |
cell_df = pd.read_parquet(cell_metadata_path)
|
|
@@ -67,8 +65,8 @@ class MERFISH(datasets.GeneratorBasedBuilder):
|
|
| 67 |
idx = 0
|
| 68 |
for filepath in expression_files:
|
| 69 |
if fs is not None:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
else:
|
| 73 |
df = pd.read_parquet(filepath)
|
| 74 |
|
|
|
|
| 1 |
import datasets
|
| 2 |
import os
|
| 3 |
import pandas as pd
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class MERFISHConfig(datasets.BuilderConfig):
|
| 6 |
def __init__(self, **kwargs):
|
|
|
|
| 9 |
|
| 10 |
class MERFISH(datasets.GeneratorBasedBuilder):
|
| 11 |
BUILDER_CONFIGS = [
|
| 12 |
+
MERFISHConfig(name="raw", description="Raw MERFISH counts per gene"),
|
| 13 |
MERFISHConfig(name="processed", description="Processed MERFISH data"),
|
| 14 |
]
|
| 15 |
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
def _split_generators(self, dl_manager):
|
| 28 |
+
base_path = f"{self.config.name}/expression"
|
| 29 |
|
| 30 |
if dl_manager.is_streaming:
|
| 31 |
expression_files = list(dl_manager.iter_files(base_path))
|
| 32 |
else:
|
| 33 |
+
# Manually list known file parts if not streaming
|
| 34 |
+
num_parts = 87 # or use Hugging Face file listings to make this dynamic
|
| 35 |
+
expression_files = [
|
| 36 |
+
f"{base_path}/part-{i:07d}.parquet" for i in range(num_parts)
|
| 37 |
+
]
|
| 38 |
+
expression_files = dl_manager.download(expression_files)
|
| 39 |
|
| 40 |
+
gene_metadata = dl_manager.download(f"{self.config.name}/gene_metadata.parquet")
|
| 41 |
+
cell_metadata = dl_manager.download(f"{self.config.name}/cell_metadata.parquet")
|
| 42 |
|
| 43 |
return [
|
| 44 |
datasets.SplitGenerator(
|
|
|
|
| 54 |
|
| 55 |
def _generate_examples(self, expression_files, gene_metadata_path, cell_metadata_path, fs):
|
| 56 |
if fs is not None:
|
| 57 |
+
gene_df = pd.read_parquet(fs.open(gene_metadata_path, "rb"))
|
| 58 |
+
cell_df = pd.read_parquet(fs.open(cell_metadata_path, "rb"))
|
| 59 |
else:
|
| 60 |
gene_df = pd.read_parquet(gene_metadata_path)
|
| 61 |
cell_df = pd.read_parquet(cell_metadata_path)
|
|
|
|
| 65 |
idx = 0
|
| 66 |
for filepath in expression_files:
|
| 67 |
if fs is not None:
|
| 68 |
+
with fs.open(filepath, "rb") as f:
|
| 69 |
+
df = pd.read_parquet(f)
|
| 70 |
else:
|
| 71 |
df = pd.read_parquet(filepath)
|
| 72 |
|