11import logging
22from typing import Annotated , Any , Literal , Dict , List , Optional , Union
33
4- import eido
54import numpy as np
65import pandas as pd
7- import peppy
6+ import peprs
87import yaml
98from dotenv import load_dotenv
109from fastapi import APIRouter , Body , Depends , Query
2928 ProjectViews ,
3029 HistoryAnnotationModel ,
3130)
32- from peppy .const import SAMPLE_RAW_DICT_KEY
31+ from peprs .const import SAMPLE_RAW_DICT_KEY
3332
3433# from ....const import SAMPLE_CONVERSION_FUNCTIONS
3534from ....dependencies import (
@@ -262,25 +261,23 @@ async def get_pep_samples(
262261 )
263262
264263 if isinstance (proj , dict ):
265- if len (proj ["_sample_dict" ]) > MAX_PROCESSED_PROJECT_SIZE :
264+ if len (proj [SAMPLE_RAW_DICT_KEY ]) > MAX_PROCESSED_PROJECT_SIZE :
266265 raise HTTPException (
267266 status_code = 400 ,
268267 detail = f"Project is too large. View raw samples, or create a view. Limit is { MAX_PROCESSED_PROJECT_SIZE } samples." ,
269268 )
270- proj = peppy .Project .from_dict (proj )
269+ proj = peprs .Project .from_dict (proj )
271270
272271 if format == "json" :
273272 return {
274273 "samples" : [sample .to_dict () for sample in proj .samples ],
275274 }
276275 elif format == "csv" :
277- return PlainTextResponse (eido . convert_project ( proj , "csv" )[ "samples" ] )
276+ return PlainTextResponse (proj . to_csv_string () )
278277 elif format == "yaml" :
279- return PlainTextResponse (
280- eido .convert_project (proj , "yaml-samples" )["samples" ]
281- )
278+ return PlainTextResponse (proj .to_yaml_string ())
282279 elif format == "basic" :
283- return eido . convert_project ( proj , "basic" )
280+ return proj . to_dict ( )
284281
285282 if raw :
286283 df = pd .DataFrame (proj [SAMPLE_RAW_DICT_KEY ])
@@ -289,12 +286,12 @@ async def get_pep_samples(
289286 items = df .replace ({np .nan : None }).to_dict (orient = "records" ),
290287 )
291288 if isinstance (proj , dict ):
292- if len (proj ["_sample_dict" ]) > MAX_PROCESSED_PROJECT_SIZE :
289+ if len (proj [SAMPLE_RAW_DICT_KEY ]) > MAX_PROCESSED_PROJECT_SIZE :
293290 raise HTTPException (
294291 status_code = 400 ,
295292 detail = f"Project is too large. View raw samples, or create a view. Limit is { MAX_PROCESSED_PROJECT_SIZE } samples." ,
296293 )
297- proj = peppy .Project .from_dict (proj )
294+ proj = peprs .Project .from_dict (proj )
298295 return [sample .to_dict () for sample in proj .samples ]
299296
300297
@@ -500,7 +497,7 @@ async def delete_sample(
500497
501498@project .get ("/subsamples" , response_model = SamplesResponseModel )
502499async def get_subsamples_endpoint (
503- subsamples : peppy . Project = Depends (get_subsamples ),
500+ subsamples : list = Depends (get_subsamples ),
504501 download : bool = False ,
505502):
506503 """
@@ -543,11 +540,8 @@ async def convert_pep(
543540 format : Optional [str ] = "plain" ,
544541):
545542 """
546- Convert a PEP to a specific format, f. For a list of available formats/filters,
547- see /eido/filters.
548-
549- See, http://eido.databio.org/en/latest/filters/#convert-a-pep-into-an-alternative-format-with-a-filter
550- for more information.
543+ Convert a PEP to a specific format. Supported filters are: basic, csv, yaml,
544+ yaml-samples, json.
551545
552546 Don't have a namespace, or project?
553547
@@ -559,18 +553,26 @@ async def convert_pep(
559553 """
560554 # default to basic
561555 if filter is None :
562- filter = "basic" # default to basic
556+ filter = "basic"
563557
564- # validate filter exists
565- filter_list = eido .get_available_pep_filters ()
566- if filter not in filter_list :
558+ # eido filter infrastructure is not in peprs; emulate the previously supported
559+ # filters using peprs Project conversion methods.
560+ available_filters = ["basic" , "csv" , "yaml" , "yaml-samples" , "json" ]
561+ if filter not in available_filters :
567562 raise HTTPException (
568- 400 , f"Unknown filter '{ filter } '. Available filters: { filter_list } "
563+ 400 , f"Unknown filter '{ filter } '. Available filters: { available_filters } "
569564 )
570565
571- # generate result
572- peppy_project = peppy .Project .from_dict (proj )
573- conv_result = eido .run_filter (peppy_project , filter , verbose = False )
566+ peprs_project = peprs .Project .from_dict (proj )
567+
568+ if filter == "basic" :
569+ conv_result = {"project_config.yaml" : peprs_project .to_yaml_string ()}
570+ elif filter == "csv" :
571+ conv_result = {"sample_table.csv" : peprs_project .to_csv_string ()}
572+ elif filter in ("yaml" , "yaml-samples" ):
573+ conv_result = {"sample_table.yaml" : peprs_project .to_yaml_string ()}
574+ else : # json
575+ conv_result = {"project.json" : peprs_project .to_json_string ()}
574576
575577 if format == "plain" :
576578 return_str = "\n " .join ([conv_result [k ] for k in conv_result ])
@@ -996,7 +998,7 @@ def get_project_history_by_id(
996998 with_id = True ,
997999 )
9981000 # convert the config to a yaml string
999- project_at_history ["_config " ] = yaml .dump (project_at_history ["_config " ])
1001+ project_at_history ["config " ] = yaml .dump (project_at_history ["config " ])
10001002 return project_at_history
10011003
10021004 except ProjectNotFoundError :
0 commit comments