Skip to content

Commit b9f813f

Browse files
Add configurable ADDITIONAL_IDS
1 parent f44f6dd commit b9f813f

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

packages/apollo-collaboration-server/src/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const validationSchema = Joi.object({
5757
DESCRIPTION: Joi.string(),
5858
FEATURE_TYPE_ONTOLOGY_LOCATION: Joi.string(),
5959
PLUGIN_LOCATION: Joi.string(),
60+
ADDITIONAL_IDS: Joi.string(),
6061
ALLOW_ROOT_USER: Joi.boolean().default(false),
6162
ROOT_USER_PASSWORD: Joi.string(),
6263
ROOT_USER_PASSWORD_FILE: Joi.string(),

packages/apollo-common/src/AssemblySpecificChange.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
2+
import { type AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
3+
24
import {
35
Change,
46
type ChangeOptions,
@@ -26,4 +28,27 @@ export abstract class AssemblySpecificChange extends Change {
2628
super(json, options)
2729
this.assembly = json.assembly
2830
}
31+
32+
getIndexedIds(
33+
feature: AnnotationFeatureSnapshot,
34+
additionalIds: string[] | undefined,
35+
): string[] {
36+
const indexedIds: string[] = []
37+
if (feature.featureId) {
38+
indexedIds.push(feature.featureId)
39+
}
40+
for (const additionalId of additionalIds ?? []) {
41+
const idValue = feature.attributes?.[additionalId]
42+
if (idValue) {
43+
indexedIds.push(idValue[0])
44+
}
45+
}
46+
if (feature.children) {
47+
for (const child of Object.values(feature.children)) {
48+
const childIndexedIds = this.getIndexedIds(child, additionalIds)
49+
indexedIds.push(...childIndexedIds)
50+
}
51+
}
52+
return indexedIds
53+
}
2954
}

packages/apollo-schemas/src/feature.schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class Feature
2525
@Prop({ type: [String], required: true, index: true })
2626
allIds: string[]
2727

28+
@Prop({ type: [String], index: true, sparse: true })
29+
indexedIds?: string[]
30+
2831
@Prop({ required: true })
2932
type: string
3033

packages/apollo-shared/src/Changes/AddFeatureChange.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export class AddFeatureChange extends FeatureChange {
8989
let featureCnt = 0
9090
logger.debug?.(`changes: ${JSON.stringify(changes)}`)
9191

92+
const { ADDITIONAL_IDS } = process.env
93+
let additionalIds: string[] | undefined
94+
if (ADDITIONAL_IDS) {
95+
additionalIds = ADDITIONAL_IDS.split(',')
96+
}
97+
9298
// Loop the changes
9399
for (const change of changes) {
94100
logger.debug?.(`change: ${JSON.stringify(change)}`)
@@ -106,9 +112,10 @@ export class AddFeatureChange extends FeatureChange {
106112

107113
// CopyFeature is called from CopyFeature.tsx
108114
if (copyFeature) {
115+
const indexedIds = this.getIndexedIds(addedFeature, additionalIds)
109116
// Add into Mongo
110117
const [newFeatureDoc] = await featureModel.create(
111-
[{ ...addedFeature, allIds, status: -1, user }],
118+
[{ ...addedFeature, allIds, indexedIds, status: -1, user }],
112119
{ session },
113120
)
114121
logger.debug?.(
@@ -143,8 +150,9 @@ export class AddFeatureChange extends FeatureChange {
143150
} else {
144151
const childIds = this.getChildFeatureIds(addedFeature)
145152
const allIdsV2 = [_id, ...childIds]
153+
const indexedIds = this.getIndexedIds(addedFeature, additionalIds)
146154
const [newFeatureDoc] = await featureModel.create(
147-
[{ allIds: allIdsV2, status: 0, ...addedFeature }],
155+
[{ allIds: allIdsV2, indexedIds, status: 0, ...addedFeature }],
148156
{ session },
149157
)
150158
logger.verbose?.(`Added docId "${newFeatureDoc._id}"`)

packages/apollo-shared/src/Changes/FromFileBaseChange.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ export abstract class FromFileBaseChange extends AssemblySpecificChange {
184184
}
185185

186186
async addFeatureIntoDb(gff3Feature: GFF3Feature, backend: ServerDataStore) {
187-
const { featureModel, refSeqModel, user } = backend
187+
const { ADDITIONAL_IDS } = process.env
188+
let additionalIds: string[] | undefined
189+
if (ADDITIONAL_IDS) {
190+
additionalIds = ADDITIONAL_IDS.split(',')
191+
}
188192
const { assembly, refSeqCache } = this
193+
const { featureModel, refSeqModel, user } = backend
189194

190195
const [{ seq_id: refName }] = gff3Feature
191196
if (!refName) {
@@ -209,10 +214,13 @@ export abstract class FromFileBaseChange extends AssemblySpecificChange {
209214
}
210215
const newFeature = gff3ToAnnotationFeature(gff3Feature, refSeqDoc._id)
211216
const allIds = this.getAllIds(newFeature)
217+
const indexedIds = this.getIndexedIds(newFeature, additionalIds)
212218

213219
// Add into Mongo
214220
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
215-
await featureModel.create([{ allIds, ...newFeature, user, status: -1 }])
221+
await featureModel.create([
222+
{ allIds, indexedIds, ...newFeature, user, status: -1 },
223+
])
216224
}
217225

218226
getAllIds(feature: AnnotationFeatureSnapshot): string[] {

packages/website/docs/02-installation/04-configuration-options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ MICROSOFT_CLIENT_SECRET=client_secret_here
6464
# Defaults to relative URL 'sequence_ontology.json'
6565
# FEATURE_TYPE_ONTOLOGY_LOCATION=sequence_ontology.json
6666

67+
# Comma-separated list of additional attributes in features to treat as ids
68+
# These will be added to feature documents' "indexedIds"
69+
# ADDITIONAL_IDS=gene_id,transcript_id,exon_id
70+
6771
# Application port, defaults to 3999
6872
# PORT=3999
6973

0 commit comments

Comments
 (0)