qiprofile

qiprofile Package

breast_pathology

This module updates the qiprofile database Subject pathology information from the pathology Excel workbook file.

class qipipe.qiprofile.breast_pathology.BreastPathologyUpdate(subject)

Bases: qipipe.qiprofile.pathology.PathologyUpdate

The Breast pathology update facade.

Parameters:subject – the Subject Mongo Engine database object to update
__init__(subject)
Parameters:subject – the Subject Mongo Engine database object to update
encounter_type(row)

Overrides qipipe.qiprofile.Pathology.encounter_type() to specialize the intervention_type to BreastSurgery.

Parameters:row – the input row
Returns:the REST data model Encounter subclass
pathology_content(row)

Collects the pathology object from the given input row. This subclass implementation adds the non-empty embedded fields specific to this tumor type.

Parameters:row – the input row
Returns:the {attribute: value} content dictionary
qipipe.qiprofile.breast_pathology.HORMONES = ['estrogen', 'progesterone']

The receptor status hormones.

qipipe.qiprofile.breast_pathology.read(workbook, **condition)

This is a convenience method that wraps BreastPathologyWorksheet qipipe.qiprofile.xls.Worksheet.read().

Parameters:
  • workbook – the read-only openpyxl workbook object
  • condition – the qipipe.qiprofile.xls.Worksheet.read() filter condition
Returns:

the qipipe.qiprofile.xls.Worksheet.read() rows

qipipe.qiprofile.breast_pathology.update(subject, rows)

Updates the given subject data object from the Breast pathology XLS rows.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • rows – the input pathology read() rows list

chemotherapy

This module updates the qiprofile database Subject chemotherapy protocol information from a Chemotherapy Excel worksheet.

qipipe.qiprofile.chemotherapy.COL_ATTRS = {'Cumulative Amount (mg/m2 BSA)': 'amount'}

The following non-standard column-attribute associations: * The Cumulative Amount column is the amount attribute.

qipipe.qiprofile.chemotherapy.SHEET = 'Chemotherapy'

The input XLS sheet name.

qipipe.qiprofile.chemotherapy.read(workbook, **condition)

This is a convenience method that wraps ChemotherapyWorksheet qipipe.qiprofile.xls.Worksheet.read().

Parameters:
  • workbook – the read-only openpyxl workbook object
  • condition – the qipipe.qiprofile.xls.Worksheet.read() filter condition
Returns:

the qipipe.qiprofile.xls.Worksheet.read() rows

qipipe.qiprofile.chemotherapy.update(subject, rows)

Updates the given subject data object from the dosage XLS rows.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • rows – the input chemotherapy read() rows list

clinical

This module updates the qiprofile database clinical information from the clinical Excel workbook file.

qipipe.qiprofile.clinical.update(subject, in_file)

Updates the subject clinical database content from the given workbook file.

Parameters:
  • subject – the target qiprofile Subject to update
  • filename – the input file location

demographics

This module updates the qiprofile database Subject demographics information from the demographics Excel workbook file.

qipipe.qiprofile.demographics.COL_ATTRS = {'Race': 'races'}

The following non-standard column-attribute associations: * The Race column is the races attribute.

qipipe.qiprofile.demographics.SHEET = 'Demographics'

The input XLS sheet name.

qipipe.qiprofile.demographics.read(workbook, **condition)

Reads the demographics XLS row which matches the given subject.

Parameters:condition – the row selection filter
Returns:the Demographics sheet qipipe.qiprofile.xls.Worksheet.read() row bundle which matches the given subject, or None if no match was found
qipipe.qiprofile.demographics.update(subject, rows)

Updates the given subject data object from the given Demographics sheet rows.

There can be no more than one Demographics update input row for the given subject. The rows parameter is an iterable in order to conform to other sheet facade modules.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • rows – the input Demographics read() rows
Raises:

DemographicsError – if there is more than one input row

dosage

This module updates the qiprofile database Subject drug dosage information from a Chemotherapy Excel worksheet.

class qipipe.qiprofile.dosage.DosageUpdate(subject, agent_class, **defaults)

Bases: object

The dosage update abstract class.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • agent_class – the dosage agent class
  • defaults – the {attribute: value} row defaults
DEFAULTS = {'duration': 1}

The default duration is 1 day.

__init__(subject, agent_class, **defaults)
Parameters:
  • subject – the Subject Mongo Engine database object to update
  • agent_class – the dosage agent class
  • defaults – the {attribute: value} row defaults
update(rows)

Updates the subject data object from the given dosage XLS rows.

Parameters:rows – the input dosage qipipe.qiprofile.xls.Worksheet.read() rows list
class qipipe.qiprofile.dosage.DosageWorksheet(workbook, sheet, agent_class, **opts)

Bases: qipipe.qiprofile.xls.Worksheet

The dosage worksheet facade.

Parameters:
  • workbook – the qipipe.qiprofile.xls.Workbook object
  • sheet – the sheet name
  • agent_class – the agent class
  • opts – the additional qipipe.qiprofile.xls.Worksheet initializer options
__init__(workbook, sheet, agent_class, **opts)
Parameters:
  • workbook – the qipipe.qiprofile.xls.Workbook object
  • sheet – the sheet name
  • agent_class – the agent class
  • opts – the additional qipipe.qiprofile.xls.Worksheet initializer options

imaging

modeling

This module updates the qiprofile database modeling information from a XNAT experiment.

qipipe.qiprofile.modeling.update(session, resource)

Updates the modeling content for the given qiprofile session database object from the given XNAT modeling resource object.

Parameters:
  • session – the target qiprofile Session to update
  • resource – the XNAT modeling resource object

parse

qipipe.qiprofile.parse.COMMA_DELIM_REGEX = <_sre.SRE_Pattern object>

Match a comma with optional white space.

qipipe.qiprofile.parse.FALSE_REGEX = <_sre.SRE_Pattern object>

The valid False string representations are a case-insensitive match for F(alse)?, Neg(ative)?, Absent or N(o)?.

qipipe.qiprofile.parse.TRAILING_NUM_REGEX = <_sre.SRE_Pattern object>

A regular expression to extract the trailing number from a string.

qipipe.qiprofile.parse.TRUE_REGEX = <_sre.SRE_Pattern object>

The valid True string representations are a case-insensitive match for T(rue)?, Pos(itive)?, Present or Y(es)?.

qipipe.qiprofile.parse.TYPE_PARSERS = {<class 'mongoengine.fields.FloatField'>: <type 'float'>, <class 'mongoengine.fields.BooleanField'>: <function <lambda>>, <class 'mongoengine.fields.ListField'>: <function <lambda>>, <class 'mongoengine.fields.StringField'>: <type 'str'>, <class 'mongoengine.fields.DateTimeField'>: <function <lambda>>, <class 'mongoengine.fields.IntField'>: <type 'int'>}

The following type cast conversion parsers: * string field => str * integer field => int * float field => float * boolean field => parse_boolean() * list field => parse_list_string()

qipipe.qiprofile.parse.default_parsers(*classes)

Associates the data model class fields to a parse function composed as follows:

  • The type cast function in TYPE_PARSERS, if present
  • The controlled value lookup, if the field has controlled values
Parameters:classes – the data model classes
Returns:the {attribute: function} dictionary
qipipe.qiprofile.parse.extract_trailing_number(value)

Returns the integer at the end of the given input value, as follows:

  • If the input value is an integer, then the result is the input value.
  • Otherwise, if the input value has a string type, then the result is the trailing digits converted to an integer.
  • Any other value is an error.
Parameters:value – the input integer or string
Returns:the trailing integer
Raises:ParseError – if the input value type is not int or a string type
qipipe.qiprofile.parse.parse_boolean(value)

Parses the input value as follows:

  • If the input value is already a boolean, then return the value
  • If the input is None or the empty string, then return None
  • Otherwise, if the input is a string which matches
    TRUE_REGEX, then return True
  • Otherwise, if the input is a string which matches
    FALSE_REGEX, then return False
  • Any other value is an error.
Parameters:value – the input value
Returns:the value as a boolean
Raises:ParseError – if the value cannot be converted
qipipe.qiprofile.parse.parse_list_string(value)

Converts a comma-separated list input string to a list, e.g.:

>> from qipipe.qiprofile.parse import parse_list_string >> parse_list_string(‘White, Asian’) [‘White’, ‘Asian’]

Parameters:value – the input value
Returns:the value converted to a list
qipipe.qiprofile.parse.parse_trailing_number(s)
Parameters:s – the input string
Returns:the trailing number in the string
Raises:ParseError – if the input string does not have a trailing number

pathology

This module updates the qiprofile database Subject pathology information from the pathology Excel workbook file.

qipipe.qiprofile.pathology.COL_ATTRS = {'Tumor Width (mm)': 'width', 'Tumor Depth (mm)': 'depth', 'Tumor Size Score': 'size', 'Patient Weight (kg)': 'weight', 'Tumor Length (mm)': 'length'}

The following non-standard column-attribute associations:

  • Patient Weight (kg): Encounter.weight attribute
  • Tumor Size Score: TNM.size attribute
  • Tumor Length (mm): TumorExtent.length attribute
  • Tumor Width (mm): TumorExtent.width attribute
  • Tumor Depth (mm): TumorExtent.depth attribute
qipipe.qiprofile.pathology.ENCOUNTER_TYPES = {'Surgery': <class 'qirest_client.model.clinical.Surgery'>, 'Biopsy': <class 'qirest_client.model.clinical.Biopsy'>}

The encounter {name: class} dictionary.

qipipe.qiprofile.pathology.PARSERS = {'size': <function <lambda>>, 'body_part': <function <lambda>>, 'lesion_number': <type 'int'>, 'subject_number': <type 'int'>, 'intervention_type': <function <lambda>>}

The following parser associations:

  • subject_number is an int
  • intervention_type converts the string to an Encounter subclass
  • body_part is capitalized
  • size is a qirest_client.clinical.TNM.Size object
class qipipe.qiprofile.pathology.PathologyUpdate(subject, tumor_type, grade_class, pathology_class)

Bases: object

The pathology update abstract class.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • tumor_type – the subclass tumor type
Option pathology_class:
 

the REST data model TumorPathology subclass

Option grade_class:
 

the REST data model Grade subclass

__init__(subject, tumor_type, grade_class, pathology_class)
Parameters:
  • subject – the Subject Mongo Engine database object to update
  • tumor_type – the subclass tumor type
Option pathology_class:
 

the REST data model TumorPathology subclass

Option grade_class:
 

the REST data model Grade subclass

encounter_type(row)

Infers the encounter type from the given row. This base implementation returns the parsed row intervention_type value.

Parameters:row – the input row
Returns:the REST data model Encounter subclass
pathology_content(row)

Collects the TumorPathology content from the given input row. This base implementation collects the pathology attribute values from the matching input row attribute value. Other updates are a subclass responsibility.

Parameters:row – the input row
Returns:the {attribute: value} content dictionary
update(rows)

Updates the subject data object from the given pathology XLS rows.

Parameters:rows – the input pathology read() rows list
update_encounter(encounter, rows)

Update the encounter object from the given input row. This base implementation sets the encounter attribute values from the matching input row attribute value and calls update_pathology() to update the pathology. Other updates are a subclass responsibility.

Parameters:
  • encounter – the encounter object
  • rows – the input pathology read() rows for the encounter
class qipipe.qiprofile.pathology.PathologyWorksheet(workbook, *classes, **opts)

Bases: qipipe.qiprofile.xls.Worksheet

The Pathology worksheet facade.

Parameters:
  • workbook – the qipipe.qiprofile.xls.Workbook object
  • classes – the subclass-specific REST data model subclasses
  • opts – the following keyword arguments:
Option parsers:

the non-standard parsers {attribute: function} dictionary

Option column_attributes:
 

the non-standard {column name: attribute} dictionary

__init__(workbook, *classes, **opts)
Parameters:
  • workbook – the qipipe.qiprofile.xls.Workbook object
  • classes – the subclass-specific REST data model subclasses
  • opts – the following keyword arguments:
Option parsers:

the non-standard parsers {attribute: function} dictionary

Option column_attributes:
 

the non-standard {column name: attribute} dictionary

qipipe.qiprofile.pathology.SHEET = 'Pathology'

The worksheet name.

radiotherapy

This module updates the qiprofile database Subject radiation protocol information from a Radiotherapy Excel worksheet.

qipipe.qiprofile.radiotherapy.AGENT_DEFAULTS = {'beam_type': 'photon'}

The default beam type is photon.

qipipe.qiprofile.radiotherapy.COL_ATTRS = {'Cumulative Amount (Gy)': 'amount'}

The following non-standard column-attribute associations: * The Cumulative Amount column is the amount attribute.

qipipe.qiprofile.radiotherapy.SHEET = 'Radiotherapy'

The input XLS sheet name.

qipipe.qiprofile.radiotherapy.read(workbook, **condition)

This is a convenience method that wraps RadiotherapyWorksheet qipipe.qiprofile.xls.Worksheet.read().

Parameters:
  • workbook – the read-only openpyxl workbook object
  • condition – the qipipe.qiprofile.xls.Worksheet.read() filter condition
Returns:

the qipipe.qiprofile.xls.Worksheet.read() rows

qipipe.qiprofile.radiotherapy.update(subject, rows)

Updates the given subject data object from the dosage XLS rows.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • rows – the input radiotherapy read() rows list

sarcoma_pathology

This module updates the qiprofile database Subject pathology information from the pathology Excel workbook file.

qipipe.qiprofile.sarcoma_pathology.COL_ATTRS = {'Tumor Location': 'location'}

The following special column: attribute associations:

  • The Tumor Location column corresponds to the pathology location attribute
qipipe.qiprofile.sarcoma_pathology.PARSERS = {'necrosis_percent': <function <lambda>>}

The following special parsers: * The necrosis percent can be an integer or a range, e.g. 80-90.

class qipipe.qiprofile.sarcoma_pathology.SarcomaPathologyUpdate(subject)

Bases: qipipe.qiprofile.pathology.PathologyUpdate

The Sarcoma pathology update facade.

Parameters:subject – the Subject Mongo Engine database object to update
__init__(subject)
Parameters:subject – the Subject Mongo Engine database object to update
pathology_content(row)

Collects the pathology object from the given input row. This subclass implementation adds the following items:

  • If there are necrosis_percent and tnm items, then the TNM necrosis_score is inferred from the necrosis percent
Parameters:row – the input row
Returns:the {attribute: value} content dictionary
qipipe.qiprofile.sarcoma_pathology.read(workbook, **condition)

This is a convenience method that wraps SarcomaPathologyWorksheet qipipe.qiprofile.xls.Worksheet.read().

Parameters:
  • workbook – the read-only openpyxl workbook object
  • condition – the qipipe.qiprofile.xls.Worksheet.read() filter condition
Returns:

the qipipe.qiprofile.xls.Worksheet.read() rows

qipipe.qiprofile.sarcoma_pathology.update(subject, rows)

Updates the given subject data object from the Sarcoma pathology XLS rows.

Parameters:
  • subject – the Subject Mongo Engine database object to update
  • rows – the input pathology read() rows list

scan

This module updates the qiprofile database scan information from a XNAT experiment.

qipipe.qiprofile.scan.update(session, xscan)

Updates the scan content for the given qiprofile session database object from the given XNAT scan object.

Parameters:
  • session – the target qiprofile Session to update
  • xscan – the XNAT scan object

update

xls

class qipipe.qiprofile.xls.Reader(worksheet, attributes, **condition)

Bases: object

Reads an Excel worksheet.

Parameters:
  • worksheet – the worksheet object
  • conditional – the optional {attribute: value} row filter condition
__init__(worksheet, attributes, **condition)
Parameters:
  • worksheet – the worksheet object
  • conditional – the optional {attribute: value} row filter condition
read()

Returns a row generator, where each row is a {attribute: value} bunch. This generator yields each row which satisfies the following condition:

  1. the row is non-empty, i.e. has at least one cell value, and
  2. if this reader has a filter, then the row satisfies the filter condition
Returns:the filtered openpyxl row iterator
worksheet = None

The wrapped openpyxl worksheet.

qipipe.qiprofile.xls.load_workbook(filename)
Parameters:filename – the XLS workbook file location
Returns:the read-only openpyxl workbook object