Skip to content

Commit 5c1cdde

Browse files
committed
#3 - updated dependencies
1 parent f769645 commit 5c1cdde

6 files changed

Lines changed: 65 additions & 66 deletions

File tree

project/Dependencies.scala

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

33
object Dependencies {
44

5-
private val circeVersion = "0.14.1"
5+
private val circeVersion = "0.14.5"
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
@@ -18,22 +18,22 @@ object Dependencies {
1818
lazy val jsoniterCore = "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % jsoniterVersion
1919
lazy val jsoniterMacros = "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion
2020

21-
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.4.5"
21+
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.4.7"
2222
lazy val methanol = "com.github.mizosoft.methanol" % "methanol" % "1.7.0"
2323
lazy val munit = "org.scalameta" %% "munit" % "1.0.0-M7"
24-
lazy val picocli = "info.picocli" % "picocli" % "4.7.1"
24+
lazy val picocli = "info.picocli" % "picocli" % "4.7.3"
2525

2626
private val scalatraVersion = "2.8.2"
2727
lazy val scalatra = ("org.scalatra" %% "scalatra" % scalatraVersion).cross(CrossVersion.for3Use2_13)
2828
lazy val scalatraJson = ("org.scalatra" %% "scalatra-json" % scalatraVersion).cross(CrossVersion.for3Use2_13)
2929

30-
lazy val slf4jJdk = "org.slf4j" % "slf4j-jdk-platform-logging" % "2.0.6"
30+
lazy val slf4jJdk = "org.slf4j" % "slf4j-jdk-platform-logging" % "2.0.7"
3131

32-
private val tapirVersion = "1.2.8"
32+
private val tapirVersion = "1.4.0"
3333
lazy val tapirStubServer = "com.softwaremill.sttp.tapir" %% "tapir-sttp-stub-server" % tapirVersion
3434
lazy val tapirSwagger = "com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion
3535
lazy val tapirCirce = "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion
36-
lazy val tapirCirceClient = "com.softwaremill.sttp.client3" %% "circe" % "3.6.2"
36+
lazy val tapirCirceClient = "com.softwaremill.sttp.client3" %% "circe" % "3.8.15"
3737
lazy val tapirNetty = "com.softwaremill.sttp.tapir" %% "tapir-netty-server" % tapirVersion
3838
lazy val tapirVertx = "com.softwaremill.sttp.tapir" %% "tapir-vertx-server" % tapirVersion
3939
// "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
@@ -43,6 +43,6 @@ object Dependencies {
4343

4444

4545
lazy val typesafeConfig = "com.typesafe" % "config" % "1.4.2"
46-
lazy val zio = "dev.zio" %% "zio" % "2.0.6"
46+
lazy val zio = "dev.zio" %% "zio" % "2.0.13"
4747

4848
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.fathomnet.worms.io.extended.CombineTrees.combine
3333
import org.fathomnet.worms.io.extended.CombineTrees
3434
import org.fathomnet.worms.io.extended.ExtendedLoader
3535

36-
3736
@Command(
3837
description = Array("The Worms Server"),
3938
name = "main",
@@ -42,19 +41,24 @@ import org.fathomnet.worms.io.extended.ExtendedLoader
4241
)
4342
class MainRunner extends Callable[Int]:
4443

45-
@Opt(names = Array("-p", "--port"), description = Array("The server port. Default is ${DEFAULT-VALUE}"))
44+
@Opt(
45+
names = Array("-p", "--port"),
46+
description = Array("The server port. Default is ${DEFAULT-VALUE}")
47+
)
4648
private var port: Int = Option(System.getenv("WORMS_PORT")).map(_.toInt).getOrElse(8080)
4749

4850
// "/Users/brian/Downloads/worms"
4951
@Parameters(index = "0", description = Array("Path to the WoRMS data file directory"))
5052
var path: Path = _
5153

52-
@Parameters(index = "1..*",
54+
@Parameters(
55+
index = "1..*",
5356
description = Array(
5457
"Paths to extra tree files (CSV with 3 columns: id, parentId, names). [Optional]",
5558
"These will becombined with the main WoRMS tree. This will create a new root (object)",
5659
"All the nodes from these files will have synthetic aphiaIds with negative values."
57-
))
60+
)
61+
)
5862
var treeFiles: Array[Path] = Array.empty[Path]
5963

6064
override def call(): Int =
@@ -123,15 +127,11 @@ object Main:
123127
WormsLoader.load(wormsDir).map { root =>
124128
if (treeFiles.nonEmpty)
125129
// Our new base. We use 0 as aphiaId so that the real aphiaIds are not incremented when the trees are combined
126-
val newRoot = WormsNode("object", "", 0L, Nil, Nil)
127-
val newBranches = treeFiles.flatMap(ExtendedLoader.load(_)).toSeq
128-
val trees = root +: newBranches
130+
val newRoot = WormsNode("object", "", 0L, Nil, Nil)
131+
val newBranches = treeFiles.flatMap(ExtendedLoader.load(_)).toSeq
132+
val trees = root +: newBranches
129133
val combinedRoot = CombineTrees.combine(newRoot, trees, root.maxAphiaId)
130134
// We need to reset the aphiaId to -1 so that it's obivious that the root is not a real aphiaId
131135
combinedRoot.copy(aphiaId = -1L)
132-
133-
else
134-
root
136+
else root
135137
}
136-
137-

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ object StateController:
140140

141141
def taxaByNameStartingWith(prefix: String): Either[ErrorMsg, List[SimpleWormsNode]] =
142142
def search(data: Data): List[SimpleWormsNode] =
143-
data.names
143+
data
144+
.names
144145
.filter(_.toLowerCase.startsWith(prefix.toLowerCase))
145146
.flatMap(data.findNodeByName)
146147
.map(_.simple)
147148
.toList
148149
runSearch(search)
149-
150-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ final case class WormsNode(
4242
(this.name +: this.alternateNames.sorted).toSeq
4343

4444
/**
45-
* A version of this node with no children
46-
*/
45+
* A version of this node with no children
46+
*/
4747
lazy val simple: SimpleWormsNode = SimpleWormsNode(
4848
name = this.name,
4949
rank = this.rank,

src/main/scala/org/fathomnet/worms/api/TaxaEndpoints.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ class TaxaEndpoints(using ec: ExecutionContext) extends Endpoints:
8989
val taxaChildrenServerEndpoint: ServerEndpoint[Any, Future] =
9090
taxaChildren.serverLogic((name: String) => Future(StateController.childTaxa(name)))
9191

92-
val taxaQueryStartswith: PublicEndpoint[String, ErrorMsg, List[SimpleWormsNode], Any] = baseEndpoint
93-
.get
94-
.in("taxa" / "query" / "startswith")
95-
.in(path[String]("prefix"))
96-
.out(jsonBody[List[SimpleWormsNode]])
97-
.description("Returns a list of taxa that start with the given prefix.")
92+
val taxaQueryStartswith: PublicEndpoint[String, ErrorMsg, List[SimpleWormsNode], Any] =
93+
baseEndpoint
94+
.get
95+
.in("taxa" / "query" / "startswith")
96+
.in(path[String]("prefix"))
97+
.out(jsonBody[List[SimpleWormsNode]])
98+
.description("Returns a list of taxa that start with the given prefix.")
9899

99100
val taxaQueryStartswithEndpoint: ServerEndpoint[Any, Future] =
100-
taxaQueryStartswith.serverLogic((prefix: String) => Future(StateController.taxaByNameStartingWith(prefix)))
101+
taxaQueryStartswith.serverLogic((prefix: String) =>
102+
Future(StateController.taxaByNameStartingWith(prefix))
103+
)
101104

102105
val all: List[ServerEndpoint[Any, Future]] = List(
103106
taxaDescendantsServerEndpoint,

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

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,34 @@ package org.fathomnet.worms.io.extended
88

99
import org.fathomnet.worms.WormsNode
1010

11-
12-
1311
object CombineTrees:
14-
15-
/**
16-
* Combine a sequence of trees into a single tree. It adjust the Aphia IDs of the
17-
* combined tree so that they are unique. The inteneded usage is that the
18-
* rootNode have a low aphiaId (0), then add the WormS tree first.
19-
* Then the worms aphiaId's will not be changed. Ony the subsequent trees will
20-
* have their aphiaId's incremented and then multiplied by -1 so that all fake
21-
* aphiaId's are negative.
22-
*
23-
* @param rootNode The root node of the tree to add the other trees to
24-
* @param trees The trees to add
25-
* @param maxAphiaId The maximum aphiaId of the original WoRMS tree. Only aphiaId's
26-
* greater than this value will be flipped to negative so that they
27-
* are not confused with real aphiaId's.
28-
* @return The combined tree
29-
*/
30-
def combine(rootNode: WormsNode, trees: Seq[WormsNode], maxAphiaId: Long): WormsNode =
12+
13+
/**
14+
* Combine a sequence of trees into a single tree. It adjust the Aphia IDs of the combined tree so
15+
* that they are unique. The inteneded usage is that the rootNode have a low aphiaId (0), then add
16+
* the WormS tree first. Then the worms aphiaId's will not be changed. Ony the subsequent trees
17+
* will have their aphiaId's incremented and then multiplied by -1 so that all fake aphiaId's are
18+
* negative.
19+
*
20+
* @param rootNode
21+
* The root node of the tree to add the other trees to
22+
* @param trees
23+
* The trees to add
24+
* @param maxAphiaId
25+
* The maximum aphiaId of the original WoRMS tree. Only aphiaId's greater than this value will
26+
* be flipped to negative so that they are not confused with real aphiaId's.
27+
* @return
28+
* The combined tree
29+
*/
30+
def combine(rootNode: WormsNode, trees: Seq[WormsNode], maxAphiaId: Long): WormsNode =
3131
var root = rootNode
32-
trees.foreach(t => {
33-
root = add(root, t, root.maxAphiaId)
34-
})
32+
trees.foreach(t => root = add(root, t, root.maxAphiaId))
3533
flipFakeAphiaId(root, maxAphiaId)
3634

37-
def add(rootNode: WormsNode, tree: WormsNode, maxAphiaId: Long): WormsNode =
38-
val node = incrementAphiaId(tree, maxAphiaId)
35+
def add(rootNode: WormsNode, tree: WormsNode, maxAphiaId: Long): WormsNode =
36+
val node = incrementAphiaId(tree, maxAphiaId)
3937
val children = rootNode.children :+ node
4038
rootNode.copy(children = children)
41-
4239

4340
def incrementAphiaId(node: WormsNode, maxAphiaId: Long): WormsNode =
4441
node.copy(
@@ -47,18 +44,18 @@ object CombineTrees:
4744
)
4845

4946
/**
50-
* Flip the aphiaId of all nodes that have aphiaId > maxAphiaId so that
51-
* fake aphiaId's are negative.
52-
*
53-
* @param node The node to flip
54-
* @param maxAphiaId The maximum aphiaId of the original tree
55-
* @return A new tree with fake aphiaId's flipped to negative
56-
*/
47+
* Flip the aphiaId of all nodes that have aphiaId > maxAphiaId so that fake aphiaId's are
48+
* negative.
49+
*
50+
* @param node
51+
* The node to flip
52+
* @param maxAphiaId
53+
* The maximum aphiaId of the original tree
54+
* @return
55+
* A new tree with fake aphiaId's flipped to negative
56+
*/
5757
def flipFakeAphiaId(node: WormsNode, maxAphiaId: Long): WormsNode =
5858
node.copy(
5959
aphiaId = if (node.aphiaId > maxAphiaId) -node.aphiaId else node.aphiaId,
6060
children = node.children.map(n => flipFakeAphiaId(n, maxAphiaId))
6161
)
62-
63-
64-

0 commit comments

Comments
 (0)