Skip to content

Commit

Permalink
Some feature search refinements
Browse files Browse the repository at this point in the history
* Try webservice last, after searching tracks
* Don't try webservice for "full path" genome IDs, nothing will be found
  • Loading branch information
jrobinso committed Nov 29, 2023
1 parent 551f21c commit 518045e
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/main/java/org/broad/igv/ui/action/SearchCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,11 @@ Set<ResultType> checkTokenType(String token) {
private SearchResult parseToken(String token) {

// Check featureDB first -- this is cheap
NamedFeature feat = searchFeatureDBs(token);
NamedFeature feat = FeatureDB.getFeature(token.toUpperCase().trim());
if (feat != null) {
return new SearchResult(feat);
}


//Check if a full or partial locus string
SearchResult result = calcChromoLocus(token);
if (result != null) {
Expand All @@ -331,6 +330,13 @@ private SearchResult parseToken(String token) {
}
}

// Try the webservice
feat = searchWebservice(token);
if (feat != null) {
return new SearchResult(feat);
}


//2 possible mutation notations, either amino acid (A123B) or nucleotide (123G>C)
boolean mutAA = token.matches(featureMutAA);
boolean mutNT = token.matches(featureMutNT);
Expand Down Expand Up @@ -378,28 +384,23 @@ private SearchResult parseToken(String token) {
return null;
}

private NamedFeature searchFeatureDBs(String str) {
NamedFeature feat = FeatureDB.getFeature(str.toUpperCase().trim());
if (feat != null) {
return feat;
} else {
try {
String tmp = "https://igv.org/genomes/locus.php?genome=$GENOME$&name=$FEATURE$";
String genomeID = GenomeManager.getInstance().getGenomeId();
if (genomeID != null) {
URL url = new URL(tmp.replace("$GENOME$", genomeID).replace("$FEATURE$", str));
String r = HttpUtils.getInstance().getContentsAsString(url);
String[] t = Globals.whitespacePattern.split(r);
if (t.length > 2) {
Locus l = Locus.fromString(t[1]);
String chr = genome == null ? l.getChr() : genome.getCanonicalChrName(l.getChr());
feat = new BasicFeature(chr, l.getStart(), l.getEnd());
return feat;
}
private NamedFeature searchWebservice(String str) {
try {
String tmp = "https://igv.org/genomes/locus.php?genome=$GENOME$&name=$FEATURE$";
String genomeID = GenomeManager.getInstance().getGenomeId();
if (genomeID != null && genomeID.indexOf("/") < 0 && genomeID.indexOf("\\") < 0) { // Filter out file paths
URL url = new URL(tmp.replace("$GENOME$", genomeID).replace("$FEATURE$", str));
String r = HttpUtils.getInstance().getContentsAsString(url);
String[] t = Globals.whitespacePattern.split(r);
if (t.length > 2) {
Locus l = Locus.fromString(t[1]);
String chr = genome == null ? l.getChr() : genome.getCanonicalChrName(l.getChr());
return new BasicFeature(chr, l.getStart(), l.getEnd());
}
} catch (Exception e) {
log.error("Search webservice error", e);
}
} catch (Exception e) {

log.error("Search webservice error", e);
}
return null;
}
Expand Down

0 comments on commit 518045e

Please sign in to comment.