2021-10-12 08:11:53 +02:00
|
|
|
package eu.dnetllib.dhp.sx.bio
|
2021-06-24 17:20:00 +02:00
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser
|
2021-10-12 08:11:53 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.Oaf
|
|
|
|
import eu.dnetllib.dhp.sx.bio.BioDBToOAF.ScholixResolved
|
2021-06-24 17:20:00 +02:00
|
|
|
import org.apache.commons.io.IOUtils
|
|
|
|
import org.apache.spark.SparkConf
|
|
|
|
import org.apache.spark.sql.{Encoder, Encoders, SaveMode, SparkSession}
|
|
|
|
import org.slf4j.{Logger, LoggerFactory}
|
|
|
|
|
|
|
|
object SparkTransformBioDatabaseToOAF {
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
|
|
val conf: SparkConf = new SparkConf()
|
|
|
|
val log: Logger = LoggerFactory.getLogger(getClass)
|
2021-06-30 11:09:30 +02:00
|
|
|
val parser = new ArgumentApplicationParser(IOUtils.toString(getClass.getResourceAsStream("/eu/dnetlib/dhp/sx/graph/bio/bio_to_oaf_params.json")))
|
2021-06-24 17:20:00 +02:00
|
|
|
parser.parseArgument(args)
|
|
|
|
val database: String = parser.get("database")
|
|
|
|
log.info("database: {}", database)
|
|
|
|
|
|
|
|
val dbPath: String = parser.get("dbPath")
|
|
|
|
log.info("dbPath: {}", database)
|
|
|
|
val targetPath: String = parser.get("targetPath")
|
|
|
|
log.info("targetPath: {}", database)
|
|
|
|
|
|
|
|
val spark: SparkSession =
|
|
|
|
SparkSession
|
|
|
|
.builder()
|
|
|
|
.config(conf)
|
|
|
|
.appName(getClass.getSimpleName)
|
|
|
|
.master(parser.get("master")).getOrCreate()
|
|
|
|
val sc = spark.sparkContext
|
|
|
|
|
2021-10-12 08:11:53 +02:00
|
|
|
implicit val resultEncoder: Encoder[Oaf] = Encoders.kryo(classOf[Oaf])
|
|
|
|
import spark.implicits._
|
2021-06-24 17:20:00 +02:00
|
|
|
database.toUpperCase() match {
|
|
|
|
case "UNIPROT" =>
|
|
|
|
spark.createDataset(sc.textFile(dbPath).flatMap(i => BioDBToOAF.uniprotToOAF(i))).write.mode(SaveMode.Overwrite).save(targetPath)
|
2021-10-12 08:11:53 +02:00
|
|
|
case "PDB" =>
|
2021-06-24 17:20:00 +02:00
|
|
|
spark.createDataset(sc.textFile(dbPath).flatMap(i => BioDBToOAF.pdbTOOaf(i))).write.mode(SaveMode.Overwrite).save(targetPath)
|
2021-06-28 22:04:22 +02:00
|
|
|
case "SCHOLIX" =>
|
|
|
|
spark.read.load(dbPath).as[ScholixResolved].map(i => BioDBToOAF.scholixResolvedToOAF(i)).write.mode(SaveMode.Overwrite).save(targetPath)
|
2021-10-12 08:11:53 +02:00
|
|
|
case "CROSSREF_LINKS" =>
|
2021-06-29 10:21:23 +02:00
|
|
|
spark.createDataset(sc.textFile(dbPath).map(i => BioDBToOAF.crossrefLinksToOaf(i))).write.mode(SaveMode.Overwrite).save(targetPath)
|
2021-06-24 17:20:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|