Skip to content

Commit 191b9b1

Browse files
Update gff conversion tests
1 parent 8aa1e44 commit 191b9b1

File tree

10 files changed

+153
-60
lines changed

10 files changed

+153
-60
lines changed

packages/apollo-shared/src/GFF3/annotationFeatureToGFF3.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/* eslint-disable prefer-destructuring */
22
/* eslint-disable @typescript-eslint/no-floating-promises */
3-
import { readFileSync, writeFileSync } from 'node:fs'
3+
import { readFileSync } from 'node:fs'
44
import { describe, it } from 'node:test'
55

66
import { type AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
77
import { formatSync } from '@gmod/gff'
88
import { assert, expect } from 'chai'
99

1010
import { annotationFeatureToGFF3 } from './annotationFeatureToGFF3'
11-
import { readAnnotationFeatureSnapshot } from './gff3ToAnnotationFeature.test'
12-
import { testCases } from './testUtil'
11+
import { readAnnotationFeatureSnapshot, testCases } from './testUtil'
1312

1413
describe('Converts AnnotationFeatureSnapshot JSON to GFF3 when', () => {
1514
for (const testCase of testCases) {
@@ -26,9 +25,6 @@ describe('Converts AnnotationFeatureSnapshot JSON to GFF3 when', () => {
2625
annotationFeatureToGFF3(annotationFeature),
2726
)
2827
const gff3 = formatSync(gffFeatures)
29-
if (gff3 !== expectedGFF3) {
30-
writeFileSync(`test_data/${filenameStem}.tmp.gff3`, gff3)
31-
}
3228
expect(gff3).to.equal(expectedGFF3)
3329
})
3430
}

packages/apollo-shared/src/GFF3/gff3ToAnnotationFeature.test.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-floating-promises */
2-
import { readFileSync, writeFileSync } from 'node:fs'
2+
import { readFileSync } from 'node:fs'
33
import { describe, it } from 'node:test'
44

55
import { type AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
@@ -8,7 +8,7 @@ import { assert, use } from 'chai'
88
import chaiExclude from 'chai-exclude'
99

1010
import { gff3ToAnnotationFeature } from './gff3ToAnnotationFeature'
11-
import { testCases } from './testUtil'
11+
import { readAnnotationFeatureSnapshot, testCases } from './testUtil'
1212

1313
use(chaiExclude)
1414

@@ -53,10 +53,6 @@ describe('Converts GFF3 to AnnotationFeatureSnapshot JSON when', () => {
5353
const annotationFeaturesExpected = JSON.parse(
5454
readFileSync(`test_data/${filenameStem}.json`, 'utf8'),
5555
) as AnnotationFeatureSnapshot[]
56-
writeFileSync(
57-
`test_data/${filenameStem}.tmp.json`,
58-
JSON.stringify(annotationFeatures, null, 2),
59-
)
6056
for (const [
6157
i,
6258
annotationFeatureExpected,
@@ -80,13 +76,6 @@ function readFeatureFile(fn: string): GFF3Feature[] {
8076
return inGff
8177
}
8278

83-
export function readAnnotationFeatureSnapshot(
84-
fn: string,
85-
): AnnotationFeatureSnapshot {
86-
const lines = readFileSync(fn).toString()
87-
return JSON.parse(lines) as AnnotationFeatureSnapshot
88-
}
89-
9079
const [ex1, , ex2, , ex3, , ex4] = readFeatureFile(
9180
'test_data/gene_representations.gff3',
9281
)

packages/apollo-shared/src/GFF3/gff3ToAnnotationFeature.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export function gff3ToAnnotationFeature(
5959
}
6060
if (convertedAttributes) {
6161
const [att, id] = convertedAttributes
62-
feature.attributes = att
62+
if (Object.keys(att).length > 0) {
63+
feature.attributes = att
64+
}
6365
if (id) {
6466
feature.featureId = id
6567
}

packages/apollo-shared/src/GFF3/testUtil.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import { readFileSync } from 'node:fs'
2+
3+
import { type AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
4+
5+
export function readAnnotationFeatureSnapshot(
6+
fn: string,
7+
): AnnotationFeatureSnapshot {
8+
const lines = readFileSync(fn).toString()
9+
return JSON.parse(lines) as AnnotationFeatureSnapshot
10+
}
11+
112
export const testCases: { filenameStem: string; description: string }[] = [
213
{
314
filenameStem: 'single_feature_no_children',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"_id": "69334de4deb1c5f4c94488c3",
3+
"refSeq": "chr1",
4+
"type": "gene",
5+
"min": 999,
6+
"max": 9000,
7+
"strand": 1,
8+
"children": {
9+
"69334de4deb1c5f4c94488c2": {
10+
"_id": "69334de4deb1c5f4c94488c2",
11+
"refSeq": "chr1",
12+
"type": "mRNA",
13+
"min": 1299,
14+
"max": 9000,
15+
"strand": 1,
16+
"children": {
17+
"69334de4deb1c5f4c94488be": {
18+
"_id": "69334de4deb1c5f4c94488be",
19+
"refSeq": "chr1",
20+
"type": "CDS",
21+
"min": 4999,
22+
"max": 5500,
23+
"strand": 1,
24+
"featureId": "cds00001"
25+
},
26+
"69334de4deb1c5f4c94488bf": {
27+
"_id": "69334de4deb1c5f4c94488bf",
28+
"refSeq": "chr1",
29+
"type": "exon",
30+
"min": 2999,
31+
"max": 3300,
32+
"strand": 1
33+
},
34+
"69334de4deb1c5f4c94488c1": {
35+
"_id": "69334de4deb1c5f4c94488c1",
36+
"refSeq": "chr1",
37+
"type": "exon",
38+
"min": 4999,
39+
"max": 5500,
40+
"strand": 1
41+
},
42+
"69334de4deb1c5f4c94488c0": {
43+
"_id": "69334de4deb1c5f4c94488c0",
44+
"refSeq": "chr1",
45+
"type": "exon",
46+
"min": 7600,
47+
"max": 8000,
48+
"strand": 1
49+
}
50+
},
51+
"featureId": "mRNA00001"
52+
}
53+
},
54+
"featureId": "gene00001"
55+
}

packages/apollo-shared/test_data/cds_without_exon_spliced_utr.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"type": "CDS",
2121
"min": 3300,
2222
"max": 7600,
23-
"strand": 1
23+
"strand": 1,
24+
"featureId": "cds00003"
2425
},
2526
"675ad4e6a5abb3a5087c064a": {
2627
"_id": "675ad4e6a5abb3a5087c064a",
@@ -62,7 +63,9 @@
6263
"max": 8900,
6364
"strand": 1
6465
}
65-
}
66+
},
67+
"featureId": "mRNA00003"
6668
}
67-
}
69+
},
70+
"featureId": "gene00001"
6871
}

packages/apollo-shared/test_data/example01.json

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"type": "TF_binding_site",
1313
"min": 999,
1414
"max": 1012,
15-
"strand": 1
15+
"strand": 1,
16+
"featureId": "tfbs00001"
1617
},
1718
"66e049f17b9cedae9ad890fb": {
1819
"_id": "66e049f17b9cedae9ad890fb",
@@ -28,31 +29,35 @@
2829
"type": "exon",
2930
"min": 1049,
3031
"max": 1499,
31-
"strand": 1
32+
"strand": 1,
33+
"featureId": "exon00002"
3234
},
3335
"66e049f17b9cedae9ad890f7": {
3436
"_id": "66e049f17b9cedae9ad890f7",
3537
"refSeq": "chr1",
3638
"type": "exon",
3739
"min": 2999,
3840
"max": 3902,
39-
"strand": 1
41+
"strand": 1,
42+
"featureId": "exon00003"
4043
},
4144
"66e049f17b9cedae9ad890f8": {
4245
"_id": "66e049f17b9cedae9ad890f8",
4346
"refSeq": "chr1",
4447
"type": "exon",
4548
"min": 4999,
4649
"max": 5500,
47-
"strand": 1
50+
"strand": 1,
51+
"featureId": "exon00004"
4852
},
4953
"66e049f17b9cedae9ad890f9": {
5054
"_id": "66e049f17b9cedae9ad890f9",
5155
"refSeq": "chr1",
5256
"type": "exon",
5357
"min": 6999,
5458
"max": 9000,
55-
"strand": 1
59+
"strand": 1,
60+
"featureId": "exon00005"
5661
},
5762
"66e049f17b9cedae9ad890fa": {
5863
"_id": "66e049f17b9cedae9ad890fa",
@@ -86,23 +91,26 @@
8691
"type": "exon",
8792
"min": 1049,
8893
"max": 1499,
89-
"strand": 1
94+
"strand": 1,
95+
"featureId": "exon00002"
9096
},
9197
"66e049f17b9cedae9ad890fd": {
9298
"_id": "66e049f17b9cedae9ad890fd",
9399
"refSeq": "chr1",
94100
"type": "exon",
95101
"min": 4999,
96102
"max": 5500,
97-
"strand": 1
103+
"strand": 1,
104+
"featureId": "exon00004"
98105
},
99106
"66e049f17b9cedae9ad890fe": {
100107
"_id": "66e049f17b9cedae9ad890fe",
101108
"refSeq": "chr1",
102109
"type": "exon",
103110
"min": 6999,
104111
"max": 9000,
105-
"strand": 1
112+
"strand": 1,
113+
"featureId": "exon00005"
106114
},
107115
"66e049f17b9cedae9ad890ff": {
108116
"_id": "66e049f17b9cedae9ad890ff",
@@ -136,31 +144,35 @@
136144
"type": "exon",
137145
"min": 1299,
138146
"max": 1499,
139-
"strand": 1
147+
"strand": 1,
148+
"featureId": "exon00001"
140149
},
141150
"66e049f17b9cedae9ad89102": {
142151
"_id": "66e049f17b9cedae9ad89102",
143152
"refSeq": "chr1",
144153
"type": "exon",
145154
"min": 2999,
146155
"max": 3902,
147-
"strand": 1
156+
"strand": 1,
157+
"featureId": "exon00003"
148158
},
149159
"66e049f17b9cedae9ad89103": {
150160
"_id": "66e049f17b9cedae9ad89103",
151161
"refSeq": "chr1",
152162
"type": "exon",
153163
"min": 4999,
154164
"max": 5500,
155-
"strand": 1
165+
"strand": 1,
166+
"featureId": "exon00004"
156167
},
157168
"66e049f17b9cedae9ad89104": {
158169
"_id": "66e049f17b9cedae9ad89104",
159170
"refSeq": "chr1",
160171
"type": "exon",
161172
"min": 6999,
162173
"max": 9000,
163-
"strand": 1
174+
"strand": 1,
175+
"featureId": "exon00005"
164176
},
165177
"66e049f17b9cedae9ad89105": {
166178
"_id": "66e049f17b9cedae9ad89105",

0 commit comments

Comments
 (0)