@@ -41,9 +41,9 @@ function getIsPartialPathwayMatch(query, allGenes) {
4141}
4242
4343/** Parse gene name from heterogeneous array */
44- function getQueriesFromSearchOptions ( newQueryArray , speciesList ) {
44+ function getQueriesFromSearchOptions ( newQueryArray , speciesList , selectedAnnotation ) {
4545 let newQueries
46- if ( newQueryArray [ 0 ] ?. isGene === true || ! getIsEligibleForPathwayExplore ( speciesList ) ) {
46+ if ( newQueryArray [ 0 ] ?. isGene === true || ! getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation ) ) {
4747 // Query is a gene
4848 newQueries = newQueryArray . map ( g => g . value )
4949 } else if ( newQueryArray . length === 0 ) {
@@ -64,19 +64,20 @@ function getQueriesFromSearchOptions(newQueryArray, speciesList) {
6464}
6565
6666/** Indicate whether pathway view should be available for this study */
67- function getIsEligibleForPathwayExplore ( speciesList ) {
67+ export function getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation ) {
6868 const isEligibleForPathwayExplore = (
6969 speciesList . length === 1 && speciesList [ 0 ] === 'Homo sapiens' &&
70+ selectedAnnotation . type === 'group' &&
7071 getFeatureFlagsWithDefaults ( ) ?. show_pathway_expression
7172 )
7273 return isEligibleForPathwayExplore
7374}
7475
7576/** Collapse search options to query array */
76- function getQueryArrayFromSearchOptions ( searchOptions , speciesList ) {
77+ function getQueryArrayFromSearchOptions ( searchOptions , speciesList , selectedAnnotation ) {
7778 let queryArray = [ ]
7879
79- if ( ! getIsEligibleForPathwayExplore ( speciesList ) ) {
80+ if ( ! getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation ) ) {
8081 return searchOptions
8182 }
8283
@@ -98,17 +99,19 @@ function getQueryArrayFromSearchOptions(searchOptions, speciesList) {
9899* @param allGenes String array of valid genes in the study
99100* @param speciesList String array of species scientific names
100101*/
101- export default function StudyGeneField ( { queries, queryFn, allGenes, speciesList, isLoading= false } ) {
102+ export default function StudyGeneField ( {
103+ queries, queryFn, allGenes, speciesList, selectedAnnotation, isLoading= false
104+ } ) {
102105 const [ inputText , setInputText ] = useState ( '' )
103106
104- const rawSuggestions = getAutocompleteSuggestions ( inputText , allGenes )
105- const searchOptions = getSearchOptions ( rawSuggestions , speciesList )
106-
107+ const includePathways = getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation )
108+ const rawSuggestions = getAutocompleteSuggestions ( inputText , allGenes , includePathways )
109+ const searchOptions = getSearchOptions ( rawSuggestions , speciesList , selectedAnnotation )
107110
108111 let enteredQueryArray = [ ]
109112 if ( inputText . length === 0 && queries && queries . length > 0 ) {
110- const queriesSearchOptions = getSearchOptions ( queries , speciesList )
111- enteredQueryArray = getQueryArrayFromSearchOptions ( queriesSearchOptions , speciesList )
113+ const queriesSearchOptions = getSearchOptions ( queries , speciesList , selectedAnnotation )
114+ enteredQueryArray = getQueryArrayFromSearchOptions ( queriesSearchOptions , speciesList , selectedAnnotation )
112115 } else {
113116 enteredQueryArray = searchOptions
114117 }
@@ -129,7 +132,7 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
129132
130133 const newNotPresentQueries = new Set ( [ ] )
131134 if ( newQueryArray ) {
132- if ( ! getIsEligibleForPathwayExplore ( speciesList ) ) {
135+ if ( ! getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation ) ) {
133136 newQueryArray . map ( g => g . value ) . forEach ( query => {
134137 // if an entered gene is not in the valid gene options for the study
135138 const isInvalidQuery = getIsInvalidQuery ( query , allGenes )
@@ -138,7 +141,7 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
138141 }
139142 } )
140143 } else {
141- const newQueries = getQueriesFromSearchOptions ( newQueryArray , speciesList )
144+ const newQueries = getQueriesFromSearchOptions ( newQueryArray , speciesList , selectedAnnotation )
142145 newQueries . forEach ( query => {
143146 // if an entered gene is not in the valid gene options for the study
144147 const isInvalidQuery = getIsInvalidQuery ( query , allGenes )
@@ -153,7 +156,7 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
153156 if ( newNotPresentQueries . size > 0 ) {
154157 setShowNotPresentGeneChoice ( true )
155158 } else if ( newQueryArray && newQueryArray . length ) {
156- const newQueries = getQueriesFromSearchOptions ( newQueryArray , speciesList )
159+ const newQueries = getQueriesFromSearchOptions ( newQueryArray , speciesList , selectedAnnotation )
157160 const queries = newQueries
158161 if ( queries . length > window . MAX_GENE_SEARCH ) {
159162 log ( 'search-too-many-genes' , { numGenes : queries . length } )
@@ -178,7 +181,7 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
178181 return queryArray
179182 }
180183 }
181- const searchOptions = getSearchOptions ( inputTextValues , speciesList )
184+ const searchOptions = getSearchOptions ( inputTextValues , speciesList , selectedAnnotation )
182185 const queryOptions = searchOptions [ 0 ] . options
183186 const newQueryArray = queryArray . concat ( queryOptions )
184187 setInputText ( '' )
@@ -226,8 +229,8 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
226229 useEffect ( ( ) => {
227230 if ( queries . join ( ',' ) !== queryArray . map ( opt => opt . value ) . join ( ',' ) ) {
228231 // the genes have been updated elsewhere -- resync
229- const queriesSearchOptions = getSearchOptions ( queries , speciesList )
230- const newQueryArray = getQueryArrayFromSearchOptions ( queriesSearchOptions , speciesList )
232+ const queriesSearchOptions = getSearchOptions ( queries , speciesList , selectedAnnotation )
233+ const newQueryArray = getQueryArrayFromSearchOptions ( queriesSearchOptions , speciesList , selectedAnnotation )
231234 setQueryArray ( newQueryArray )
232235 setInputText ( '' )
233236 setNotPresentQueries ( new Set ( [ ] ) )
@@ -354,7 +357,7 @@ export default function StudyGeneField({ queries, queryFn, allGenes, speciesList
354357/** Last filtering applied before showing selectable autocomplete options */
355358function finalFilterOptions ( option , rawInput ) {
356359 const input = rawInput . toLowerCase ( )
357- const label = option . label . toLowerCase ( )
360+ const label = 'label' in option ? option . label . toLowerCase ( ) : option . toLowerCase ( )
358361 const isPathway = option . data . isGene === false
359362 return isPathway || label . includes ( input ) // partial match
360363}
@@ -376,8 +379,8 @@ function filterSearchOptions(rawGeneOptions, rawPathwayOptions) {
376379}
377380
378381/** takes an array of gene name strings, and returns options suitable for react-select */
379- function getSearchOptions ( rawSuggestions , speciesList ) {
380- if ( ! getIsEligibleForPathwayExplore ( speciesList ) ) {
382+ function getSearchOptions ( rawSuggestions , speciesList , selectedAnnotation ) {
383+ if ( ! getIsEligibleForPathwayExplore ( speciesList , selectedAnnotation ) ) {
381384 return rawSuggestions . map ( rawSuggestion => {
382385 const geneName = rawSuggestion
383386 return { label : geneName , value : geneName , isGene : true }
0 commit comments