Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rmh brca #67

Merged
merged 15 commits into from
Feb 28, 2024
Merged
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
46 changes: 35 additions & 11 deletions lib/import/brca/providers/royal_marsden/royal_marsden_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ class RoyalMarsdenHandler < Import::Germline::ProviderHandler
'2b' => 2,
'2c' => 3,
'variant' => 2 }.freeze
NON_PATH_VARIANT_CLASS = { '2a' => 1,
'2b' => 2,
'variant' => 2 }.freeze

TEST_TYPE_MAP = { 'affected' => :diagnostic,
'unaffected' => :predictive }.freeze
# rubocop:disable Lint/MixedRegexpCaptureTypes
CDNA_REGEX_PROT = /c\.(?<cdna>.+)(?=(?<separtors>_|;.)p\.(?<impact>.+))/i.freeze
CDNA_REGEX_NOPROT = /c\.(?<cdna>.+)/i.freeze
CDNA_REGEX_PROT = /c\.(?<cdna>.+)(?=(?<separators>_|;.)p\.(?<impact>.+))/i
CDNA_REGEX_NOPROT = /c\.(?<cdna>.+)/i
DEL_DUP_REGEX = /(?<deldup>Deletion|Duplication)\s(ex|exon)s?\s?
(?<exon>\d+([a-z -]+\d+)?)|
(exon|ex)s?\s?(?<exon>\d+([a-z -]+\d+)?)\s?
Expand All @@ -50,8 +53,8 @@ def process_fields(record)
record.raw_fields,
PASS_THROUGH_FIELDS)
process_varpathclass(genotype, record)
process_teststatus(genotype, record)
process_variant(genotype, record)
process_teststatus(genotype, record)
process_large_deldup(genotype, record)
process_test_scope(genotype, record)
process_test_type(genotype, record)
Expand Down Expand Up @@ -85,6 +88,7 @@ def process_varpathclass(genotype, record)
@logger.debug 'NO VARIANT PATHCLASS DETECTED'
return
end

varpathclass = record.raw_fields['variantpathclass'].downcase.strip
# unless record.raw_fields['variantpathclass'].nil?
# if varpathclass.present? && VARIANT_PATH_CLASS[varpathclass]
Expand All @@ -98,15 +102,24 @@ def process_teststatus(genotype, record)
@logger.debug 'UNABLE TO DETERMINE TESTSTATUS'
return
end

teststatus = record.raw_fields['teststatus']
nonpathvarclass = record.raw_fields['variantpathclass']&.downcase&.strip
# unless record.raw_fields['teststatus'].nil?
if normal_test?(teststatus)
genotype.add_status(1)
elsif failed_test?(teststatus)
process_assign_teststatus(genotype, teststatus, nonpathvarclass)
end

def process_assign_teststatus(genotype, teststatus, nonpathvarclass)
if failed_test?(teststatus)
genotype.add_status(9)
genotype.add_variant_class(nil)
elsif non_pathogenic_variant_test?(teststatus, nonpathvarclass)
genotype.add_status(10)
elsif positive_test?(teststatus)
genotype.add_status(2)
elsif normal_test?(teststatus)
genotype.add_status(1)
elsif borderline_test?(teststatus)
genotype.add_status(7)
end
end

Expand Down Expand Up @@ -154,7 +167,6 @@ def process_large_deldup(genotype, record)

def normal_test?(teststatus)
%r{NO PATHOGENIC (VARIANT|DEL/DUP) IDENTIFIED}.match(teststatus) ||
/non-pathogenic variant detected/.match(teststatus) ||
/No mutation detected/.match(teststatus)
end

Expand All @@ -164,9 +176,21 @@ def failed_test?(teststatus)

def positive_test?(teststatus)
/c\..+/.match(teststatus) ||
/Deletion*/.match(teststatus) ||
/Duplication*/.match(teststatus) ||
/Exon*/i.match(teststatus)
/Deletion.*/.match(teststatus) ||
/Duplication.*/.match(teststatus) ||
/Exon.*/i.match(teststatus) ||
/Del.*ex\s?1*/i.match(teststatus) ||
/Ex.*del/i.match(teststatus) ||
/BRCA.*exon.*Deletion/i.match(teststatus)
end

def borderline_test?(teststatus)
/borderline/.match(teststatus)
end

def non_pathogenic_variant_test?(teststatus, nonpathvarclass)
/non-pathogenic\svariant\sdetected/i.match(teststatus) ||
NON_PATH_VARIANT_CLASS[nonpathvarclass]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,54 @@ def setup
normal_record.raw_fields['teststatus'] = 'NO PATHOGENIC VARIANT IDENTIFIED'
@handler.process_teststatus(@genotype, normal_record)
assert_equal 1, @genotype.attribute_map['teststatus']

non_path_record = build_raw_record('pseudo_id1' => 'bob')
non_path_record.raw_fields['teststatus'] = 'Ex del'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can raw_fields be passed to the build_raw_record method, eg:

broken_record = build_raw_record('pseudo_id1' => 'bob', raw_fields: { 'teststatus' => 'Ex del' } )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @ollietulloch ! I have tried that and it doesn't work- I think its because build new record adds the test status field by loading the rawtext_clinical_json. So that needs to be loaded first then we can update the test status afterwards. Let me know if there is another way!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, perhaps something for a future PR. It'd be nice for build_raw_record to be able to popluate raw_fields

non_path_record.raw_fields['variantpathclass'] = '2a'
@handler.process_teststatus(@genotype, non_path_record)
assert_equal 10, @genotype.attribute_map['teststatus']

non_path_record = build_raw_record('pseudo_id1' => 'bob')
non_path_record.raw_fields['teststatus'] = 'Ex del'
non_path_record.raw_fields['variantpathclass'] = '2b'
@handler.process_teststatus(@genotype, non_path_record)
assert_equal 10, @genotype.attribute_map['teststatus']

non_path_record = build_raw_record('pseudo_id1' => 'bob')
non_path_record.raw_fields['teststatus'] = 'Ex del'
non_path_record.raw_fields['variantpathclass'] = 'variant'
@handler.process_teststatus(@genotype, non_path_record)
assert_equal 10, @genotype.attribute_map['teststatus']

path_record = build_raw_record('pseudo_id1' => 'bob')
path_record.raw_fields['teststatus'] = 'Ex Del'
path_record.raw_fields['variantpathclass'] = '1b'
@handler.process_teststatus(@genotype, path_record)
assert_equal 2, @genotype.attribute_map['teststatus']

path_record = build_raw_record('pseudo_id1' => 'bob')
path_record.raw_fields['teststatus'] = 'Del ex 1'
path_record.raw_fields['variantpathclass'] = '1b'
@handler.process_teststatus(@genotype, path_record)
assert_equal 2, @genotype.attribute_map['teststatus']

path_record = build_raw_record('pseudo_id1' => 'bob')
path_record.raw_fields['teststatus'] = 'BRCA exon Deletion'
path_record.raw_fields['variantpathclass'] = '1b'
@handler.process_teststatus(@genotype, path_record)
assert_equal 2, @genotype.attribute_map['teststatus']

path_record = build_raw_record('pseudo_id1' => 'bob')
path_record.raw_fields['teststatus'] = 'borderline'
path_record.raw_fields['variantpathclass'] = '1b'
@handler.process_teststatus(@genotype, path_record)
assert_equal 7, @genotype.attribute_map['teststatus']

path_record = build_raw_record('pseudo_id1' => 'bob')
path_record.raw_fields['teststatus'] = 'non-pathogenic variant detected'
path_record.raw_fields['variantpathclass'] = '1b'
@handler.process_teststatus(@genotype, path_record)
assert_equal 10, @genotype.attribute_map['teststatus']
end

test 'process_variant' do
Expand Down
Loading