Skip to content

Commit 69ee590

Browse files
committed
New Treatments endpoint and bump to 5.0.0-alpha4
1 parent 9bf5a89 commit 69ee590

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name := "LuciusAPI"
22

33
import aether.AetherKeys._
44

5-
version in ThisBuild := "5.0.0-alpha2"
5+
version in ThisBuild := "5.0.0-alpha4"
66

77
scalaVersion := "2.11.12"
88

99
resolvers += Resolver.githubPackages("data-intuitive")
1010
resolvers += "Artifactory" at "https://sparkjobserver.jfrog.io/artifactory/jobserver/"
1111

1212
libraryDependencies ++= Seq(
13-
"com.data-intuitive" %% "luciuscore" % "4.0.1-SNAPSHOT",
13+
"com.data-intuitive" %% "luciuscore" % "4.0.5",
1414
"spark.jobserver" %% "job-server-api" % "0.11.1" % "provided",
1515
"spark.jobserver" %% "job-server-extras" % "0.11.1" % "provided",
1616
"org.scalactic" %% "scalactic" % "3.0.7" % "test" ,

src/main/scala/com/dataintuitive/luciusapi/Common.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ object Common extends Serializable {
167167
Try(config.getString("limit").toInt).getOrElse(default)
168168
}
169169

170+
def optParamLike(config: Config, default: List[String] = Nil): List[String] = {
171+
Try(config.getString("like").split(" ").toList).getOrElse(default)
172+
}
173+
174+
def optParamTrtType(config: Config, default: List[String] = Nil): List[String] = {
175+
Try(config.getString("trtType").split(" ").toList).getOrElse(default)
176+
}
177+
170178
def optParamFeatures(config: Config, default: List[String] = List(".*")): List[String] = {
171179
Try(config.getString("features").toString.split(" ").toList).getOrElse(default)
172180
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.dataintuitive.luciusapi
2+
3+
import com.dataintuitive.luciuscore._
4+
import genes._
5+
import api._
6+
7+
import Common.ParamHandlers._
8+
9+
import spark.jobserver.api.{JobEnvironment, SingleProblem, ValidationProblem}
10+
import spark.jobserver._
11+
12+
import scala.util.Try
13+
import org.scalactic._
14+
import Accumulation._
15+
import com.typesafe.config.Config
16+
17+
import org.apache.spark.sql.SparkSession
18+
import org.apache.spark.sql.Dataset
19+
20+
/**
21+
* Returns a list of treatments and corresponding samples matching a query, optionally with a limit on the number of results.
22+
*
23+
* Input:
24+
*
25+
* - __`query`__: Depending on the pattern, a regexp match or `startsWith` is applied (mandatory)
26+
*
27+
* - __`version`__: v1, v2 or t1 (optional, default is `v1`)
28+
*
29+
* - __`limit`__: The result size is limited to this number (optional, default is 10)
30+
*/
31+
object treatments extends SparkSessionJob with NamedObjectSupport {
32+
33+
import Treatments._
34+
35+
type JobData = Treatments.JobData
36+
type JobOutput = collection.Map[String, Any]
37+
38+
override def validate(sparkSession: SparkSession,
39+
runtime: JobEnvironment,
40+
config: Config): JobData Or Every[ValidationProblem] = {
41+
42+
val version = validVersion(config)
43+
val db = getDB(runtime)
44+
val flatDb = getFlatDB(runtime)
45+
val genes = getGenes(runtime)
46+
47+
val compoundQuery = paramCompoundQ(config)
48+
val limit = optParamLimit(config)
49+
val trtType = optParamTrtType(config)
50+
val like = optParamLike(config)
51+
52+
val cachedData = withGood(db, flatDb, genes) { CachedData(_, _, _) }
53+
val specificData = withGood(compoundQuery) { SpecificData(_, limit, like, trtType) }
54+
55+
withGood(version, cachedData, specificData) { JobData(_, _, _) }
56+
57+
}
58+
59+
override def runJob(sparkSession: SparkSession,
60+
runtime: JobEnvironment,
61+
data: JobData): JobOutput = {
62+
63+
implicit val thisSession = sparkSession
64+
65+
Map(
66+
"info" -> Treatments.infoMsg,
67+
"header" -> Treatments.header(data),
68+
"data" -> Treatments.result(data)
69+
)
70+
71+
}
72+
73+
}

0 commit comments

Comments
 (0)