-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rewrite of BB is complete * Chromosome aliasing rewrite complete * Removed old MethylTrack and associated files
- Loading branch information
Showing
67 changed files
with
5,600 additions
and
1,690 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/broad/igv/feature/genome/ChromAlias.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.broad.igv.feature.genome; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ChromAlias { | ||
|
||
private String chr; | ||
private Map<String, String> aliases; | ||
|
||
public ChromAlias(String chr) { | ||
this.chr = chr; | ||
this.aliases = new HashMap<>(); | ||
this.aliases.put("chr", chr); | ||
} | ||
|
||
public String getChr() { | ||
return chr; | ||
} | ||
|
||
public void put(String nameSet, String alias) { | ||
aliases.put(nameSet, alias); | ||
} | ||
public String get(String nameSet) { | ||
return aliases.get(nameSet); | ||
} | ||
|
||
public boolean containsKey(String nameSet) { | ||
return aliases.containsKey(nameSet); | ||
} | ||
|
||
public Collection<String> values() { | ||
return aliases.values(); | ||
} | ||
|
||
|
||
|
||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/org/broad/igv/feature/genome/ChromAliasBB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.broad.igv.feature.genome; | ||
|
||
import org.broad.igv.feature.BasicFeature; | ||
import org.broad.igv.ucsc.bb.BBFile; | ||
import java.io.IOException; | ||
|
||
public class ChromAliasBB extends ChromAliasSource { | ||
|
||
|
||
BBFile reader; | ||
|
||
public ChromAliasBB(String path, Genome genome) throws IOException { | ||
this.reader = new BBFile(path, genome); | ||
} | ||
|
||
|
||
/** | ||
* Return the canonical chromosome name for the alias. If none found return the alias | ||
* | ||
* @param alias | ||
* @returns {*} | ||
*/ | ||
public String getChromosomeName(String alias) { | ||
if(aliasCache.containsKey(alias)) { | ||
return aliasCache.get(alias).get("chr"); | ||
} else { | ||
try { | ||
ChromAlias aliasRecord = search(alias); | ||
if(aliasRecord == null) { | ||
aliasRecord.put(alias, null); // Prevents future attempts | ||
} else { | ||
return aliasRecord.get("chr"); | ||
} | ||
} catch (IOException e) { | ||
// TODO -- log | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Return an alternate chromosome name (alias). | ||
* | ||
* @param chr | ||
* @param nameSet -- The name set, e.g. "ucsc" | ||
* @returns {*|undefined} | ||
*/ | ||
public String getChromosomeAlias(String chr, String nameSet) { | ||
ChromAlias aliasRecord = this.aliasCache.get(chr); | ||
return aliasRecord != null && aliasRecord.containsKey(nameSet) ? aliasRecord.get(nameSet) : chr; | ||
} | ||
|
||
/** | ||
* Search for chromosome alias bed record. If found, cache results in the alias -> chr map | ||
* | ||
* @param alias | ||
* @returns {Promise<any>} | ||
*/ | ||
public ChromAlias search(String alias) throws IOException { | ||
if (!this.aliasCache.containsKey(alias)) { | ||
BasicFeature f = this.reader.search(alias); | ||
if (f != null) { | ||
String chr = f.getChr(); | ||
ChromAlias aliasRecord = new ChromAlias(chr); | ||
this.aliasCache.put(chr, aliasRecord); | ||
for (String key : f.getAttributeKeys()){ | ||
final String a = f.getAttribute(key); | ||
aliasRecord.put(key, a); | ||
this.aliasCache.put(a, aliasRecord); // One entry for each alias | ||
} | ||
} | ||
} | ||
return this.aliasCache.get(alias); | ||
} | ||
|
||
} |
156 changes: 156 additions & 0 deletions
156
src/main/java/org/broad/igv/feature/genome/ChromAliasDefaults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package org.broad.igv.feature.genome; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ChromAliasDefaults extends ChromAliasSource { | ||
|
||
public ChromAliasDefaults(String id, List<String> chromosomeNames) { | ||
|
||
this.init(id, chromosomeNames); | ||
} | ||
|
||
private void init(String id, List<String> chromosomeNames) { | ||
|
||
List<ChromAlias> aliasRecords = new ArrayList<>(); | ||
for (String name : chromosomeNames) { | ||
|
||
boolean skipRest = false; | ||
ChromAlias record = new ChromAlias(name); | ||
aliasRecords.add(record); | ||
|
||
if (name.startsWith("gi|")) { | ||
// NCBI | ||
String alias = ChromAliasDefaults.getNCBIName(name); | ||
record.put("ncbi-gi-versioned", alias); | ||
|
||
// Also strip version number out, if present | ||
int dotIndex = alias.lastIndexOf('.'); | ||
if (dotIndex > 0) { | ||
alias = alias.substring(0, dotIndex); | ||
record.put("ncbi-gi", alias); | ||
} | ||
} else { | ||
// Special cases for human and mouse | ||
if (id.startsWith("hg") || id.equals("1kg_ref") || id.equals("b37")) { | ||
switch (name) { | ||
case "chrX": | ||
record.put("ncbi", "23"); | ||
skipRest = true; | ||
break; | ||
case "chrY": | ||
record.put("ncbi", "24"); | ||
skipRest = true; | ||
break; | ||
} | ||
} else if (id.startsWith("GRCh")) { | ||
switch (name) { | ||
case "23": | ||
record.put("ucsc", "chrX"); | ||
skipRest = true; | ||
break; | ||
case "24": | ||
record.put("ucsc", "chrY"); | ||
skipRest = true; | ||
break; | ||
} | ||
} else if (id.startsWith("mm") || id.startsWith("rheMac")) { | ||
switch (name) { | ||
case "chrX": | ||
record.put("ncbi", "21"); | ||
skipRest = true; | ||
break; | ||
case "chrY": | ||
record.put("ncbi", "22"); | ||
skipRest = true; | ||
break; | ||
} | ||
} else if (id.startsWith("GRCm")) { | ||
switch (name) { | ||
case "21": | ||
record.put("ucsc", "chrX"); | ||
skipRest = true; | ||
break; | ||
case "22": | ||
record.put("ucsc", "chrY"); | ||
skipRest = true; | ||
break; | ||
} | ||
} | ||
if (skipRest) continue; | ||
|
||
// | ||
if (name.equals("chrM")) { | ||
record.put("ncbi", "MT"); | ||
} else if (name.equals("MT")) { | ||
record.put("ucsc", "chrM"); | ||
} else if (name.toLowerCase().startsWith("chr")) { | ||
record.put("ncbi", name.substring(3)); | ||
} else if (isSmallPositiveInteger(name)) { | ||
record.put("ucsc", "chr" + name); | ||
} | ||
} | ||
} | ||
|
||
for (ChromAlias rec : aliasRecords) { | ||
for (String a : rec.values()) { | ||
this.aliasCache.put(a, rec); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Return the canonical chromosome name for the alias. If none found return the alias | ||
* | ||
* @param alias | ||
* @returns {*} | ||
*/ | ||
@Override | ||
public String getChromosomeName(String alias) { | ||
return this.aliasCache.containsKey(alias) ? this.aliasCache.get(alias).get("chr") : alias; | ||
} | ||
|
||
/** | ||
* Return an alternate chromosome name (alias). | ||
* | ||
* @param chr | ||
* @param nameSet -- The name set, e.g. "ucsc" | ||
* @returns {*|undefined} | ||
*/ | ||
@Override | ||
public String getChromosomeAlias(String chr, String nameSet) { | ||
ChromAlias aliasRecord = this.aliasCache.get(chr); | ||
return aliasRecord != null && aliasRecord.containsKey(nameSet) ? aliasRecord.get(nameSet) : chr; | ||
} | ||
|
||
@Override | ||
public ChromAlias search(String alias) { | ||
return this.aliasCache.get(alias); | ||
} | ||
|
||
/** | ||
* Extract the user friendly name from an NCBI accession | ||
* example: gi|125745044|ref|NC_002229.3| => NC_002229.3 | ||
*/ | ||
|
||
public static String getNCBIName(String name) { | ||
|
||
String[] tokens = name.split("\\|"); | ||
return tokens[tokens.length - 1]; | ||
} | ||
|
||
|
||
public static boolean isSmallPositiveInteger(String str) { | ||
int length = str.length(); | ||
if (length > 100) return false; | ||
for (int i = 0; i < length; i++) { | ||
char c = str.charAt(i); | ||
if (c < '0' || c > '9') { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.