Skip to content

Commit 5cdc590

Browse files
committed
add special codec for "bigRmsk" format
1 parent 6b5d8d4 commit 5cdc590

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

src/main/java/org/broad/igv/bbfile/codecs/BBBedCodec.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@
1313

1414
public class BBBedCodec implements BBCodec {
1515

16-
private final Genome genome;
16+
1717
private final BBUtils.ASTable astable;
1818

1919
int standardFieldCount;
2020
IGVBEDCodec igvBedCodec;
2121

2222
public BBBedCodec(int standardFieldCount, BBUtils.ASTable autosql) {
23-
this(standardFieldCount, autosql, null);
24-
}
25-
26-
public BBBedCodec(int standardFieldCount, BBUtils.ASTable autosql, Genome genome) {
27-
this.genome = genome;
2823
this.astable = autosql;
2924
this.standardFieldCount = standardFieldCount;
3025
this.igvBedCodec = new IGVBEDCodec(); // Backing "tribble" codec

src/main/java/org/broad/igv/bbfile/codecs/BBCodecFactory.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public static BBCodec getCodec(String autosql, int standardFieldCount) {
1212
BBUtils.ASTable astable = autosql == null ||
1313
autosql.length() == 0 ? null : BBUtils.parseAutosql(autosql);
1414

15-
return new BBBedCodec(standardFieldCount, astable);
15+
switch(astable.name) {
16+
case "bigRmskBed":
17+
return new BBRmskCodec(standardFieldCount, astable);
18+
default:
19+
return new BBBedCodec(standardFieldCount, astable);
20+
}
1621

1722
}
1823
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.broad.igv.bbfile.codecs;
2+
3+
import org.broad.igv.bbfile.BBUtils;
4+
import org.broad.igv.bbfile.BedData;
5+
import org.broad.igv.feature.BasicFeature;
6+
7+
import java.awt.*;
8+
import java.util.Map;
9+
10+
public class BBRmskCodec implements BBCodec {
11+
12+
BBBedCodec bedCodec;
13+
14+
public BBRmskCodec(int standardFieldCount, BBUtils.ASTable autosql) {
15+
bedCodec = new BBBedCodec(standardFieldCount, autosql);
16+
}
17+
18+
@Override
19+
public BasicFeature decode(BedData data) {
20+
BasicFeature feature = bedCodec.decode(data);
21+
22+
String name = feature.getName();
23+
String repClass = null;
24+
String[] parts = name.split("#");
25+
if (parts.length > 1) {
26+
name = parts[0];
27+
repClass = parts[1];
28+
}
29+
30+
feature.setName(name);
31+
if (repClass != null) {
32+
feature.setAttribute("Repeat Class", repClass);
33+
int idx1 = repClass.indexOf("/");
34+
String c = idx1 > 0 ? repClass.substring(0, idx1) : repClass;
35+
if (c.endsWith("?")) c = c.substring(c.length() - 1);
36+
Color color = classColors.containsKey(c) ? classColors.get(c) : defaultColor;
37+
feature.setColor(color);
38+
}
39+
40+
return feature;
41+
}
42+
43+
44+
static Map<String, Color> classColors = Map.of(
45+
"SINE", new Color(31, 119, 180),
46+
"LINE", new Color(255, 127, 14),
47+
"LTR", new Color(44, 160, 44),
48+
"DNA", new Color(214, 39, 40),
49+
"Simple", new Color(148, 103, 189),
50+
"Low_complexity", new Color(140, 86, 75),
51+
"Satellite", new Color(227, 119, 194),
52+
"RNA", new Color(127, 127, 127),
53+
"Other", new Color(188, 189, 34),
54+
"Unknown", new Color(23, 190, 207)
55+
);
56+
57+
static Color defaultColor = new Color(0, 180, 180);
58+
}

src/test/java/org/broad/igv/bbfile/BBDataSourceTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,29 @@ public void testBigInteract() throws IOException {
115115
assertTrue(count > 0);
116116
}
117117

118+
// NOTE: bigInteract is not yet supported in IGV desktop, bigInteract is treated as a plain bed file.
119+
@Test
120+
public void testBigRmsk() throws IOException {
121+
122+
String path = "https://hgdownload.soe.ucsc.edu/hubs/GCA/009/914/755/GCA_009914755.4/bbi/GCA_009914755.4_T2T-CHM13v2.0.t2tRepeatMasker/chm13v2.0_rmsk.bb";
123+
124+
BBFileReader bbReader = new BBFileReader(path);
125+
BBDataSource bbSource = new BBDataSource(bbReader, null);
126+
127+
String chr = "chr3";
128+
int start = 63081504;
129+
int end = 64501215;
130+
131+
Iterator<Feature> iter = bbSource.getFeatures(chr, start, end);
132+
133+
int count = 0;
134+
while (iter.hasNext()) {
135+
Feature f = iter.next();
136+
assertEquals(chr, f.getChr());
137+
assertTrue(f.getStart() <= end && f.getEnd() >= start);
138+
count++;
139+
}
140+
assertTrue(count > 0);
141+
}
118142

119143
}

0 commit comments

Comments
 (0)