Skip to content

Commit

Permalink
Support htsget scheme. See samtools/hts-specs#581
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Jul 21, 2021
1 parent 69ab1d9 commit e22aa85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dev/htsget.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ <h1>htsget server example</h1>
// name: 'giab.NA12878',
// sourceType: 'htsget',
// format: "VCF",
url: 'https://htsget.ga4gh.org/variants/giab.NA12878'
url: 'htsget://htsget.ga4gh.org/variants/giab.NA12878'
},
{
// type: 'alignment',
// name: 'giab.NA12878.NIST7086.1',
// sourceType: 'htsget',
// format: 'bam',
url: 'https://htsget.ga4gh.org/reads/giab.NA12878.NIST7086.1'
url: 'htsget://htsget.ga4gh.org/reads/giab.NA12878.NIST7086.1'
}
]
};
Expand Down
23 changes: 14 additions & 9 deletions js/htsget/htsgetReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class HtsgetReader {

static async inferFormat(config) {
try {
const headerURL = `${config.url}${config.url.includes("?") ? "&" : "?"}class=header`;
const url = getUrl(config);
const headerURL = `${url}${url.includes("?") ? "&" : "?"}class=header`;
const ticket = await igvxhr.loadJson(headerURL, buildOptions(config))
if (ticket.htsget) {
const format = ticket.htsget.format;
Expand All @@ -97,17 +98,21 @@ class HtsgetReader {
}

/**
* Extract the full url from the config. Striving for backward compatibility.
* Extract the full url from the config. Striving for backward compatibility, "endpoint" and "id" are deprecated.
*
* @param config
*/
function getUrl(config) {
if(config.url && config.endpoint && config.id) {
return config.url + config.endpoint + config.id;
} else if(config.endpoint && config.id) {
return config.endpoint + config.id;
} else if(config.url) {
return config.url;
function getUrl(config) {
if (config.url && config.endpoint && config.id) {
return config.url + config.endpoint + config.id; // Deprecated
} else if (config.endpoint && config.id) {
return config.endpoint + config.id; // Deprecated
} else if (config.url) {
if (config.url.startsWith("htsget://")) {
return config.url.replace("htsget://", "https://"); // htsget -> http not supported
} else {
return config.url;
}
} else {
throw Error("Must specify either 'url', or 'endpoint' and 'id");
}
Expand Down

0 comments on commit e22aa85

Please sign in to comment.