Skip to content

Commit

Permalink
Merge 1984e6d into 546cd0f
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Oct 29, 2019
2 parents 546cd0f + 1984e6d commit 19b1330
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 34 deletions.
80 changes: 80 additions & 0 deletions examples/vanilla/homology-grape-tomato.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title>Homology, interspecies | Ideogram</title>
<style>
body {font: 14px Arial; line-height: 19.6px; padding: 0 15px;}
a, a:visited {text-decoration: none;}
a:hover {text-decoration: underline;}
a, a:hover, a:visited, a:active {color: #0366d6;}
</style>
<script type="text/javascript" src="../../dist/js/ideogram.min.js"></script>
<link rel="icon" type="image/x-icon" href="img/ideogram_favicon.ico">
</head>
<body>
<h1>Homology, grape and tomato | Ideogram</h1>
<a href="../">Overview</a> |
<a href="homology-advanced">Previous</a> |
<a href="annotations-basic">Next</a> |
<a href="https://github.com/eweitz/ideogram/blob/gh-pages/homology-interspecies.html" target="_blank">Source</a>

<p>
This demonstrates support for drawing features between two genomes that
lack centromere data.
</p>
<p>
See also: <a href='homology-human-chimpanzee'>Homology, human and chimpanzee</a>
</p>

<script type="text/javascript">

function onIdeogramLoad() {

var chrs, chr1, chr4, syntheticRegions, humanTaxid, mouseTaxid;

humanTaxid = ideogram.getTaxid('vitis-vinifera');
mouseTaxid = ideogram.getTaxid('solanum-lycopersicum');

var chrs = ideogram.chromosomes,
chr1 = chrs[humanTaxid]['1'],
chr4 = chrs[mouseTaxid]['1'],
syntenicRegions = [];

range1 = {
chr: chr1,
start: 11106530,
stop: 11262550,
orientation: 'reverse'
};

range2 = {
chr: chr4,
start: 94844850,
stop: 94855760
};

syntenicRegions.push({'r1': range1, 'r2': range2});

ideogram.drawSynteny(syntenicRegions);

}

var config = {
organism: ['vitis-vinifera', 'solanum-lycopersicum'],
chromosomes: {
'vitis-vinifera': ['1'],
'solanum-lycopersicum': ['1']
},
chrHeight: 400,
chrMargin: 50,
fullChromosomeLabels: true,
perspective: 'comparative',
rotatable: false,
onLoad: onIdeogramLoad
};

var ideogram = new Ideogram(config);

</script>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/vanilla/orthologs.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ <h1>Orthologs | Ideogram</h1>
<option>Chimpanzee (Pan troglodytes)</option>
<option>Mouse (Mus musculus)</option>
<option>Rat (Rattus norvegicus)</option>
<option>Chicken (Gallus gallus)</option>
<option>Zebrafish (Danio rerio)</option>
<option>Fly (Drosophila melanogaster)</option>
<option>Worm (Caenorhabditis elegans)</option>
<option>Thale cress (Arabidopsis thaliana)</option>
Expand All @@ -52,6 +54,8 @@ <h1>Orthologs | Ideogram</h1>
<option>Chimpanzee (Pan troglodytes)</option>
<option selected>Mouse (Mus musculus)</option>
<option>Rat (Rattus norvegicus)</option>
<option>Chicken (Gallus gallus)</option>
<option>Zebrafish (Danio rerio)</option>
<option>Fly (Drosophila melanogaster)</option>
<option>Worm (Caenorhabditis elegans)</option>
<option>Thale cress (Arabidopsis thaliana)</option>
Expand Down
7 changes: 0 additions & 7 deletions src/js/ideogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ export default class Ideogram {
return d3;
}

/**
* e.g. "Homo sapiens" -> "homo-sapiens"
*/
static slugify(value) {
return value.toLowerCase().replace(' ', '-');
}

/**
* Sorts two chromosome objects by type and name
* - Nuclear chromosomes come before non-nuclear chromosomes.
Expand Down
4 changes: 2 additions & 2 deletions src/js/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoveriew Methods for initialization
*/

import {d3} from '../lib';
import {d3, slug} from '../lib';
import {configure} from './configure';
import {finishInit} from './finish-init';
import {writeContainer} from './write-container';
Expand Down Expand Up @@ -106,7 +106,7 @@ function onLoad() {

function getBandFileName(taxid, accession, ideo) {
var organism = ideo.organisms[taxid];
var bandFileName = [Ideogram.slugify(organism.scientificName)];
var bandFileName = [slug(organism.scientificName)];
var assemblies = organism.assemblies;
var resolution = ideo.config.resolution;

Expand Down
16 changes: 12 additions & 4 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ function getTaxid(name) {
ideo = this,
organisms = ideo.organisms;

name = name.toLowerCase();
name = slug(name);

for (taxid in organisms) {
organism = organisms[taxid];
commonName = organism.commonName.toLowerCase();
scientificName = organism.scientificName.toLowerCase();
commonName = slug(organism.commonName);
scientificName = slug(organism.scientificName);
if (commonName === name || scientificName === name) {
return taxid;
}
Expand Down Expand Up @@ -172,7 +172,15 @@ function getScientificName(taxid) {
return null;
}

/**
* e.g. "Homo sapiens" -> "homo-sapiens"
*/
function slug(value) {
return value.toLowerCase().replace(' ', '-');
}

export {
assemblyIsAccession, hasNonGenBankAssembly, hasGenBankAssembly, getDataDir,
round, onDidRotate, getSvg, fetch, d3, getTaxid, getCommonName, getScientificName
round, onDidRotate, getSvg, fetch, d3, getTaxid, getCommonName,
getScientificName, slug
};
42 changes: 26 additions & 16 deletions src/js/services/organisms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {d3} from '../lib';
import {d3, slug} from '../lib';

/**
* Returns NCBI Taxonomy identifier (taxid) for organism name
Expand All @@ -10,7 +10,7 @@ function getTaxidFromEutils(orgName, ideo) {

return d3.json(taxonomySearch).then(function(data) {
taxid = data.esearchresult.idlist[0];
return taxid;
return [orgName, taxid];
});
}

Expand All @@ -37,7 +37,7 @@ function getOrganismFromEutils(taxid, callback) {

function setTaxidData(taxid, ideo) {

var dataDir, organism, urlOrg, taxids;
var dataDir, urlOrg, taxids;

if (ideo.assemblyIsAccession()) {
return new Promise(function(resolve) {
Expand All @@ -47,8 +47,7 @@ function setTaxidData(taxid, ideo) {
}

dataDir = ideo.config.dataDir;
organism = ideo.organisms[taxid].scientificName.toLowerCase();
urlOrg = organism.replace(' ', '-');
urlOrg = slug(ideo.organisms[taxid].scientificName);

taxids = [taxid];

Expand Down Expand Up @@ -132,7 +131,7 @@ function setAssemblyAndChromosomes(taxid, resolve, ideo) {
originalChrs = config.chromosomes[taxid];
} else {
// Encountered when neither organism has centromere data
orgName = ideo.getScientificName(taxid).toLowerCase();
orgName = slug(ideo.getScientificName(taxid));
ideo.config.chromosomes[taxid] =
config.chromosomes[orgName].slice();
originalChrs = ideo.config.chromosomes[taxid];
Expand Down Expand Up @@ -162,9 +161,9 @@ function isOrganismSupported(org, ideo) {
for (taxid in ideo.organisms) {
ideoOrg = ideo.organisms[taxid];
if (
taxid === org ||
ideoOrg.commonName.toLowerCase() === org.toLowerCase() ||
ideoOrg.scientificName.toLowerCase() === org.toLowerCase()
taxid === slug(org) ||
slug(ideoOrg.commonName) === slug(org) ||
slug(ideoOrg.scientificName) === slug(org)
) {
return true;
}
Expand All @@ -186,11 +185,17 @@ function populateNonNativeOrg(orgs, ideo) {
org = orgs[i];
if (isOrganismSupported(org, ideo) === false) {
promise = getTaxidFromEutils(org, ideo)
.then(function(taxid) {
.then(function(orgNameAndTaxid) {

var taxid = orgNameAndTaxid[1],
orgName = orgNameAndTaxid[0],
name, scientificName;

name = orgName.replace('-', ' ');
scientificName = name[0].toUpperCase() + name.slice(1);

augmentedOrganismMetadata[taxid] = {
scientificName: org,
scientificNameAbbr: '',
scientificName: scientificName,
commonName: '',
assemblies: {default: ''}
};
Expand All @@ -213,7 +218,7 @@ function populateNonNativeOrg(orgs, ideo) {
}

function prepareTmpChrsAndTaxids(ideo) {
var orgs, taxids, tmpChrs, org, taxid,
var orgs, taxids, tmpChrs, org, taxid, chrsOrgSlugs,
config = ideo.config;

taxids = [];
Expand All @@ -228,14 +233,19 @@ function prepareTmpChrsAndTaxids(ideo) {
taxids.push(taxid);
if (config.multiorganism) {
if (typeof config.chromosomes !== 'undefined') {
chrsOrgSlugs = Object.keys(config.chromosomes).map(org => slug(org));
// Adjusts 'chromosomes' configuration parameter to make object
// keys use taxid instead of common organism name
if (orgFields.scientificName.toLowerCase() in config.chromosomes) {
if (chrsOrgSlugs.includes(slug(orgFields.scientificName))) {
org = orgFields.scientificName;
} else if (orgFields.commonName.toLowerCase() in config.chromosomes) {
} else if (chrsOrgSlugs.includes(slug(orgFields.commonName))) {
org = orgFields.commonName;
}
tmpChrs[taxid] = config.chromosomes[org.toLowerCase()];
if (slug(org) in config.chromosomes) {
tmpChrs[taxid] = config.chromosomes[slug(org)];
} else {
tmpChrs[taxid] = config.chromosomes[org.toLowerCase()];
}
} else {
tmpChrs = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ function parseChromosomes(results, taxid, ideo) {
chromosomes.forEach(chr => {
if (chr.length > maxLength.bp) maxLength.bp = chr.length;
});
if (maxLength.bp > ideo.maxLength.bp) ideo.maxLength.bp = maxLength.bp;
ideo.maxLength[taxid] = maxLength;

ideo.coordinateSystem = 'bp';

return chromosomes;
Expand Down
11 changes: 7 additions & 4 deletions src/js/views/chromosome-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function getCentromerePosition(hasBands, bands) {
* bands, centromere position, etc.
*/
function getChromosomeModel(bands, chrName, taxid, chrIndex) {
var hasBands,
var hasBands, org, abbreviatedName, splitName,
chr = {},
ideo = this;

Expand All @@ -152,9 +152,12 @@ function getChromosomeModel(bands, chrName, taxid, chrIndex) {
chr.id = 'chr' + chr.name + '-' + taxid;

if (ideo.config.fullChromosomeLabels === true) {
var name = this.organisms[taxid].scientificName.split(' ');
var scientificNameAbbr = name[0][0].toUpperCase() + '. ' + name[1];
chr.name = scientificNameAbbr + ' chr' + chr.name;
org = this.organisms[taxid];
console.log(org.scientificName);
splitName = org.scientificName.split(' ');
abbreviatedName = splitName[0][0] + '. ' + splitName[1];

chr.name = abbreviatedName + ' chr' + chr.name;
}

chr.bands = bands;
Expand Down

0 comments on commit 19b1330

Please sign in to comment.