Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion condaEnv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ channels:
dependencies:
- python=3.10 # required for in-house codebase compatibility
- pandas
- samtools
# - samtools
- isatools
- multiqc
- schema
Expand Down
140 changes: 140 additions & 0 deletions dp_tools/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from dp_tools.core.check_model import ValidationProtocol, FlagCode

#########################################
# DATA MODEL INIT
#########################################

car = {
"wheels": [
{"isFlat": False},
{"isFlat": False},
{"isFlat": True}, # uh oh
{"isFlat": False},
],
"engineOkay": True,
"gasTank": 100,
"isElectric": False,
# doesn't apply so this entry isn't included
# "charge":0
}


#########################################
# Check function definitions
#########################################


def check_if_wheel_flat(wheel: dict):
if not wheel["isFlat"]:
code = FlagCode.GREEN
message = "Wheel is ready to go!"
else:
code = FlagCode.HALT
message = "This wheel is flat!"
return {"code": code, "message": message}


def check_engine_okay(car: dict):
if car["engineOkay"]:
code = FlagCode.GREEN
message = "Engine looks good"
else:
code = FlagCode.HALT
message = "Engine needs work!"
return {"code": code, "message": message}


def check_gas(cur_gas: float, minimum_gas: float):
if cur_gas >= minimum_gas:
code = FlagCode.GREEN
message = f"Gas tank is at {cur_gas}. Which is above {minimum_gas}"
else:
code = FlagCode.HALT
message = (
f"Gas tank needs a fill up! Current: {cur_gas}. Minimum: {minimum_gas}"
)
return {"code": code, "message": message}


def check_charge(cur_charge: float, minimum_charge: float):
if cur_charge >= minimum_charge:
code = FlagCode.GREEN
message = "Charge looks good"
else:
code = FlagCode.HALT
message = "Needs a charge!"
return {"code": code, "message": message}


#########################################
# Protocol definition
#########################################

vp = ValidationProtocol()
with vp.component_start(
name="PreDrive Check",
description="Make sure the car is ready for the trip",
):

with vp.component_start(
name="Engine",
description="Make sure the engine is running fine",
):
with vp.payload(payloads=[{"car": car}]):
vp.add(check_engine_okay)

with vp.component_start(
name="Tires",
description="Make sure the tires are road ready",
):
with vp.payload(
payloads=[
{"wheel": car["wheels"][0]},
{"wheel": car["wheels"][1]},
{"wheel": car["wheels"][2]},
{"wheel": car["wheels"][3]},
]
):
vp.add(check_if_wheel_flat)

with vp.component_start(
name="Fuel",
description="Check gas or charge is sufficent",
):
# NOTE: lambda is used in payload to defer evaluation conditioned
# on whether the check is run or skipped.
with vp.payload(payloads=[{"cur_gas": lambda: car["gasTank"]}]):
vp.add(check_gas, config={"minimum_gas": 95}, skip=(car["isElectric"]))

with vp.payload(payloads=[{"cur_charge": lambda: car["charge"]}]):
vp.add(
check_charge,
config={"minimum_charge": 95},
skip=(not car["isElectric"]),
)


#########################################
# Running Protocol
#########################################

# Now printing the queued checks
print(vp.queued_checks())

print("********************************")
# Running the checks
vp.run()
vp.run(skip_components = ["Tires"])

# And showing the results
print(vp.report()["flag_table"])

print("Individual Flag Row")
print(vp.report()["flag_table"].iloc[5].to_dict())


#########################################
# Exporting Protocol Results to File
#########################################

vp.report()["flag_table"].to_csv("VV_log.tsv", sep = "\t")
65 changes: 37 additions & 28 deletions dp_tools/microarray/checks.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
def check_if_valid_extensions(file, valid_ext):
"""description
params (description + data type)
return (description + data type)"""
pass
def check_factor():
"""description"""
pass

def check_if_extensions_valid(file, valid_ext):
""" Description of the function
Description Line 2

:param file: Input raw data file
:type file: Path
:param valid_ext: Extensions that are allow for the raw data files
:type valid_ext: list[str]
:return: A required fields-only flag entry dictionary
from enum import Flag
from dp_tools.core.check_model import FlagCode, FlagEntry
import pandas as pd

def check_factor_values_in_runsheet(runsheet_file: str) -> FlagEntry:
"""Verifies inclusion of factor values in runsheet

:param runsheet_file: Path to runsheet file
:type runsheet_file: str
:return: determination if factor value was located
:rtype: FlagEntry
"""
pass # Does nothing (... is equivalent)
runsheet = pd.read_csv(runsheet_file)
code = FlagCode.HALT
message = f"Runsheet does not have a Factor Value column"
for col_name in runsheet.columns:
if "Factor Value" in col_name:
code = FlagCode.GREEN
message = f"Factor Value column detected in runsheet"
return {"code": code, "message": message}

def check_factor_values_in_runsheet():
""" Description of the function
Description Line 2
def check_html_file(html_file: str) -> FlagEntry:
"""Verifies if the rendered Rmarkdown file has a valid html extension

:param file: Input raw data file
:type file: Path
:param valid_ext: Extensions that are allow for the raw data files
:type valid_ext: list[str]
:return: A required fields-only flag entry dictionary
:param html_file: Path to rendered Rmarkdown
:type html_file: str
:return: determination if the file has a valid extension
:rtype: FlagEntry
"""
pass # Does nothing (... is equivalent)
if html_file[-4:] == "html":
code = FlagCode.GREEN
message = f"File is an html file"
else:
code = FlagCode.HALT
message = f"File is not an html file"
return {"code": code, "message": message}







9 changes: 9 additions & 0 deletions tests/checks/test_microarray_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dp_tools.microarray.checks import check_factor_values_in_runsheet

from dp_tools.core.check_model import FlagCode


def test_check_factor_values_in_runsheet():
res = check_factor_values_in_runsheet(r"C:\Users\linde\rmarkdown\affy_processing\data_runsheets\GLDS_6_runsheet.csv")
assert res["code"] == FlagCode.GREEN
assert res["message"]