Example #1
0
def get_nr_samples_excel(orderform_path: str) -> int:
    """Parse a excel orderform file and return the number of sample rows"""
    orderform_parser = ExcelOrderformParser()
    workbook: Workbook = openpyxl.load_workbook(
        filename=orderform_path, read_only=True, data_only=True
    )
    sheet_name: str = orderform_parser.get_sheet_name(workbook.sheetnames)
    orderform_sheet: Worksheet = workbook[sheet_name]
    nr_samples = 0
    current_row = "unknown"
    for row in orderform_sheet.rows:
        if row[0].value == "</SAMPLE ENTRIES>":
            # End of samples
            break
        elif row[0].value == "<SAMPLE ENTRIES>":
            # Samples start here
            current_row = "samples"
            continue
        if current_row == "samples":
            values = []
            for cell in row:
                value = str(cell.value)
                if value == "None":
                    value = ""
                values.append(value)

            # skip empty rows
            if values[0]:
                nr_samples += 1
    return nr_samples
Example #2
0
def test_parse_rml_orderform(rml_orderform: str,
                             nr_samples_rml_orderform: int):
    """Test to parse an excel orderform in xlsx format"""
    # GIVEN a orderform in excel format
    assert is_excel(Path(rml_orderform))
    # GIVEN a orderform API
    order_form_parser = ExcelOrderformParser()
    # GIVEN the correct orderform name
    order_name: str = Path(rml_orderform).stem

    # WHEN parsing the RML orderform
    order_form_parser.parse_orderform(excel_path=rml_orderform)

    # THEN assert that the correct name was set
    assert order_form_parser.order_name == order_name

    # THEN assert that the number of samples was correct
    assert len(order_form_parser.samples) == nr_samples_rml_orderform
Example #3
0
def test_parse_mip_orderform(mip_orderform: str,
                             nr_samples_mip_orderform: int):
    """Test to parse a mip orderform in xlsx format"""
    # GIVEN a orderform in excel format
    assert is_excel(Path(mip_orderform))
    # GIVEN a orderform API
    order_form_parser = ExcelOrderformParser()
    # GIVEN the correct orderform name
    order_name: str = Path(mip_orderform).stem

    # WHEN parsing the mip orderform
    order_form_parser.parse_orderform(excel_path=mip_orderform)

    # THEN assert the number of samples parsed are correct
    assert len(order_form_parser.samples) == nr_samples_mip_orderform

    # THEN assert that the project type is correct
    assert order_form_parser.project_type == str(Pipeline.MIP_DNA)
Example #4
0
def test_parse_metagenome_orderform(metagenome_orderform: str):
    """Test to parse an metagenome orderform in excel format"""
    # GIVEN a order form in excel format
    assert is_excel(Path(metagenome_orderform))
    # GIVEN a orderform API
    orderform_parser: ExcelOrderformParser = ExcelOrderformParser()

    # WHEN parsing the orderform
    orderform_parser.parse_orderform(excel_path=metagenome_orderform)

    # THEN assert that the project type is correct
    assert orderform_parser.project_type == OrderType.METAGENOME
Example #5
0
def test_parse_microbial_orderform(microbial_orderform: str):
    """Test to parse a microbial orderform in excel format"""
    # GIVEN a order form in excel format
    assert is_excel(Path(microbial_orderform))
    # GIVEN a orderform API
    orderform_parser: ExcelOrderformParser = ExcelOrderformParser()

    # WHEN parsing the orderform
    orderform_parser.parse_orderform(excel_path=microbial_orderform)

    # THEN assert that the project type is correct
    assert orderform_parser.project_type == OrderType.MICROSALT
Example #6
0
def test_parse_balsamic_orderform(balsamic_orderform: str):
    """Test to parse an balsamic orderform in excel format"""
    # GIVEN a orderform in excel format
    assert is_excel(Path(balsamic_orderform))
    # GIVEN a orderform API
    orderform_parser: ExcelOrderformParser = ExcelOrderformParser()

    # WHEN parsing the orderform
    orderform_parser.parse_orderform(excel_path=balsamic_orderform)

    # THEN assert that the project type is correct
    assert orderform_parser.project_type == OrderType.BALSAMIC
Example #7
0
def test_generate_parsed_rml_orderform(rml_order_parser: ExcelOrderformParser,
                                       caplog):
    """Test to generate a order from a parsed rml excel file"""
    # GIVEN a order form parser that have parsed an excel file

    # WHEN generating the order
    order: Orderform = rml_order_parser.generate_orderform()

    # THEN assert that some samples where parsed and found
    assert order.samples
    # THEN assert that no cases where found since this is an RML order
    assert not order.cases
Example #8
0
def test_parse_sarscov2_orderform(sarscov2_orderform: str):
    """Test to parse a sarscov2 orderform in excel format"""

    # GIVEN a order form in excel format
    assert is_excel(Path(sarscov2_orderform))
    # GIVEN a orderform API
    orderform_parser: ExcelOrderformParser = ExcelOrderformParser()

    # WHEN parsing the orderform
    orderform_parser.parse_orderform(excel_path=sarscov2_orderform)

    # THEN assert that the project type is correct
    assert orderform_parser.project_type == OrderType.SARS_COV_2
Example #9
0
def test_parse_fastq_orderform(fastq_orderform: str,
                               nr_samples_fastq_orderform: int):
    """Test to parse an fastq orderform in xlsx format"""
    # GIVEN a orderform in excel format
    assert is_excel(Path(fastq_orderform))
    # GIVEN a orderform API
    order_form_parser = ExcelOrderformParser()
    # GIVEN the correct orderform name
    order_name: str = Path(fastq_orderform).stem

    # WHEN parsing the fastq orderform
    order_form_parser.parse_orderform(excel_path=fastq_orderform)

    # THEN assert that the correct name was set
    assert order_form_parser.order_name == order_name

    # THEN assert that the correct number if samples where parsed
    assert len(order_form_parser.samples) == nr_samples_fastq_orderform

    # THEN it should determine the project type
    assert order_form_parser.project_type == str(Pipeline.FASTQ)

    # THEN it should determine the correct customer should have been parsed
    assert order_form_parser.customer_id == "cust000"
Example #10
0
def test_generate_mip_orderform_with_cases(
        mip_order_parser: ExcelOrderformParser):
    """Test to parse a mip orderform with cases"""
    # GIVEN a mip orderform parser

    # WHEN generating a orderform
    orderform: Orderform = mip_order_parser.generate_orderform()

    # THEN assert that there where cases in the order
    assert len(orderform.cases) > 0

    case_obj = orderform.cases[0]
    assert len(case_obj.samples) == 3
    assert case_obj.name == "mipdnacase1"
    assert case_obj.priority == "research"
    assert set(case_obj.panels) == set(["AD-HSP", "Ataxi", "Actionable"])
Example #11
0
def fixture_fastq_order_parser(fastq_orderform: str) -> ExcelOrderformParser:
    """Return a orderform parser that have parsed an orderform in excel format"""
    order_form_parser = ExcelOrderformParser()
    order_form_parser.parse_orderform(excel_path=fastq_orderform)
    return order_form_parser