Skip to content

Commit

Permalink
Restore GenBank accession support, restore some tests, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Aug 29, 2019
1 parent 083547f commit a5dee70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 50 deletions.
54 changes: 22 additions & 32 deletions src/js/services/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {d3, hasGenBankAssembly} from '../lib';
import {d3} from '../lib';
import {
esearch, esummary, elink, getAssemblySearchUrl
} from './eutils-config.js';
Expand All @@ -11,41 +11,31 @@ function getNuccoreLink(asmUid, ideo) {

// Get a list of IDs for the chromosomes in this genome.
//
// If assembly is GenBank-only or if a GenBank assembly was explicitly
// requested (GCA_), then query chromosomes sequences in Nucleotide DB via
// INSDC link. (GenBank is the American INSDC repository.)
// Otherwise, query RefSeq chromosomes in Nucleotide DB.
if (hasGenBankAssembly(ideo)) {
// TODO: account for GenBank-only
qs = '&db=nuccore&linkname=assembly_nuccore_insdc&from_uid=' + asmUid;
return ideo.elink + qs;
} else {
qs = ('&db=nuccore&dbfrom=assembly&linkname=assembly_nuccore_refseq&' +
'cmd=neighbor_history&from_uid=' + asmUid);
return d3.json(ideo.elink + qs)
.then(function(data) {
var webenv = data.linksets[0].webenv;
qs =
'&db=nuccore' +
'&term=%231+AND+%28' +
'sequence_from_chromosome[Properties]+OR+' +
'sequence_from_plastid[Properties]+OR+' +
'sequence_from_mitochondrion[Properties]%29' +
'&WebEnv=' + webenv + '&usehistory=y&retmax=1000';
return ideo.esearch + qs;
});
}
// Query chromosomes sequences in Nucleotide DB (nuccore) via
// Assembly DB E-Utils link.
qs = ('&db=nuccore&dbfrom=assembly&linkname=assembly_nuccore&' +
'cmd=neighbor_history&from_uid=' + asmUid);

return d3.json(ideo.elink + qs)
.then(function(data) {
var webenv = data.linksets[0].webenv;
qs =
'&db=nuccore' +
'&term=%231+AND+%28' +
'sequence_from_chromosome[Properties]+OR+' +
'sequence_from_plastid[Properties]+OR+' +
'sequence_from_mitochondrion[Properties]%29' +
'&WebEnv=' + webenv + '&usehistory=y&retmax=1000';
return ideo.esearch + qs;
});
}

function fetchNucleotideSummary(data, ideo) {
var links, ntSummary;
var ids, ntSummary;

if ('esearchresult' in data) {
links = data.esearchresult.idlist.join(',');
} else {
links = data.linksets[0].linksetdbs[0].links.join(',');
}
ntSummary = ideo.esummary + '&db=nucleotide&id=' + links;
ids = data.esearchresult.idlist.join(',');

ntSummary = ideo.esummary + '&db=nucleotide&id=' + ids;

return d3.json(ntSummary);
}
Expand Down
36 changes: 18 additions & 18 deletions test/web-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-new */
/* eslint-disable spaced-comment */
/* eslint-disable no-use-before-define */
/* eslint-disable no-unused-vars */
Expand Down Expand Up @@ -1570,23 +1571,23 @@ describe('Ideogram', function() {
// These tests fail due to an upstream breaking change in NCBI E-Utils.
// Specifically, the Entrez GenColl database was retired without notice.
//
// it('should support GenBank accessions in "assembly" parameter', function(done) {
// // Tests use case for non-default assemblies.
// // GCA_000002125.2 is commonly called HuRef
// // https://www.ncbi.nlm.nih.gov/assembly/GCA_000002125.2
it('should support GenBank accessions in "assembly" parameter', function(done) {
// Tests use case for non-default assemblies.
// GCA_000002125.2 is commonly called HuRef
// https://www.ncbi.nlm.nih.gov/assembly/GCA_000002125.2

// function callback() {
// var chr1Length = ideogram.chromosomes['9606']['1'].length;
// // For reference, see length section of LOCUS field in GenBank record at
// // https://www.ncbi.nlm.nih.gov/nuccore/CM001609.2
// assert.equal(chr1Length, 219475005);
// done();
// }
function callback() {
var chr1Length = ideogram.chromosomes['9606']['1'].length;
// For reference, see length section of LOCUS field in GenBank record at
// https://www.ncbi.nlm.nih.gov/nuccore/CM001609.2
assert.equal(chr1Length, 219475005);
done();
}

// config.assembly = 'GCA_000002125.2';
// config.onLoad = callback;
// var ideogram = new Ideogram(config);
// });
config.assembly = 'GCA_000002125.2';
config.onLoad = callback;
var ideogram = new Ideogram(config);
});

// it('should recover chromosomes when given scaffolds', function(done) {
// // Tests use case from ../examples/vanilla/human.html
Expand Down Expand Up @@ -1627,10 +1628,9 @@ describe('Ideogram', function() {
// var numHumanChromosomes = 24; // (22,X,Y)
// var numChromosomes = ideo.chromosomesArray.length;

// if(numTimesOnLoadHasBeenCalled === 1) {
// if (numTimesOnLoadHasBeenCalled === 1) {
// assert.equal(numChromosomes, numChimpChromosomes);
// }
// else if(numTimesOnLoadHasBeenCalled === 2) {
// } else if (numTimesOnLoadHasBeenCalled === 2) {
// assert.equal(numChromosomes, numHumanChromosomes);
// done();
// }
Expand Down

0 comments on commit a5dee70

Please sign in to comment.