Skip to content

Commit

Permalink
Merge pull request #3 from Ferlab-Ste-Justine/feat/CQDG_257_alt_id
Browse files Browse the repository at this point in the history
CQDG:257 alt id
  • Loading branch information
adipaul1981 authored Dec 7, 2023
2 parents 4bc33e5 + e873385 commit 70b8606
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Binary file added src/main/resources/test.xlsx
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/scala/bio/ferlab/ontology/OntologyTerm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ case class OntologyTerm(
id: String,
name: String,
parents: Seq[OntologyTerm] = Nil,
is_leaf: Boolean = false
is_leaf: Boolean = false,
alternateIds: Seq[String] = Nil
) {
override def toString: String = s"$name ($id)"
}
7 changes: 7 additions & 0 deletions src/main/scala/bio/ferlab/transform/DownloadTransformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object DownloadTransformer {
val patternId = "id: ([A-Z]+:[0-9]+)".r
val patternName = "name: (.*)".r
val patternIsA = "is_a: ([A-Z]+:[0-9]+) (\\{.*})? ?! (.*)".r
val patternAltId = "^alt_id: (HP:[0-9]+|MONDO:[0-9]+)$".r

def using[A](r: BufferedSource)(f: BufferedSource => A): A =
try {
Expand Down Expand Up @@ -45,6 +46,12 @@ object DownloadTransformer {
val headOntoCopy = headOnto.copy(parents = headOnto.parents :+ OntologyTerm(id, name, Nil))
headOntoCopy :: current.tail
}
else if (line.matches(patternAltId.regex)) {
val patternAltId(altId) = line
val headOnto = current.head
val headOntoCopy = headOnto.copy(alternateIds = headOnto.alternateIds :+ altId)
headOntoCopy :: current.tail
}
else {
current
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/bio/ferlab/transform/WriteJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ case class OntologyTermOutput (
name: String,
parents: Seq[String] = Nil,
ancestors: Seq[BasicOntologyTermOutput] = Nil,
is_leaf: Boolean =false
is_leaf: Boolean =false,
alt_ids: Seq[String] = Nil
) {}

case class BasicOntologyTermOutput (
Expand All @@ -31,7 +32,8 @@ object WriteJson {
k.name,
k.parents.map(_.toString),
v._1.map(i => BasicOntologyTermOutput(i.id, i.name, i.parents.map(_.toString))).toSeq,
v._2
v._2,
k.alternateIds
)}.toSeq.toDF().write.mode("overwrite").json(outputDir)
}

Expand Down

0 comments on commit 70b8606

Please sign in to comment.