Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case-insensitive search to chrom aliasing code #1621

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/main/java/org/broad/igv/feature/genome/ChromAliasBB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.broad.igv.feature.BasicFeature;
import org.broad.igv.ucsc.bb.BBFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ChromAliasBB extends ChromAliasSource {

Expand All @@ -16,30 +14,6 @@ public ChromAliasBB(String path, Genome genome) throws IOException {
}


/**
* 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).getChr();
} else {
try {
ChromAlias aliasRecord = search(alias);
if(aliasRecord == null) {
aliasRecord.put(alias, null); // Prevents future attempts
} else {
return aliasRecord.getChr();
}
} catch (IOException e) {
// TODO -- log
}
}
return null;
}

/**
* Return an alternate chromosome name (alias).
*
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/broad/igv/feature/genome/ChromAliasDefaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ private void init(String id, List<String> chromosomeNames) {
}
}

/**
* 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).getChr() : alias;
}

/**
* Return an alternate chromosome name (alias).
*
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/broad/igv/feature/genome/ChromAliasFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ public ChromAliasFile(List<List<String>> chromAliases, List<String> chromosomeNa
}


/**
* Return the canonical chromosome name for the alias. If none found return the alias
*
* @param alias
* @returns {*}
*/
public String getChromosomeName(String alias) {
return this.aliasCache.containsKey(alias) ? this.aliasCache.get(alias).getChr() : alias;
}

/**
* Return an alternate chromosome name (alias).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public ChromAliasSource() {
aliasCache = new HashMap<>();
}

public abstract String getChromosomeName(String alias);

public abstract String getChromosomeAlias(String chr, String nameSet);

public abstract ChromAlias search(String alias) throws IOException;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/broad/igv/feature/genome/Genome.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,24 @@ private void addTracks(GenomeConfig config) {
public String getCanonicalChrName(String str) {
if (str == null) {
return str;
} else if (chrAliasCache.containsKey(str)) {
}

if (chrAliasCache.containsKey(str)) {
return chrAliasCache.get(str);
} else if (chromAliasSource != null) {
try {
ChromAlias aliasRecord = chromAliasSource.search(str);

if(aliasRecord == null && !str.equals(str.toLowerCase())) {
aliasRecord = chromAliasSource.search(str.toLowerCase());
}

if (aliasRecord != null) {
String chr = aliasRecord.getChr();
for (String a : aliasRecord.values()) {
chrAliasCache.put(a, chr);
}
chrAliasCache.put(str, chr); // Usually redundant, but will catch lowercase search case
return chr;
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static void setup() {
public void getChromosomeName() throws IOException {
String path = "test/data/genomes/GCF_000002655.1.chromAlias.bb";
ChromAliasSource chromAlias = new ChromAliasBB(path, mockGenome);
assertEquals("NC_007194.1", chromAlias.getChromosomeName("CM000169.1")) ;
assertEquals("NC_007194.1", chromAlias.getChromosomeName( "1"));
assertEquals("NC_007194.1", chromAlias.getChromosomeName( "chr1"));
assertEquals("NC_007194.1", chromAlias.search("CM000169.1").getChr());
assertEquals("NC_007194.1", chromAlias.search( "1").getChr());
assertEquals("NC_007194.1", chromAlias.search( "chr1").getChr());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public static void setup() {
@Test
public void getCanonicalChromosomeName() {

assertEquals(ncibMockGenome.getCanonicalChrName("chrX"), "23");
assertEquals(ncibMockGenome.getCanonicalChrName("chrM"), "MT");
assertEquals("23", ncibMockGenome.getCanonicalChrName("chrX"));
assertEquals("MT", ncibMockGenome.getCanonicalChrName("chrM"));

assertEquals(ucscMockGenome.getCanonicalChrName("23"), "chrX");
assertEquals(ucscMockGenome.getCanonicalChrName("MT"), "chrM");
assertEquals("chrX", ucscMockGenome.getCanonicalChrName("23"));
assertEquals("chrM", ucscMockGenome.getCanonicalChrName("MT"));

assertEquals("chr1", ucscMockGenome.getCanonicalChrName("Chr1"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static void setup() {
public void getChromosomeName() throws IOException {
String path = TestUtils.DATA_DIR + "genomes/GCF_000002655.1.chromAlias.txt";
ChromAliasFile chromAlias = new ChromAliasFile(path, mockGenome.getChromosomeNames());
assertEquals("NC_007194.1", chromAlias.getChromosomeName("CM000169.1")) ;
assertEquals("NC_007194.1", chromAlias.getChromosomeName( "1"));
assertEquals("NC_007194.1", chromAlias.getChromosomeName( "chr1"));
assertEquals("NC_007194.1", chromAlias.search("CM000169.1").getChr()) ;
assertEquals("NC_007194.1", chromAlias.search( "1").getChr());
assertEquals("NC_007194.1", chromAlias.search( "chr1").getChr());
}

@Test
Expand Down
Loading