1
1
package is .hail .backend
2
2
3
3
import is .hail .asm4s ._
4
+ import is .hail .backend .Backend .jsonToBytes
4
5
import is .hail .backend .spark .SparkBackend
5
6
import is .hail .expr .ir .{
6
7
BaseIR , CodeCacheKey , CompiledFunction , IR , IRParser , IRParserEnvironment , LoweringAnalyses ,
7
8
SortField , TableIR , TableReader ,
8
9
}
9
- import is .hail .expr .ir .functions .IRFunctionRegistry
10
10
import is .hail .expr .ir .lowering .{TableStage , TableStageDependency }
11
11
import is .hail .io .{BufferSpec , TypedCodecSpec }
12
12
import is .hail .io .fs ._
@@ -20,7 +20,6 @@ import is.hail.types.virtual.{BlockMatrixType, TFloat64}
20
20
import is .hail .utils ._
21
21
import is .hail .variant .ReferenceGenome
22
22
23
- import scala .collection .JavaConverters ._
24
23
import scala .collection .mutable
25
24
import scala .reflect .ClassTag
26
25
@@ -29,7 +28,7 @@ import java.nio.charset.StandardCharsets
29
28
30
29
import com .fasterxml .jackson .core .StreamReadConstraints
31
30
import org .json4s ._
32
- import org .json4s .jackson .{ JsonMethods , Serialization }
31
+ import org .json4s .jackson .JsonMethods
33
32
import sourcecode .Enclosing
34
33
35
34
object Backend {
@@ -41,13 +40,6 @@ object Backend {
41
40
s " hail_query_ $id"
42
41
}
43
42
44
- private var irID : Int = 0
45
-
46
- def nextIRID (): Int = {
47
- irID += 1
48
- irID
49
- }
50
-
51
43
def encodeToOutputStream (
52
44
ctx : ExecuteContext ,
53
45
t : PTuple ,
@@ -66,6 +58,9 @@ object Backend {
66
58
assert(t.isFieldDefined(off, 0 ))
67
59
codec.encode(ctx, elementType, t.loadField(off, 0 ), os)
68
60
}
61
+
62
+ def jsonToBytes (f : => JValue ): Array [Byte ] =
63
+ JsonMethods .compact(f).getBytes(StandardCharsets .UTF_8 )
69
64
}
70
65
71
66
abstract class BroadcastValue [T ] { def value : T }
@@ -89,14 +84,6 @@ abstract class Backend extends Closeable {
89
84
90
85
val persistedIR : mutable.Map [Int , BaseIR ] = mutable.Map ()
91
86
92
- protected [this ] def addJavaIR (ir : BaseIR ): Int = {
93
- val id = Backend .nextIRID()
94
- persistedIR += (id -> ir)
95
- id
96
- }
97
-
98
- def removeJavaIR (id : Int ): Unit = persistedIR.remove(id)
99
-
100
87
def defaultParallelism : Int
101
88
102
89
def canExecuteParallelTasksOnDriver : Boolean = true
@@ -131,30 +118,7 @@ abstract class Backend extends Closeable {
131
118
def lookupOrCompileCachedFunction [T ](k : CodeCacheKey )(f : => CompiledFunction [T ])
132
119
: CompiledFunction [T ]
133
120
134
- var references : Map [String , ReferenceGenome ] = Map .empty
135
-
136
- def addDefaultReferences (): Unit =
137
- references = ReferenceGenome .builtinReferences()
138
-
139
- def addReference (rg : ReferenceGenome ): Unit = {
140
- references.get(rg.name) match {
141
- case Some (rg2) =>
142
- if (rg != rg2) {
143
- fatal(
144
- s " Cannot add reference genome ' ${rg.name}', a different reference with that name already exists. Choose a reference name NOT in the following list: \n " +
145
- s " @1 " ,
146
- references.keys.truncatable(" \n " ),
147
- )
148
- }
149
- case None =>
150
- references += (rg.name -> rg)
151
- }
152
- }
153
-
154
- def hasReference (name : String ) = references.contains(name)
155
-
156
- def removeReference (name : String ): Unit =
157
- references -= name
121
+ def references : mutable.Map [String , ReferenceGenome ]
158
122
159
123
def lowerDistributedSort (
160
124
ctx : ExecuteContext ,
@@ -189,9 +153,6 @@ abstract class Backend extends Closeable {
189
153
190
154
def withExecuteContext [T ](f : ExecuteContext => T )(implicit E : Enclosing ): T
191
155
192
- private [this ] def jsonToBytes (f : => JValue ): Array [Byte ] =
193
- JsonMethods .compact(f).getBytes(StandardCharsets .UTF_8 )
194
-
195
156
final def valueType (s : String ): Array [Byte ] =
196
157
jsonToBytes {
197
158
withExecuteContext { ctx =>
@@ -220,15 +181,7 @@ abstract class Backend extends Closeable {
220
181
}
221
182
}
222
183
223
- def loadReferencesFromDataset (path : String ): Array [Byte ] = {
224
- withExecuteContext { ctx =>
225
- val rgs = ReferenceGenome .fromHailDataset(ctx.fs, path)
226
- rgs.foreach(addReference)
227
-
228
- implicit val formats : Formats = defaultJSONFormats
229
- Serialization .write(rgs.map(_.toJSON).toFastSeq).getBytes(StandardCharsets .UTF_8 )
230
- }
231
- }
184
+ def loadReferencesFromDataset (path : String ): Array [Byte ]
232
185
233
186
def fromFASTAFile (
234
187
name : String ,
@@ -240,18 +193,22 @@ abstract class Backend extends Closeable {
240
193
parInput : Array [String ],
241
194
): Array [Byte ] =
242
195
withExecuteContext { ctx =>
243
- val rg = ReferenceGenome .fromFASTAFile(ctx, name, fastaFile, indexFile,
244
- xContigs, yContigs, mtContigs, parInput)
245
- rg.toJSONString.getBytes(StandardCharsets .UTF_8 )
196
+ jsonToBytes {
197
+ Extraction .decompose {
198
+ ReferenceGenome .fromFASTAFile(ctx, name, fastaFile, indexFile,
199
+ xContigs, yContigs, mtContigs, parInput).toJSON
200
+ }(defaultJSONFormats)
201
+ }
246
202
}
247
203
248
- def parseVCFMetadata (path : String ): Array [Byte ] = jsonToBytes {
204
+ def parseVCFMetadata (path : String ): Array [Byte ] =
249
205
withExecuteContext { ctx =>
250
- val metadata = LoadVCF .parseHeaderMetadata(ctx.fs, Set .empty, TFloat64 , path)
251
- implicit val formats = defaultJSONFormats
252
- Extraction .decompose(metadata)
206
+ jsonToBytes {
207
+ Extraction .decompose {
208
+ LoadVCF .parseHeaderMetadata(ctx.fs, Set .empty, TFloat64 , path)
209
+ }(defaultJSONFormats)
210
+ }
253
211
}
254
- }
255
212
256
213
def importFam (path : String , isQuantPheno : Boolean , delimiter : String , missingValue : String )
257
214
: Array [Byte ] =
@@ -261,27 +218,6 @@ abstract class Backend extends Closeable {
261
218
)
262
219
}
263
220
264
- def pyRegisterIR (
265
- name : String ,
266
- typeParamStrs : java.util.ArrayList [String ],
267
- argNameStrs : java.util.ArrayList [String ],
268
- argTypeStrs : java.util.ArrayList [String ],
269
- returnType : String ,
270
- bodyStr : String ,
271
- ): Unit = {
272
- withExecuteContext { ctx =>
273
- IRFunctionRegistry .registerIR(
274
- ctx,
275
- name,
276
- typeParamStrs.asScala.toArray,
277
- argNameStrs.asScala.toArray,
278
- argTypeStrs.asScala.toArray,
279
- returnType,
280
- bodyStr,
281
- )
282
- }
283
- }
284
-
285
221
def execute (ctx : ExecuteContext , ir : IR ): Either [Unit , (PTuple , Long )]
286
222
}
287
223
0 commit comments