Skip to content

Commit

Permalink
use nameField when parsing BED files (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvolkening committed Nov 3, 2022
1 parent 03d9c41 commit 275eae3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion js/feature/decode/ucsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function decodeBed(tokens, header) {
const attributeKVs = parseAttributeString(tokens[3], '=')
feature.attributes = {}
for (let kv of attributeKVs) {
feature.attributes[kv[0]] = kv[1]
feature.attributes[kv[0]] = kv[1];
if (header.nameField != undefined && kv[0] === header.nameField) {
feature.name = kv[1];
}
}
}
if (!feature.name) {
Expand Down
5 changes: 5 additions & 0 deletions test/data/bed/gfftags.bed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#gffTags
track name="chr1" description="chr1 Annotations" itemRgb="On"
chr1 1088 1128 Key1=INS230;Key2=Foo 0 + 1088 1088 65,105,225
chr1 133 2809 Key2=Bar;Key1=terminator 0 + 133 133 65,105,225
chr1 1301 1746 Key1=M13 origin;Key2=Baz 0 + 1301 1301 65,105,225
17 changes: 17 additions & 0 deletions test/testBED.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,22 @@ suite("testBed", function () {
assert.equal(23, features.length); // # of features over this region
})

test("gffTags/nameField", async function () {
const config = {
type: "annotation",
format: "bed",
delimiter: "\t",
indexed: false,
nameField: "Key1",
url: require.resolve("./data/bed/gfftags.bed")
}
const reader = new FeatureFileReader(config);
const features = await reader.readFeatures("chr1", 0, Number.MAX_VALUE);
assert.ok(features);
assert.equal(features.length, 3);
assert.equal(features[1].name, 'terminator');
assert.equal(features[2].name, 'M13 origin');
})

})

0 comments on commit 275eae3

Please sign in to comment.