@@ -6,30 +6,23 @@ const _ = require('lodash');
66const classNames = require ( 'classnames' ) ;
77
88const { fetch } = require ( '../../../util' ) ;
9- const config = require ( '../../../config' ) ;
10- let { DATASOURCES } = require ( '../../../models/entity/summary' ) ;
9+ const { MAX_SIF_NODES , NS_HGNC_SYMBOL , NS_GENECARDS , NS_NCBI_GENE , NS_UNIPROT } = require ( '../../../config' ) ;
1110
1211const ENTITY_OTHER_NAMES_LIMIT = 4 ;
1312const ENTITY_SUMMARY_DISPLAY_LIMIT = 6 ;
1413
15- //Temporary - to be dealt with in #1116 (https://github.com/PathwayCommons/app-ui/issues/1116)
16- const DATASOURCE_NAMES = {
17- [ DATASOURCES . NCBIGENE ] : {
18- displayName : 'NCBI Gene' ,
19- linkUrl : DATASOURCES . NCBIGENE
20- } ,
21- [ DATASOURCES . HGNC ] : {
22- displayName : 'HGNC' ,
23- linkUrl : 'http://identifiers.org/hgnc.symbol/'
24- } ,
25- [ DATASOURCES . UNIPROT ] : {
26- displayName : 'UniProt' ,
27- linkUrl : DATASOURCES . UNIPROT
28- } ,
29- [ DATASOURCES . GENECARDS ] : {
30- displayName : 'GeneCards' ,
31- linkUrl : 'https://www.genecards.org/cgi-bin/carddisp.pl?gene='
32- } ,
14+ const SUPPORTED_COLLECTIONS = new Map ( [
15+ [ NS_GENECARDS , 'GeneCards' ] ,
16+ [ NS_HGNC_SYMBOL , 'HGNC' ] ,
17+ [ NS_NCBI_GENE , 'NCBI Gene' ] ,
18+ [ NS_UNIPROT , 'UniProt' ]
19+ ] ) ;
20+
21+ const getHgncFromXref = xrefLinks => {
22+ let symbol ;
23+ const hgncXrefLink = _ . find ( xrefLinks , link => link . namespace === NS_HGNC_SYMBOL ) ;
24+ if ( hgncXrefLink ) symbol = _ . last ( _ . compact ( hgncXrefLink . uri . split ( '/' ) ) ) ;
25+ return symbol ;
3326} ;
3427
3528class EntitySummaryBox extends React . Component {
@@ -43,12 +36,11 @@ class EntitySummaryBox extends React.Component {
4336 }
4437 render ( ) {
4538 let { summary } = this . props ;
46- let { dataSource, displayName, localID, description, aliasIds, xref } = summary ;
47- // Retrieve the HGNC symbol (http://www.pathwaycommons.org/sifgraph/swagger-ui.html)
48- let hgncSymbol = summary . xref [ DATASOURCES . HGNC ] || localID ; // Prefix is hgnc
49- let sortedLinks = _ . toPairs ( xref ) . concat ( [ [ dataSource , localID ] ] )
50- . sort ( ( p1 , p2 ) => p1 [ 0 ] > p2 [ 0 ] ? 1 : - 1 )
51- . map ( pair => h ( 'a.plain-link' , { href : ( DATASOURCE_NAMES [ pair [ 0 ] ] ) . linkUrl + pair [ 1 ] , target :'_blank' } , ( DATASOURCE_NAMES [ pair [ 0 ] ] ) . displayName ) ) ;
39+ let { displayName, description, aliasIds, xrefLinks } = summary ;
40+ const hgncSymbol = getHgncFromXref ( xrefLinks ) ;
41+
42+ let sortedLinks = xrefLinks . sort ( ( p1 , p2 ) => p1 . namespace > p2 . namespace ? 1 : - 1 )
43+ . map ( link => h ( 'a.plain-link' , { href : link . uri , target :'_blank' } , SUPPORTED_COLLECTIONS . get ( link . namespace ) ) ) ;
5244
5345 let moreInfo = h ( 'div.entity-more-info' , [
5446 h ( 'div.entity-names' , [
@@ -109,9 +101,7 @@ class EntitySummaryBoxList extends React.Component {
109101
110102 componentDidMount ( ) {
111103 let { entitySummaryResults } = this . props ;
112- let hgncSymbols = _ . values ( entitySummaryResults )
113- . map ( summary => summary . xref [ DATASOURCES . HGNC ] || summary . xref [ 'localID' ] ) ; // Prefix is hgnc
114-
104+ let hgncSymbols = entitySummaryResults . map ( summaryResult => getHgncFromXref ( _ . get ( summaryResult , [ 'summary' , 'xrefLinks' ] ) ) ) ;
115105
116106 fetch ( '/api/interactions/image?' + queryString . stringify ( { sources : hgncSymbols } ) ) . then ( r => r . json ( ) ) . then ( res => {
117107 let { img } = res ;
@@ -121,21 +111,15 @@ class EntitySummaryBoxList extends React.Component {
121111
122112 render ( ) {
123113 let { entitySummaryResults } = this . props ;
124- const entitySummaryKeys = _ . keys ( entitySummaryResults ) ;
125-
126- // Retrieve the HGNC symbol (http://www.pathwaycommons.org/sifgraph/swagger-ui.html)
127- let sources = _ . values ( entitySummaryResults )
128- . map ( summary => summary . xref [ DATASOURCES . HGNC ] || summary . xref [ 'localID' ] ) ; // Prefix is hgnc
129-
130- let singleSrcLabel = `View interactions between ${ sources [ 0 ] } and top ${ config . MAX_SIF_NODES } genes` ;
114+ let sources = entitySummaryResults . map ( summaryResult => getHgncFromXref ( _ . get ( summaryResult , [ 'summary' , 'xrefLinks' ] ) ) ) ;
115+ let singleSrcLabel = `View interactions between ${ sources [ 0 ] } and top ${ MAX_SIF_NODES } genes` ;
131116 let multiSrcLabel = `View iteractions between ${ sources . slice ( 0 , sources . length - 1 ) . join ( ', ' ) } and ${ sources . slice ( - 1 ) } ` ;
132-
133117 let interactionsLinkLabel = sources . length === 1 ? singleSrcLabel : multiSrcLabel ;
134118
135- let entitySummaryBoxes = entitySummaryKeys
119+ let entitySummaryBoxes = entitySummaryResults
136120 . slice ( 0 , ENTITY_SUMMARY_DISPLAY_LIMIT )
137- . map ( key => {
138- const summary = _ . get ( entitySummaryResults , key ) ;
121+ . map ( summaryResult => {
122+ const summary = _ . get ( summaryResult , 'summary' ) ;
139123 let props = { summary } ;
140124 return h ( EntitySummaryBox , props ) ;
141125 } ) ;
0 commit comments