Example #1
0
def export_families(filename_prefix, families, file_format, include_project_column=False, include_case_review_columns=False):
    """Export Families table.

    Args:
        filename_prefix (string): Filename wihtout
        families (list): List of Django Family objects to include in the table
        file_format (string): "xls" or "tsv"
        include_project_column (bool): whether to add a column with the project name
        include_case_review_columns (bool): whether to include Case Review-related columns
    Returns:
        Django HttpResponse object with the table data as an attachment.
    """
    header = []

    if include_project_column:
        header.extend(['project'])

    header.extend([
        'family_id',
        'display_name',
        'created_date',
        'description',
        'analysis_status',
        'analysis_summary',
        'analysis_notes',
    ])

    if include_case_review_columns:
        header.extend([
            'internal_case_review_summary',
            'internal_case_review_notes',
        ])

    rows = []
    analysis_status_lookup = dict(Family.ANALYSIS_STATUS_CHOICES)
    for f in families:
        row = []
        if include_project_column:
            row.extend([f.project.name or f.project.project_id])

        row.extend([
            f.family_id,
            f.display_name,
            f.created_date,
            f.description,
            analysis_status_lookup.get(f.analysis_status, f.analysis_status),
            _convert_html_to_plain_text(f.analysis_summary, remove_line_breaks=(file_format == 'tsv')),
            _convert_html_to_plain_text(f.analysis_notes, remove_line_breaks=(file_format == 'tsv')),
        ])

        if include_case_review_columns:
            row.extend([
                _convert_html_to_plain_text(f.internal_case_review_summary, remove_line_breaks=(file_format == 'tsv')),
                _convert_html_to_plain_text(f.internal_case_review_notes, remove_line_breaks=(file_format == 'tsv')),
            ])

        rows.append(row)

    return export_table(filename_prefix, header, rows, file_format)
Example #2
0
def export_individuals(filename_prefix,
                       individuals,
                       file_format,
                       include_project_column=False,
                       include_display_name=False,
                       include_dates=False,
                       include_case_review_columns=False,
                       include_phenotips_columns=False):
    """Export Individuals table.

    Args:
        filename_prefix (string): Filename without the file extension.
        individuals (list): List of Django Individual objects to include in the table
        file_format (string): "xls" or "tsv"
        include_project_column (bool):
        include_display_name (bool):
        include_dates (bool):
        include_case_review_columns (bool):
        include_phenotips_columns (bool):

    Returns:
        Django HttpResponse object with the table data as an attachment.
    """

    header = []
    if include_project_column:
        header.extend(['project'])

    header.extend([
        'family_id',
        'individual_id',
        'paternal_id',
        'maternal_id',
        'sex',
        'affected_status',
        'notes',
    ])

    if include_display_name:
        header.extend(['display_name'])

    if include_dates:
        header.extend(['created_date'])

    if include_case_review_columns:
        header.extend([
            'case_review_status',
            'case_review_status_last_modified_date',
            'case_review_status_last_modified_by',
            'case_review_discussion',
        ])

    if include_phenotips_columns:
        phenotips_columns_header = [
            'phenotips_features_present', 'phenotips_features_absent',
            'paternal_ancestry', 'maternal_ancestry', 'age_of_onset'
        ]
        header.extend(phenotips_columns_header)

    rows = []
    for i in individuals:
        row = []
        if include_project_column:
            row.extend([i.family.project.name or i.family.project.project_id])

        row.extend([
            i.family.family_id,
            i.individual_id,
            i.paternal_id,
            i.maternal_id,
            _SEX_TO_EXPORT_VALUE.get(i.sex),
            _AFFECTED_TO_EXPORT_VALUE.get(i.affected),
            _convert_html_to_plain_text(i.notes),
        ])
        if include_display_name:
            row.extend([i.display_name])
        if include_dates:
            row.extend([i.created_date])

        if include_case_review_columns:
            row.extend([
                Individual.CASE_REVIEW_STATUS_LOOKUP.get(
                    i.case_review_status, ''),
                i.case_review_status_last_modified_date,
                _user_to_string(i.case_review_status_last_modified_by),
                i.case_review_discussion,
            ])

        if include_phenotips_columns:
            if i.phenotips_data:
                phenotips_json = json.loads(i.phenotips_data)
                phenotips_fields = _parse_phenotips_data(phenotips_json)
                row.extend(
                    [phenotips_fields[h] for h in phenotips_columns_header])
            else:
                row.extend(['' for h in phenotips_columns_header])

        rows.append(row)

    return export_table(filename_prefix, header, rows, file_format)
Example #3
0
def export_families(
    filename_prefix,
    families,
    file_format,
    include_project_name=False,
    include_internal_case_review_summary=False,
    include_internal_case_review_notes=False,
):
    """Export Families table.

    Args:
        filename_prefix (string): Filename wihtout
        families (list): List of Django Family objects to include in the table
        file_format (string): "xls" or "tsv"

    Returns:
        Django HttpResponse object with the table data as an attachment.
    """
    header = []

    if include_project_name:
        header.append('Project')

    header.extend([
        'Family ID',
        'Display Name',
        'Created Date',
        'Description',
        'Analysis Status',
        'Analysis Summary',
        'Analysis Notes',
    ])

    if include_internal_case_review_summary:
        header.append('Internal Case Review Summary')
    if include_internal_case_review_notes:
        header.append('Internal Case Review Notes')

    rows = []
    analysis_status_lookup = dict(Family.ANALYSIS_STATUS_CHOICES)
    for family in families:
        row = []
        if include_project_name:
            row.append(family.project.name or family.project.project_id)

        row.extend([
            family.family_id,
            family.display_name,
            family.created_date,
            family.description,
            analysis_status_lookup.get(family.analysis_status,
                                       family.analysis_status),
            _convert_html_to_plain_text(
                family.analysis_summary,
                remove_line_breaks=(file_format == 'tsv')),
            _convert_html_to_plain_text(
                family.analysis_notes,
                remove_line_breaks=(file_format == 'tsv')),
        ])

        if include_internal_case_review_summary:
            row.append(
                _convert_html_to_plain_text(
                    family.internal_case_review_summary,
                    remove_line_breaks=(file_format == 'tsv')), )
        if include_internal_case_review_notes:
            row.append(
                _convert_html_to_plain_text(
                    family.internal_case_review_notes,
                    remove_line_breaks=(file_format == 'tsv')), )

        rows.append(row)

    return export_table(filename_prefix, header, rows, file_format)
Example #4
0
def export_individuals(
    filename_prefix,
    individuals,
    file_format,
    include_project_name=False,
    include_display_name=False,
    include_created_date=False,
    include_case_review_status=False,
    include_case_review_last_modified_date=False,
    include_case_review_last_modified_by=False,
    include_case_review_discussion=False,
    include_hpo_terms_present=False,
    include_hpo_terms_absent=False,
    include_paternal_ancestry=False,
    include_maternal_ancestry=False,
    include_age_of_onset=False,
):
    """Export Individuals table.

    Args:
        filename_prefix (string): Filename without the file extension.
        individuals (list): List of Django Individual objects to include in the table
        file_format (string): "xls" or "tsv"

    Returns:
        Django HttpResponse object with the table data as an attachment.
    """

    header = []
    if include_project_name:
        header.append('Project')

    header.extend([
        'Family ID',
        'Individual ID',
        'Paternal ID',
        'Maternal ID',
        'Sex',
        'Affected Status',
        'Notes',
    ])

    if include_display_name:
        header.append('Display Name')
    if include_created_date:
        header.append('Created Date')
    if include_case_review_status:
        header.append('Case Review Status')
    if include_case_review_last_modified_date:
        header.append('Case Review Status Last Modified')
    if include_case_review_last_modified_by:
        header.append('Case Review Status Last Modified By')
    if include_case_review_discussion:
        header.append('Case Review Discussion')
    if include_hpo_terms_present:
        header.append('HPO Terms (present)')
    if include_hpo_terms_absent:
        header.append('HPO Terms (absent)')
    if include_paternal_ancestry:
        header.append('Paternal Ancestry')
    if include_maternal_ancestry:
        header.append('Maternal Ancestry')
    if include_age_of_onset:
        header.append('Age of Onset')

    rows = []
    for i in individuals:
        row = []
        if include_project_name:
            row.extend([i.family.project.name or i.family.project.project_id])

        row.extend([
            i.family.family_id,
            i.individual_id,
            i.paternal_id,
            i.maternal_id,
            _SEX_TO_EXPORTED_VALUE.get(i.sex),
            __AFFECTED_TO_EXPORTED_VALUE.get(i.affected),
            _convert_html_to_plain_text(i.notes),
        ])

        if include_display_name:
            row.append(i.display_name)
        if include_created_date:
            row.append(i.created_date)
        if include_case_review_status:
            row.append(
                Individual.CASE_REVIEW_STATUS_LOOKUP.get(
                    i.case_review_status, ''))
        if include_case_review_last_modified_date:
            row.append(i.case_review_status_last_modified_date)
        if include_case_review_last_modified_by:
            row.append(_user_to_string(i.case_review_status_last_modified_by))
        if include_case_review_discussion:
            row.append(i.case_review_discussion)

        if (include_hpo_terms_present or \
            include_hpo_terms_absent or \
            include_paternal_ancestry or \
            include_maternal_ancestry or \
            include_age_of_onset):
            if i.phenotips_data:
                phenotips_json = json.loads(i.phenotips_data)
                phenotips_fields = _parse_phenotips_data(phenotips_json)
            else:
                phenotips_fields = {}

            if include_hpo_terms_present:
                row.append(
                    phenotips_fields.get('phenotips_features_present', ''))
            if include_hpo_terms_absent:
                row.append(
                    phenotips_fields.get('phenotips_features_absent', ''))
            if include_paternal_ancestry:
                row.append(phenotips_fields.get('paternal_ancestry', ''))
            if include_maternal_ancestry:
                row.append(phenotips_fields.get('maternal_ancestry', ''))
            if include_age_of_onset:
                row.append(phenotips_fields.get('age_of_onset', ''))

        rows.append(row)

    return export_table(filename_prefix, header, rows, file_format)