Skip to content

Commit 4e97f65

Browse files
committed
Investigating issues with loading extended data
1 parent f906a11 commit 4e97f65

7 files changed

Lines changed: 51 additions & 35 deletions

File tree

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Dependencies._
33
Global / onChangedBuildSource := ReloadOnSourceChanges
44
Laika / sourceDirectories := Seq(baseDirectory.value / "docs")
55

6-
ThisBuild / scalaVersion := "3.7.1"
6+
ThisBuild / scalaVersion := "3.7.3"
77
ThisBuild / organization := "org.fathomnet"
88
ThisBuild / organizationName := "MBARI"
99
ThisBuild / startYear := Some(2021)

project/Dependencies.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ import sbt._
22

33
object Dependencies {
44

5-
private val circeVersion = "0.14.14"
5+
private val circeVersion = "0.14.15"
66
lazy val circeCore = "io.circe" %% "circe-core" % circeVersion
77
lazy val circeGeneric = "io.circe" %% "circe-generic" % circeVersion
88
lazy val circeParser = "io.circe" %% "circe-parser" % circeVersion
99

1010
lazy val jansi = "org.fusesource.jansi" % "jansi" % "2.4.2"
1111

12-
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.5.18"
12+
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.5.19"
1313
lazy val methanol = "com.github.mizosoft.methanol" % "methanol" % "1.8.3"
1414
lazy val munit = "org.scalameta" %% "munit" % "1.1.1"
1515
lazy val picocli = "info.picocli" % "picocli" % "4.7.7"
1616

1717
lazy val slf4jJdk = "org.slf4j" % "slf4j-jdk-platform-logging" % "2.0.17"
1818

19-
private val tapirVersion = "1.11.35"
19+
private val tapirVersion = "1.11.48"
2020
lazy val tapirStubServer = "com.softwaremill.sttp.tapir" %% "tapir-sttp-stub-server" % tapirVersion
2121
lazy val tapirSwagger = "com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion
2222
lazy val tapirCirce = "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion
2323
lazy val tapirCirceClient = "com.softwaremill.sttp.client3" %% "circe" % "3.11.0"
2424
lazy val tapirNetty = "com.softwaremill.sttp.tapir" %% "tapir-netty-server" % tapirVersion
2525
lazy val tapirVertx = "com.softwaremill.sttp.tapir" %% "tapir-vertx-server" % tapirVersion
2626

27-
lazy val typesafeConfig = "com.typesafe" % "config" % "1.4.3"
28-
lazy val zio = "dev.zio" %% "zio" % "2.1.19"
27+
lazy val typesafeConfig = "com.typesafe" % "config" % "1.4.5"
28+
lazy val zio = "dev.zio" %% "zio" % "2.1.21"
2929

3030
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.11.2
1+
sbt.version=1.11.7

src/main/scala/org/fathomnet/worms/Main.scala

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import org.fathomnet.worms.etc.jdk.CustomExecutors
1313
import org.fathomnet.worms.etc.jdk.CustomExecutors.*
1414
import org.fathomnet.worms.etc.jdk.Logging.given
1515
import org.fathomnet.worms.io.WormsLoader
16+
17+
import scala.util.control.NonFatal
1618
// import org.fathomnet.worms.io.extended.CombineTrees.combine
1719
import org.fathomnet.worms.io.extended.{CombineTrees, ExtendedLoader}
1820
import picocli.CommandLine
@@ -129,13 +131,20 @@ object Main:
129131
val (wormsConcepts, rootOpt) = WormsLoader.load(wormsDir)
130132
val newRoot = rootOpt.map { root =>
131133
if (treeFiles.nonEmpty)
132-
// Our new base. We use 0 as aphiaId so that the real aphiaIds are not incremented when the trees are combined
133-
val newRoot = WormsNode("object", "", 0L, 0L, Nil, Nil)
134-
val newBranches = treeFiles.flatMap(ExtendedLoader.load(_)).toSeq
135-
val trees = root +: newBranches
136-
val combinedRoot = CombineTrees.combine(newRoot, trees, root.maxAphiaId)
137-
// We need to reset the aphiaId to -1 so that it's obivious that the root is not a real aphiaId
138-
combinedRoot.copy(aphiaId = -1L)
134+
try {
135+
// Our new base. We use 0 as aphiaId so that the real aphiaIds are not incremented when the trees are combined
136+
val newRoot = WormsNode("object", "", 0L, 0L, Nil, Nil)
137+
val newBranches = treeFiles.flatMap(ExtendedLoader.load).toSeq
138+
val trees = root +: newBranches
139+
val combinedRoot = CombineTrees.combine(newRoot, trees, root.maxAphiaId)
140+
// We need to reset the aphiaId to -1 so that it's obivious that the root is not a real aphiaId
141+
combinedRoot.copy(aphiaId = -1L)
142+
}
143+
catch {
144+
case NonFatal(e) =>
145+
log.atWarn.withCause(e).log("Error combining trees from " + treeFiles.mkString(", "))
146+
root
147+
}
139148
else root
140149
}
141150
(wormsConcepts, newRoot)

src/main/scala/org/fathomnet/worms/io/MutableWormsNode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object MutableWormsNodeBuilder:
4343
do parentNode.children.append(conceptNode)
4444
// In worms, the root node has an aphiaId of 1
4545
val minAphiaId = wormsConcepts.map(_.id).min
46-
map.get(minAphiaId).get
46+
map(minAphiaId)
4747

4848
/**
4949
* Given the full tree, return only the animalia node

src/main/scala/org/fathomnet/worms/io/extended/ExtendedLoader.scala

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.fathomnet.worms.io.{MutableWormsNodeBuilder, WormsConcept, WormsConce
1111
import org.fathomnet.worms.{WormsNode, WormsNodeBuilder}
1212

1313
import java.nio.file.Path
14-
import scala.util.Using
14+
import scala.util.{Failure, Success, Try, Using}
1515
import scala.util.control.NonFatal
1616

1717
object ExtendedLoader:
@@ -39,17 +39,22 @@ object ExtendedLoader:
3939
* @return
4040
*/
4141
def load(extendedFile: Path): Option[WormsNode] =
42-
val wormsConcepts = read(extendedFile.toString)
43-
val tree = MutableWormsNodeBuilder.buildTree(wormsConcepts)
44-
Option(WormsNodeBuilder.from(tree))
42+
Try {
43+
val wormsConcepts = read(extendedFile.toString)
44+
val tree = MutableWormsNodeBuilder.buildTree(wormsConcepts)
45+
Option(WormsNodeBuilder.from(tree))
46+
} match
47+
case Success(s) => s
48+
case Failure(exception) =>
49+
log.atError.withCause(exception).log(s"Failed to load extended file: $extendedFile")
50+
None
4551

4652
def read(file: String): Seq[WormsConcept] =
47-
val t = Using(scala.io.Source.fromFile(file)) { source =>
53+
Using(scala.io.Source.fromFile(file)) { source =>
4854
source.getLines().flatMap(from).toSeq
49-
}
50-
t match
51-
case scala.util.Success(s) => s
52-
case scala.util.Failure(e) =>
55+
} match
56+
case Success(s) => s
57+
case Failure(e) =>
5358
log.atError.withCause(e).log(s"Failed to read file: $file")
5459
Seq.empty
5560

src/main/scala/org/fathomnet/worms/io/model.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package org.fathomnet.worms.io
88

99
import scala.io.Source
10-
import scala.util.Try
10+
import scala.util.{Success, Try, Using}
1111

1212
/*
1313
* This file contains code to read the 3 relevant files from the Worms
@@ -20,12 +20,14 @@ import scala.util.Try
2020
def taxonIDToKey(taxonID: String): Long =
2121
taxonID.split(":").last.toLong
2222

23-
def readFile[A](file: String, rowMapper: String => Option[A]): List[A] =
24-
Source
25-
.fromFile(file)
26-
.getLines
27-
.flatMap(rowMapper)
28-
.toList
23+
def readFile[A](file: String, rowMapper: String => Option[A]): List[A] = {
24+
Using(Source.fromFile(file)) { source =>
25+
source.getLines().flatMap(rowMapper).toList
26+
} match
27+
case Success(list) => list
28+
case _ => List.empty[A]
29+
30+
}
2931

3032
final case class Taxon(
3133
taxonID: String,
@@ -34,9 +36,9 @@ final case class Taxon(
3436
rank: String,
3537
acceptedNameUsageID: Option[String]
3638
):
37-
val id = taxonIDToKey(taxonID)
38-
val parentId = parentNameUsageID.map(taxonIDToKey)
39-
val acceptedId = acceptedNameUsageID.map(taxonIDToKey)
39+
val id: Long = taxonIDToKey(taxonID)
40+
val parentId: Option[Long] = parentNameUsageID.map(taxonIDToKey)
41+
val acceptedId: Option[Long] = acceptedNameUsageID.map(taxonIDToKey)
4042

4143
object Taxon:
4244
def from(row: String): Option[Taxon] =
@@ -72,7 +74,7 @@ final case class SpeciesProfile(
7274
isExtinct: Option[Boolean],
7375
isBrackish: Option[Boolean]
7476
):
75-
val id = taxonIDToKey(taxonID)
77+
val id: Long = taxonIDToKey(taxonID)
7678

7779
object SpeciesProfile:
7880

0 commit comments

Comments
 (0)