Skip to content
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
8 changes: 4 additions & 4 deletions src/client/components/element-info/entity-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import assocDisp from './entity-assoc-display';
import CancelablePromise from 'p-cancelable';
import { isComplex, isGGP, ELEMENT_TYPE } from '../../../model/element/element-type';
import RelatedPapers from '../related-papers';
import Organism from '../../../model/organism';

import {
focusDomElement, makeClassList, initCache, SingleValueCache,
Expand Down Expand Up @@ -383,11 +384,10 @@ class EntityInfo extends DataComponent {
nameChildren.push( matchName() );
}

if( complete && m.name.toLowerCase() !== s.name.toLowerCase() ){
if( m.organism != null ){
nameChildren.push(
h('br'),
h('span', '('),
matchName(),
h('span', ' ('),
Organism.fromId(m.organism).name(),
h('span', ')')
);
}
Expand Down
28 changes: 28 additions & 0 deletions src/model/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Cytoscape from 'cytoscape';
import { TWITTER_ACCOUNT_NAME } from '../../config';
import { getPubmedCitation } from '../../util/pubmed';
import { isServer } from '../../util/';
import Organism from '../organism';

const DEFAULTS = Object.freeze({
// data
Expand Down Expand Up @@ -323,6 +324,33 @@ class Document {
}
}

commonOrganism(){
const orgs = this.organisms();
const counts = this.organismCounts();
const getCount = org => counts.get(org) || 0;
const sortedOrgs = _.sortBy(orgs, o => -getCount(o));

if( sortedOrgs.length === 0 ){ return null; }

return Organism.fromId(sortedOrgs[0]);
}

irregularOrganismEntities(){
const comOrg = this.commonOrganism();

const isIrreg = ent => {
const entOrg = ent.organism();

if( entOrg == null ){ return false; } // e.g. chemical

return !entOrg.same(comOrg);
};

if( comOrg == null ){ return []; } // no common org => no irreg ents

return this.entities().filter(isIrreg);
}

add( el ){
let add = el => this.elementSet.add( el );

Expand Down
9 changes: 9 additions & 0 deletions src/model/element/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Element from './element';
import _ from 'lodash';
import { tryPromise } from '../../util';
import { ENTITY_TYPE, getNCBIEntityType } from './entity-type';
import Organism from '../organism';

const TYPE = 'entity';

Expand Down Expand Up @@ -155,6 +156,14 @@ class Entity extends Element {
return update;
}

organism(){
const assoc = this.association();

if( !assoc ){ return null; } // no org

return Organism.fromId(assoc.organism);
}

json(){
return _.assign( {}, super.json(), _.pick( this.syncher.get(), _.keys(DEFAULTS) ) );
}
Expand Down
4 changes: 4 additions & 0 deletions src/model/organism.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class Organism {
};
}

same(other){
return this.id() === other.id();
}

static fromName( name ){
return organisms.find( org => nameMatches( org.name(), name ) ) || Organism.OTHER;
}
Expand Down