-
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.
- Loading branch information
Showing
56 changed files
with
1,329 additions
and
7,316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.broad.igv.bbfile; | ||
|
||
class BBBlock { | ||
long offset; | ||
long size; | ||
|
||
public BBBlock(long offset, long size) { | ||
this.offset = offset; | ||
this.size = size; | ||
} | ||
} |
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.bbfile; | ||
|
||
import org.broad.igv.util.ByteBufferUnsigned; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
/** | ||
* Parser for BB chromosome tree - a B+ tree of chromosomes, their sizes, and a unique ID for each. | ||
*/ | ||
public class BBChromTree { | ||
|
||
private final int keySize; | ||
private final int valSize; | ||
private final long startOffset; | ||
|
||
Map<String, Integer> nameToIdMap; | ||
Map<Integer, String> idToNameMap; | ||
Map<String, Long> nameToSizeMap; | ||
|
||
BBChromTree(ByteBufferUnsigned bb, long startOffset) { | ||
|
||
int magic = bb.getInt(); | ||
boolean legit = magic == 0x78CA8C91; | ||
int blockSize = bb.getInt(); | ||
this.keySize = bb.getInt(); | ||
this.valSize = bb.getInt(); | ||
long itemCount = bb.getLong(); | ||
long reserved = bb.getLong(); | ||
|
||
this.nameToIdMap = new HashMap<>(); | ||
this.idToNameMap = new HashMap<>(); | ||
this.nameToSizeMap = new HashMap<>(); | ||
|
||
// Kick off the recursive walk of the tree | ||
this.startOffset = startOffset; | ||
this.readTreeNode(-1, bb); | ||
} | ||
|
||
void readTreeNode(int offset, ByteBufferUnsigned bb) { | ||
|
||
if (offset >= 0) bb.position(offset); | ||
byte type = bb.get(); | ||
byte reserved = bb.get(); | ||
int count = bb.getUShort(); | ||
|
||
if (type == 1) { | ||
// Leaf node -- supplemental table 10 | ||
for (int i = 0; i < count; i++) { | ||
String name = bb.getFixedLengthString(keySize); | ||
if (valSize == 8) { | ||
int id = bb.getInt(); | ||
long chromSize = bb.getUInt(); | ||
//if (genome) key = genome.getChromosomeName(key) // Translate to canonical chr name | ||
this.nameToIdMap.put(name, id); | ||
this.idToNameMap.put(id, name); | ||
this.nameToSizeMap.put(name, chromSize); | ||
|
||
} else { | ||
throw new RuntimeException("Unexpected 'valSize' in chromosome tree. Expected 8, actual value is" + valSize); | ||
} | ||
} | ||
} else { | ||
// non leave node - supplemental table 12 | ||
for (int i = 0; i < count; i++) { | ||
String key = bb.getFixedLengthString(keySize); | ||
long childOffset = bb.getLong(); | ||
int bufferOffset = (int) (childOffset - startOffset); | ||
int currOffset = bb.position(); | ||
readTreeNode(bufferOffset, bb); | ||
bb.position(currOffset); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.