-
Notifications
You must be signed in to change notification settings - Fork 60
/
util.ts
176 lines (158 loc) · 4 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { isSupportedIndexingAdapter } from '@jbrowse/core/util'
import sanitize from 'sanitize-filename'
import path from 'path'
export interface UriLocation {
uri: string
locationType: 'UriLocation'
}
export interface LocalPathLocation {
localPath: string
locationType: 'LocalPathLocation'
}
export interface IndexedFastaAdapter {
type: 'IndexedFastaAdapter'
fastaLocation: UriLocation
faiLocation: UriLocation
}
export interface BgzipFastaAdapter {
type: 'BgzipFastaAdapter'
fastaLocation: UriLocation
faiLocation: UriLocation
gziLocation: UriLocation
}
export interface TwoBitAdapter {
type: 'TwoBitAdapter'
twoBitLocation: UriLocation
}
export interface ChromeSizesAdapter {
type: 'ChromSizesAdapter'
chromSizesLocation: UriLocation
}
export interface CustomSequenceAdapter {
type: string
}
export interface RefNameAliasAdapter {
type: 'RefNameAliasAdapter'
location: UriLocation
}
export interface CustomRefNameAliasAdapter {
type: string
}
export interface Assembly {
displayName?: string
name: string
aliases?: string[]
sequence: Sequence
refNameAliases?: {
adapter: RefNameAliasAdapter | CustomRefNameAliasAdapter
}
refNameColors?: string[]
}
export interface Sequence {
type: 'ReferenceSequenceTrack'
trackId: string
adapter:
| IndexedFastaAdapter
| BgzipFastaAdapter
| TwoBitAdapter
| ChromeSizesAdapter
| CustomSequenceAdapter
}
export interface Gff3TabixAdapter {
type: 'Gff3TabixAdapter'
gffGzLocation: UriLocation | LocalPathLocation
}
export interface Gff3Adapter {
type: 'Gff3Adapter'
gffLocation: UriLocation | LocalPathLocation
}
export interface GtfAdapter {
type: 'GtfAdapter'
gtfLocation: UriLocation | LocalPathLocation
}
export interface VcfTabixAdapter {
type: 'VcfTabixAdapter'
vcfGzLocation: UriLocation | LocalPathLocation
}
export interface VcfAdapter {
type: 'VcfAdapter'
vcfLocation: UriLocation | LocalPathLocation
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Track = Record<string, any>
export interface TextSearching {
indexingFeatureTypesToExclude?: string[]
indexingAttributes?: string[]
textSearchAdapter: TrixTextSearchAdapter
}
export interface TrixTextSearchAdapter {
type: string
textSearchAdapterId: string
ixFilePath: UriLocation
ixxFilePath: UriLocation
metaFilePath: UriLocation
assemblyNames: string[]
}
export interface Config {
assemblies?: Assembly[]
assembly?: Assembly
configuration?: {}
aggregateTextSearchAdapters?: TrixTextSearchAdapter[]
connections?: unknown[]
defaultSession?: {}
tracks?: Track[]
}
export type indexType = 'aggregate' | 'perTrack'
export function createTextSearchConf(
name: string,
trackIds: string[],
assemblyNames: string[],
locationPath: string,
) {
const base = path.join(locationPath, 'trix')
const n = sanitize(name)
return {
type: 'TrixTextSearchAdapter',
textSearchAdapterId: name,
ixFilePath: {
localPath: path.join(base, `${n}.ix`),
locationType: 'LocalPathLocation',
},
ixxFilePath: {
localPath: path.join(base, `${n}.ixx`),
locationType: 'LocalPathLocation',
},
metaFilePath: {
localPath: path.join(base, `${n}.json`),
locationType: 'LocalPathLocation',
},
tracks: trackIds,
assemblyNames,
}
}
export function findTrackConfigsToIndex(
tracks: Track[],
trackIds: string[],
assemblyName?: string,
) {
return trackIds
.map(trackId => {
const currentTrack = tracks.find(t => trackId === t.trackId)
if (!currentTrack) {
throw new Error(`Track not found in session for trackId ${trackId}`)
}
return currentTrack
})
.filter(track =>
assemblyName ? track.assemblyNames.includes(assemblyName) : true,
)
.filter(track => isSupportedIndexingAdapter(track.adapter?.type))
}
export function decodeURIComponentNoThrow(uri: string) {
try {
return decodeURIComponent(uri)
} catch (e) {
// avoid throwing exception on a failure to decode URI component
return uri
}
}