Commit e062f718 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Adding more tables

parent b1191ca3
...@@ -2,41 +2,61 @@ package nl.lumc.sasc.biopet.tools ...@@ -2,41 +2,61 @@ package nl.lumc.sasc.biopet.tools
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.utils.summary.db.{Libraries, Samples}
import slick.driver.H2Driver.api._ import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
import nl.lumc.sasc.biopet.utils.{ConfigUtils, ToolCommand} import nl.lumc.sasc.biopet.utils.{ConfigUtils, ToolCommand}
import scala.concurrent.Await
import scala.concurrent.duration.Duration
/** /**
* Created by pjvanthof on 26/01/2017. * Created by pjvanthof on 26/01/2017.
*/ */
object SummaryToSqlite extends ToolCommand { object SummaryToSqlite extends ToolCommand {
case class Args(inputJson: File = null, case class Args(inputJson: File = null,
outputHdf5: File = null) extends AbstractArgs outputSqlite: File = null,
force: Boolean = false) extends AbstractArgs
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
opt[File]('I', "inputJson") required () maxOccurs 1 valueName "<file>" action { (x, c) => opt[File]('I', "inputJson") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputJson = x) c.copy(inputJson = x)
} text "Input json file" } text "Input json file"
opt[File]('o', "outputHdf5") required () maxOccurs 1 valueName "<file>" action { (x, c) => opt[File]('o', "outputHdf5") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(outputHdf5 = x) c.copy(outputSqlite = x)
} text "Output hdf5 file" } text "Output hdf5 file"
opt[Unit]('f', "force") action { (x, c) =>
c.copy(force = true)
} text "If database already exist it will be moved"
} }
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {
val argsParser = new OptParser val argsParser = new OptParser
val cmdArgs = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException) val cmdArgs = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
logger.info("Start")
val jsonMap = ConfigUtils.fileToConfigMap(cmdArgs.inputJson) val jsonMap = ConfigUtils.fileToConfigMap(cmdArgs.inputJson)
val db = Database.forURL(s"jdbc:sqlite:${cmdArgs.outputHdf5.getAbsolutePath}", driver = "org.sqlite.JDBC") if (cmdArgs.outputSqlite.exists()) {
if (cmdArgs.force) cmdArgs.outputSqlite.delete()
else throw new IllegalArgumentException(s"Db already exist: ${cmdArgs.outputSqlite}")
}
try { val db = Database.forURL(s"jdbc:sqlite:${cmdArgs.outputSqlite.getAbsolutePath}", driver = "org.sqlite.JDBC")
try {
val samples = TableQuery[Samples]
val libraries = TableQuery[Libraries]
val setup = DBIO.seq(
(samples.schema ++ libraries.schema).create
)
val setupFuture = db.run(setup)
Await.result(setupFuture, Duration.Inf)
} finally db.close } finally db.close
logger.info("Done")
} }
} }
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
<version>3.1.1</version> <version>3.1.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.xerial</groupId>
<artifactId>slf4j-nop</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>1.6.4</version> <version>3.16.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>colt</groupId> <groupId>colt</groupId>
......
package nl.lumc.sasc.biopet.utils.summary.db
import java.sql.Blob
import slick.driver.H2Driver.api._
/**
* Created by pjvan_thof on 26-1-17.
*/
class Libraries(tag: Tag) extends Table[(Int, String, Int, Blob)](tag, "Libraries") {
def libraryId = column[Int]("libraryId", O.PrimaryKey) // This is the primary key column
def libraryName = column[String]("libraryName")
def sampleId = column[Int]("sampleId")
def tags = column[Blob]("tags")
// Every table needs a * projection with the same type as the table's type parameter
def * = (libraryId, libraryName, sampleId, tags)
}
\ No newline at end of file
package nl.lumc.sasc.biopet.utils.summary.db
import slick.driver.H2Driver.api._
/**
* Created by pjvanthof on 27/01/2017.
*/
class Pipelines(tag: Tag) extends Table[(Int, String)](tag, "Pipelines") {
def pipelineId = column[Int]("runId", O.PrimaryKey) // This is the primary key column
def pipelineName = column[String]("sampleName")
// Every table needs a * projection with the same type as the table's type parameter
def * = (pipelineId, pipelineName)
}
\ No newline at end of file
package nl.lumc.sasc.biopet.utils.summary.db
import slick.driver.H2Driver.api._
/**
* Created by pjvanthof on 27/01/2017.
*/
class Runs(tag: Tag) extends Table[(Int, String)](tag, "Runs") {
def runId = column[Int]("runId", O.PrimaryKey) // This is the primary key column
def runName = column[String]("sampleName")
// Every table needs a * projection with the same type as the table's type parameter
def * = (runId, runName)
}
\ No newline at end of file
package nl.lumc.sasc.biopet.utils.summary.db package nl.lumc.sasc.biopet.utils.summary.db
import java.sql.Blob
import slick.driver.H2Driver.api._ import slick.driver.H2Driver.api._
/** /**
* Created by pjvan_thof on 26-1-17. * Created by pjvan_thof on 26-1-17.
*/ */
class Samples(tag: Tag) extends Table[(Int, String)](tag, "SUPPLIERS") { class Samples(tag: Tag) extends Table[(Int, String, Blob)](tag, "Samples") {
def sampleId = column[Int]("sampleId", O.PrimaryKey) // This is the primary key column def sampleId = column[Int]("sampleId", O.PrimaryKey) // This is the primary key column
def sampleName = column[String]("sampleName") def sampleName = column[String]("sampleName")
def tags = column[Blob]("tags")
// Every table needs a * projection with the same type as the table's type parameter // Every table needs a * projection with the same type as the table's type parameter
def * = (sampleId, sampleName) def * = (sampleId, sampleName, tags)
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment