Skip to content

Commit

Permalink
#3539 added lab compare export option (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharath-kandula authored Nov 15, 2023
1 parent 2be6619 commit 698544f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
} else if (labSelectionMode === 'include') {
inputError = 'You must include at least 1 lab';
}
if (format === 'lab_compare'){
if (selectedLabs.length !== 2) {
inputError = 'You must select 2 labs';
}
}

let selectedOrgs = $("input[name='org_selection']:checked");
if (selectedOrgs.length) {
Expand Down
2 changes: 2 additions & 0 deletions classification/views/classification_export_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def export_view(request: HttpRequest) -> Response:
format_clinvar_expert_compare = {'id': 'clinvar_compare_expert', 'name': 'ClinVar Expert Panel Compare', 'admin_only': True}
format_json = {'id': 'json', 'name': 'JSON'}
format_spelling = {'id': 'spelling', 'name': 'Spelling Report', 'admin_only': True}
format_lab_compare = {'id': 'lab_compare', 'name': 'Lab Compare', 'admin_only': True}
format_redcap = {'id': 'redcap', 'name': 'REDCap'}
format_vcf = {'id': 'vcf', 'name': 'VCF'}
formats = [
Expand All @@ -91,6 +92,7 @@ def export_view(request: HttpRequest) -> Response:
format_clinvar_compare,
format_clinvar_expert_compare,
format_spelling,
format_lab_compare,
format_json,
format_mvl
]
Expand Down
1 change: 1 addition & 0 deletions classification/views/exports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from classification.views.exports.classification_export_formatter_redcap import ClassificationExportFormatterRedCap
from classification.views.exports.classification_export_formatter_spelling import ClassificationExportFormatterSpelling
from classification.views.exports.classification_export_formatter_vcf import ClassificationExportFormatterVCF
from classification.views.exports.classification_export_formatter_lab_compare import ClassificationExportInternalCompare
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from typing import List

from django.http import HttpRequest
from django.urls.base import reverse

from classification.enums import SpecialEKeys
from classification.views.exports.classification_export_decorator import register_classification_exporter
from classification.views.exports.classification_export_filter import ClassificationFilter, AlleleData
from classification.views.exports.classification_export_formatter import ClassificationExportFormatter
from library.django_utils import get_url_from_view_path
from library.utils import ExportRow, export_column, delimited_row


class ClassificationlabCompareRow(ExportRow):

def __init__(self, AlleleData, lab1, lab2):
self.AlleleData = AlleleData
self.lab1 = lab1
self.lab2 = lab2

@export_column("Allele URL")
def allele_url(self):
url = get_url_from_view_path(reverse('view_allele', kwargs={"allele_id": self.AlleleData}))
return url

@export_column("Lab 1")
def lab_clinical_significance(self):
return self.lab1

@export_column("Lab 2")
def lab2_clinical_significance(self):
return self.lab2

@export_column("Difference")
def difference(self, lab_name1, lab_name2):
if (self.lab1 != '' and self.lab2 != '') and self.lab1 == self.lab2:
return 'Same'
elif self.lab1 == '' and self.lab2 != '':
return lab_name2
elif self.lab1 != '' and self.lab2 == '':
return lab_name1
elif self.lab1 != self.lab2:
return 'Different'
elif self.lab1 == '' and self.lab2 == '':
return 'No data'


@register_classification_exporter("lab_compare")
class ClassificationExportInternalCompare(ClassificationExportFormatter):

@classmethod
def from_request(cls, request: HttpRequest) -> 'ClassificationExportInternalCompare':
return ClassificationExportInternalCompare(
classification_filter=ClassificationFilter.from_request(request),
)

def content_type(self) -> str:
return "text/csv"

def extension(self) -> str:
return "csv"

def header(self) -> List[str]:
if self.classification_filter.include_sources and len(self.classification_filter.include_sources) == 2:
lab_names = sorted([str(lab) for lab in self.classification_filter.include_sources])
return [delimited_row(['Allele URL', lab_names[0], lab_names[1], 'Difference'], ',')]
else:
raise ValueError("Must specify 2 labs to compare")

def footer(self) -> List[str]:
return []

def row(self, allele_data: AlleleData) -> List[str]:
rows: List[str] = []
lab1 = set()
lab2 = set()
if self.classification_filter.include_sources:
lab_name1, lab_name2 = sorted(self.classification_filter.include_sources)
for cm in allele_data.cms_regardless_of_issues:
if cm.lab == lab_name1 and cm.clinical_significance is not None:
lab1.add(cm.get(SpecialEKeys.CLINICAL_SIGNIFICANCE))
if cm.lab == lab_name2 and cm.clinical_significance is not None:
lab2.add(cm.get(SpecialEKeys.CLINICAL_SIGNIFICANCE))

lab1_set = ','.join(lab1)
lab2_set = ','.join(lab2)
row = ClassificationlabCompareRow(AlleleData=allele_data.allele_id, lab1=lab1_set, lab2=lab2_set)
rows.append(delimited_row([row.allele_url(), row.lab_clinical_significance(),
row.lab2_clinical_significance(), row.difference(lab_name1, lab_name2)], ','))
else:
raise ValueError("Error comparing labs")
return rows

0 comments on commit 698544f

Please sign in to comment.