Skip to content

Commit

Permalink
add download type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgrent committed Jan 2, 2024
1 parent 8191724 commit 030a6e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/grein_loader/load_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
import json
import pandas
from typing import Tuple
from .exceptions import GreinLoaderException
from . import utils
#from .exceptions import GreinLoaderException
#from . import utils
from exceptions import GreinLoaderException
import utils

LOGGER = logging.getLogger(__name__)


def load_dataset(gse_id: str) -> Tuple[dict, dict, pandas.DataFrame]:
def load_dataset(gse_id: str, download_type: str="RAW") -> Tuple[dict, dict, pandas.DataFrame]:
""" Loads a dataset from GREIN.
:param: gse_id: The dataset's GSE id.
:param: gse_id: The dataset's GSE id, download_type: The type of data to download for expression value, either RAW or NORMALIZED
:type: gse_id: str
:return: description, metadata, count_matrix of the GREIN dataset
:rtype: description:dict, metadata:dictionary, count_matrix:pandas dataframe
Expand Down Expand Up @@ -212,6 +214,14 @@ def load_dataset(gse_id: str) -> Tuple[dict, dict, pandas.DataFrame]:
line_content = line.decode()
if "ACK" in line_content:
break

# in case method parameter is set to normalized, different request is send
if download_type == "NORMALIZED":
try:
xhr_send_r = s.post(xhr_send_url, data=payloads.count_matrix_normalized())
except requests.exceptions.HTTPError as err:
LOGGER.error("Streaming error for normailzed count matrix", err)
raise GreinLoaderException("Streaming error for normailzed count matrix", err)

# requesting count matrix
try:
Expand Down Expand Up @@ -323,4 +333,3 @@ def _generate_metadata_formdata(n_columns, no_samples=100):
n = n+1
raw_form += raw_utils.raw_form_end(no_samples)
return raw_form

3 changes: 3 additions & 0 deletions src/grein_loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def metadata_labels_parameter(self):
def count_matrix_parameter(self):
return '["18#0|m|{\\"method\\":\\"update\\",\\"data\\":{\\"counts_rows_selected\\":[],\\"counts_rows_current\\":[],\\"counts_rows_all\\":[],\\"counts_state\\":null,\\"counts_search\\":\\"\\",\\"counts_cell_clicked\\":{},\\".clientdata_output_downloadcounts_hidden\\":false}}"]'

def count_matrix_normalized(self):
return '["19#0|m|{\\"method\\":\\"update\\",\\"data\\":{\\"counts_choice\\":\\"Normalized\\"}}"]'

def raw_form_start(self):
return "draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false"

Expand Down

0 comments on commit 030a6e8

Please sign in to comment.