Skip to content

Commit 70b8606

Browse files
authored
Merge pull request #3 from Ferlab-Ste-Justine/feat/CQDG_257_alt_id
CQDG:257 alt id
2 parents 4bc33e5 + e873385 commit 70b8606

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/main/resources/test.xlsx

7.3 KB
Binary file not shown.

src/main/scala/bio/ferlab/ontology/OntologyTerm.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ case class OntologyTerm(
44
id: String,
55
name: String,
66
parents: Seq[OntologyTerm] = Nil,
7-
is_leaf: Boolean = false
7+
is_leaf: Boolean = false,
8+
alternateIds: Seq[String] = Nil
89
) {
910
override def toString: String = s"$name ($id)"
1011
}

src/main/scala/bio/ferlab/transform/DownloadTransformer.scala

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ object DownloadTransformer {
1515
val patternId = "id: ([A-Z]+:[0-9]+)".r
1616
val patternName = "name: (.*)".r
1717
val patternIsA = "is_a: ([A-Z]+:[0-9]+) (\\{.*})? ?! (.*)".r
18+
val patternAltId = "^alt_id: (HP:[0-9]+|MONDO:[0-9]+)$".r
1819

1920
def using[A](r: BufferedSource)(f: BufferedSource => A): A =
2021
try {
@@ -45,6 +46,12 @@ object DownloadTransformer {
4546
val headOntoCopy = headOnto.copy(parents = headOnto.parents :+ OntologyTerm(id, name, Nil))
4647
headOntoCopy :: current.tail
4748
}
49+
else if (line.matches(patternAltId.regex)) {
50+
val patternAltId(altId) = line
51+
val headOnto = current.head
52+
val headOntoCopy = headOnto.copy(alternateIds = headOnto.alternateIds :+ altId)
53+
headOntoCopy :: current.tail
54+
}
4855
else {
4956
current
5057
}

src/main/scala/bio/ferlab/transform/WriteJson.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ case class OntologyTermOutput (
99
name: String,
1010
parents: Seq[String] = Nil,
1111
ancestors: Seq[BasicOntologyTermOutput] = Nil,
12-
is_leaf: Boolean =false
12+
is_leaf: Boolean =false,
13+
alt_ids: Seq[String] = Nil
1314
) {}
1415

1516
case class BasicOntologyTermOutput (
@@ -31,7 +32,8 @@ object WriteJson {
3132
k.name,
3233
k.parents.map(_.toString),
3334
v._1.map(i => BasicOntologyTermOutput(i.id, i.name, i.parents.map(_.toString))).toSeq,
34-
v._2
35+
v._2,
36+
k.alternateIds
3537
)}.toSeq.toDF().write.mode("overwrite").json(outputDir)
3638
}
3739

0 commit comments

Comments
 (0)