Skip to content

Commit

Permalink
Implement reader for UCSC ".2bit" sequence format
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 2, 2023
1 parent e76048d commit dcee1f1
Show file tree
Hide file tree
Showing 30 changed files with 438 additions and 63,605 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ColorSpaceSequence(Sequence sequence) {
public byte[] getSequence(String chr, int start, int end) {
// We need to know the base just to the left of the start
int csStart = (start == 0 ? 0 : start - 1);
byte[] baseSequence = sequence.getSequence(chr, csStart, end, true);
byte[] baseSequence = sequence.getSequence(chr, csStart, end);
if (baseSequence == null || baseSequence.length == 0) {
return baseSequence;
}
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/org/broad/igv/feature/genome/Genome.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,7 @@ public byte[] getSequence(String chr, int start, int end, boolean useCache) {
if (end <= start) {
return null;
}
return sequence.getSequence(chr, start, end, useCache);
}

public boolean sequenceIsRemote() {
return sequence.isRemote();
}

public boolean sequenceIsFasta() {
return sequence.isFasta();
return sequence.getSequence(chr, start, end);
}

public String getDisplayName() {
Expand Down Expand Up @@ -633,11 +625,6 @@ private static synchronized String getSpeciesForID(String id) {
ucsdIDMap.put("b37", "hg19");
}


public boolean sequenceIsLoaded(ReferenceFrame frame) {
return sequence.isLoaded(frame);
}

public void setAnnotationResources(List<ResourceLocator> annotationResources) {
this.annotationResources = annotationResources;
}
Expand Down
179 changes: 0 additions & 179 deletions src/main/java/org/broad/igv/feature/genome/IGVSequence.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public InMemorySequence(String chr, byte[] seq) {
sequenceMap.put(chr, seq);
}

public byte[] getSequence(String chr, int qstart, int qend, boolean useCache) {
public byte[] getSequence(String chr, int qstart, int qend) {
byte[] allBytes = sequenceMap.get(chr);
if (allBytes == null) {
return null;
Expand Down Expand Up @@ -86,8 +86,4 @@ public int getChromosomeLength(String chrname) {
return bytes == null ? 0 : bytes.length;
}

@Override
public boolean isRemote() {
return false;
}
}
9 changes: 1 addition & 8 deletions src/main/java/org/broad/igv/feature/genome/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@
*/
public interface Sequence {

byte[] getSequence(String chr, int start, int end, boolean useCache);
byte[] getSequence(String chr, int start, int end);

byte getBase(String chr, int position);

List<String> getChromosomeNames();

int getChromosomeLength(String chrname);

default boolean isLoaded(ReferenceFrame frame) {
return false;
}

boolean isRemote();

default boolean isFasta() {return false;}
}
36 changes: 5 additions & 31 deletions src/main/java/org/broad/igv/feature/genome/SequenceWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,17 @@ public int getChromosomeLength(String chrname) {
return sequence.getChromosomeLength(chrname);
}

@Override
public boolean isLoaded(ReferenceFrame frame) {
if (!cacheSequences) return false;

int startTile = (int) frame.getOrigin() / tileSize;
int endTile = (int) frame.getEnd() / tileSize;
String chr = frame.getChrName();
for (int i = startTile; i <= endTile; i++) {
String key = getKey(chr, i);
if (!sequenceCache.containsKey(key)) return false;

}
return true;
}

@Override
public boolean isRemote() {
return sequence.isRemote();
}

@Override
public boolean isFasta() {
return sequence.isFasta();
}

/**
* Return the reference dna sequence for the exact interval specified.
*
* @param chr
* @param start
* @param end
* @param useCache
* @return
*/
public byte[] getSequence(String chr, int start, int end, boolean useCache) {
public byte[] getSequence(String chr, int start, int end) {

if (cacheSequences && useCache) {
if (cacheSequences) {
byte[] seqbytes = new byte[end - start];

int startTile = start / tileSize;
Expand Down Expand Up @@ -170,7 +144,7 @@ public byte[] getSequence(String chr, int start, int end, boolean useCache) {

return seqbytes;
} else {
return sequence.getSequence(chr, start, end, useCache);
return sequence.getSequence(chr, start, end);
}
}

Expand All @@ -187,7 +161,7 @@ private SequenceTile getSequenceTile(String chr, int tileNo) {
return null;
}

byte[] seq = sequence.getSequence(chr, start, end, true);
byte[] seq = sequence.getSequence(chr, start, end);
tile = new SequenceTile(start, seq);
sequenceCache.put(key, tile);
}
Expand Down Expand Up @@ -235,7 +209,7 @@ private SequenceTile[] getSequenceTiles(String chr, int startTile, int endTile)
private void loadTiles(String chr, int startTile, SequenceTile[] tiles, TileRange toLoad) {
int start = toLoad.startTile * tileSize;
int end = (toLoad.endTile + 1) * tileSize;
byte[] seq = sequence.getSequence(chr, start, end, true);
byte[] seq = sequence.getSequence(chr, start, end);

if(seq == null) {
log.warn("Null sequence for " + chr + ":" + start + "-" + end);
Expand Down
Loading

0 comments on commit dcee1f1

Please sign in to comment.