Skip to content

Commit df779e3

Browse files
committed
add tests
1 parent d7f1b17 commit df779e3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/main/scala/com/fulcrumgenomics/fasta/CollectAlternateContigNames.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class CollectAlternateContigNames
216216

217217
// Apply to an existing sequence dictionary if necessary
218218
val dict: SequenceDictionary = existing match {
219-
case None if sortBySequencingRole => SequenceDictionary(metadatas.toSeq:_*)
219+
case None if !sortBySequencingRole => SequenceDictionary(metadatas.toSeq:_*)
220220
case None =>
221221
// Use the user-provided roles, otherwise use all role
222222
val roles = (if (sequenceRoles.nonEmpty) sequenceRoles.toIndexedSeq else SequenceRole.values)

src/test/scala/com/fulcrumgenomics/fasta/CollectAlternateContigNamesTest.scala

+41
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,45 @@ class CollectAlternateContigNamesTest extends UnitSpec {
147147
dict.last.name shouldBe "NC_012920.1"
148148
dict.last.aliases should contain theSameElementsInOrderAs Seq("J01415.2", "chrM")
149149
}
150+
151+
it should "sort by sequencing roles when they all are defined" in {
152+
val output = makeTempFile("test.", ".dict")
153+
val tool = new CollectAlternateContigNames(
154+
input = reportHg19,
155+
output = output,
156+
primary = Column.RefSeqAccession,
157+
alternates = Seq(Column.UcscName),
158+
sequenceRoles = Seq(UnplacedScaffold, UnlocalizedScaffold, AssembledMolecule),
159+
sortBySequencingRole = true
160+
)
161+
executeFgbioTool(tool)
162+
163+
val dict = SequenceDictionary(output)
164+
dict should have length 84
165+
dict.head.name shouldBe "NT_113961.1"
166+
dict.head.aliases should contain theSameElementsInOrderAs Seq("chrUn_gl000211")
167+
dict.last.name shouldBe "NC_012920.1"
168+
dict.last.aliases should contain theSameElementsInOrderAs Seq("chrM")
169+
dict.map(m => m(Column.SequenceRole.tag)).toIndexedSeq.distinct should contain theSameElementsInOrderAs Seq(UnplacedScaffold, UnlocalizedScaffold, AssembledMolecule).map(_.key)
170+
}
171+
172+
it should "sort by sequencing roles when no roles are defined" in {
173+
val output = makeTempFile("test.", ".dict")
174+
val tool = new CollectAlternateContigNames(
175+
input = reportHg19,
176+
output = output,
177+
primary = Column.RefSeqAccession,
178+
alternates = Seq(Column.UcscName),
179+
sortBySequencingRole = true
180+
)
181+
executeFgbioTool(tool)
182+
183+
val dict = SequenceDictionary(output)
184+
dict should have length 93
185+
dict.head.name shouldBe "NC_000001.10"
186+
dict.head.aliases should contain theSameElementsInOrderAs Seq("chr1")
187+
dict.last.name shouldBe "NT_167243.1"
188+
dict.last.aliases should contain theSameElementsInOrderAs Seq("chrUn_gl000249")
189+
dict.map(m => m(Column.SequenceRole.tag)).toIndexedSeq.distinct should contain theSameElementsInOrderAs Seq(AssembledMolecule, AltScaffold, UnlocalizedScaffold, UnplacedScaffold).map(_.key)
190+
}
150191
}

0 commit comments

Comments
 (0)