@@ -47,6 +47,26 @@ const geneLinkedVariantTypes = ['mut', 'cnv', 'exp'];
4747const getRapidReportVariants = async ( tableName , variantType , reportId , rapidTable ) => {
4848 let allKbMatches ;
4949
50+ const kbmatchJoin = {
51+ model : db . models . kbMatches ,
52+ attributes : { exclude : KBMATCHEXCLUDE } ,
53+ include : [
54+ {
55+ model : db . models . kbMatchedStatements ,
56+ as : 'kbMatchedStatements' ,
57+ attributes : {
58+ exclude : STATEMENTEXCLUDE ,
59+ } ,
60+ through : { attributes : [ 'flags' ] } ,
61+ } ,
62+ ] ,
63+ } ;
64+
65+ // get variants that don't have kbmatches in the unknownSignificance table (if gene check passes)
66+ if ( rapidTable === 'unknownSignificance' ) {
67+ kbmatchJoin . required = false ;
68+ }
69+
5070 const query = {
5171 order : [ [ 'id' , 'ASC' ] ] ,
5272 attributes : {
@@ -56,20 +76,7 @@ const getRapidReportVariants = async (tableName, variantType, reportId, rapidTab
5676 reportId,
5777 } ,
5878 include : [
59- {
60- model : db . models . kbMatches ,
61- attributes : { exclude : KBMATCHEXCLUDE } ,
62- include : [
63- {
64- model : db . models . kbMatchedStatements ,
65- as : 'kbMatchedStatements' ,
66- attributes : {
67- exclude : STATEMENTEXCLUDE ,
68- } ,
69- through : { attributes : [ 'flags' ] } ,
70- } ,
71- ] ,
72- } ,
79+ kbmatchJoin ,
7380 {
7481 model : db . models . observedVariantAnnotations ,
7582 attributes : { exclude : OBSVARANNOTEXCLUDE } ,
@@ -107,10 +114,26 @@ const getRapidReportVariants = async (tableName, variantType, reportId, rapidTab
107114 const therapeuticResultsFromAnnotation = [ ] ;
108115 const cancerRelevanceResultsFromAnnotation = [ ] ;
109116 const unknownSignificanceFromAnnotation = [ ] ;
117+ const unknownSignificanceFromGeneProperty = [ ] ;
110118 const doNotReport = [ ] ;
111119
112120 const tumourSuppressorLofVariants = { } ;
113121
122+ // separate out variants that qualify based on gene properties alone, if filtering for table 3
123+ if ( rapidTable === 'unknownSignificance' ) {
124+ for ( const variant of allKbMatches ) {
125+ if ( variant . gene . cancerGeneListMatch
126+ || variant . gene . oncogene
127+ || variant . gene . tumourSuppressor ) {
128+ unknownSignificanceFromGeneProperty . push ( variant ) ;
129+ }
130+ }
131+ }
132+ // remove the kbmatch-less variants from further sorting
133+ allKbMatches = allKbMatches . filter ( ( variant ) => {
134+ return ( variant . kbMatches . length > 0 ) ;
135+ } ) ;
136+
114137 for ( const variant of allKbMatches ) {
115138 // check whether the variant has LOF effect on tumour suppressor gene
116139 const tumourSuppressorLof = variant . kbMatches . some ( ( kbmatch ) => {
@@ -327,6 +350,11 @@ const getRapidReportVariants = async (tableName, variantType, reportId, rapidTab
327350 unknownSignificanceResults = unknownSignificanceResults . filter ( ( variant ) => {
328351 return variant . kbMatches . length > 0 ;
329352 } ) ;
353+
354+ // add variants back to unknownSig list, that are tagged for this table based on gene properties alone
355+ // so that they can be filtered out of results if they are in TA or CR
356+ unknownSignificanceResults . push ( ...unknownSignificanceFromGeneProperty ) ;
357+
330358 // remove variants already included in a different section
331359 for ( const row of unknownSignificanceResults ) {
332360 if ( ! ( therapeuticAssociationResults . find (
@@ -341,6 +369,7 @@ const getRapidReportVariants = async (tableName, variantType, reportId, rapidTab
341369 // add variants that are tagged for this table regardless of whatever other
342370 // reason there may be to exclude them
343371 unknownSignificanceResultsFiltered . push ( ...unknownSignificanceFromAnnotation ) ;
372+
344373 return unknownSignificanceResultsFiltered ;
345374} ;
346375
0 commit comments