|
| 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