Skip to content

Commit

Permalink
Pull request #179: Test for empty input to ovl-cov-stats
Browse files Browse the repository at this point in the history
Merge in SAT/falconc from feature/TAG-4945-empty-stats to develop

* commit 'b07290fc74d6945d5112aca54ac59bca34ec9fa2':
  Stop writing nan for ovl-cov-stats
  Test for input input to ovl-cov-stats
  • Loading branch information
Christopher Dunn committed Jul 7, 2021
2 parents da6c16f + b07290f commit f9d1b56
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion falconc.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "1.13.0"
version = "1.13.1"
author = "Zev Kronenberg"
author = "Christopher Dunn"
description = "C Utilities for bioinformatics"
Expand Down
6 changes: 6 additions & 0 deletions src/falconcpkg/ovl_cov_stats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ proc collect_from_fofn*(in_fn_list: seq[string]): seq[int] =
allCounts.add(counts)
return allCounts

proc standardDeviation(s: RunningStat): float =
if s.n == 0:
return 0.0
else:
return stats.standardDeviation(s)

proc calc_stats*(counts: seq[int]): tuple[mean, stddev, median: float, min, max, n: int] =
var rs: RunningStat
rs.push(counts)
Expand Down
6 changes: 3 additions & 3 deletions tests/t_ovl_cov_stats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ suite "ovl_cov_stats calc_stats":
test "empty input":
let data: seq[int] = @[]
let results = ovl_cov_stats.calc_stats(data)
let expected = (mean: float(0.0), stddev: float(NaN), median: float(0.0), min: 0, max: 0, n: 0)
let expected = (mean: float(0.0), stddev: float(0.0), median: float(0.0), min: 0, max: 0, n: 0)
# If this is not converted to string, tuple comparison fails for some reason.
check $results == $expected

Expand All @@ -48,14 +48,14 @@ suite "ovl_cov_stats calc_stats":
suite "ovl_cov_stats collect_from_stream":
# This implicitly tests the count_overlaps proc.

test "empty input":
test "empty stream":
let inStr = ""
let inStream: Stream = newStringStream(inStr)
let results = ovl_cov_stats.collect_from_stream(inStream)
let expected: seq[int] = @[]
check results == expected

test "empty input":
test "test data 1":
let inStr = testDataCollectFromStream1
let inStream: Stream = newStringStream(inStr)
let results = ovl_cov_stats.collect_from_stream(inStream)
Expand Down
18 changes: 18 additions & 0 deletions tests/t_stats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import falconcpkg/stats
import unittest


let expected_json_on_empty = """{
"sum": 0,
"mean": 0.0,
"median": 0,
"max": 0,
"N100": 0,
"L100": 0,
"N90": 0,
"L90": 0,
"N50": 0,
"L50": 0,
"esize": 0.0
}"""
let expected_json = """{
"sum": 120,
"mean": 40.0,
Expand Down Expand Up @@ -37,3 +50,8 @@ suite "stats":

check stats.to_json(st) == expected_json
check stats.to_table(st) == expected_table
test "calc_stats empty":
let reads = newSeq[int32](0)
let st = stats.calc_stats(reads)

check stats.to_json(st) == expected_json_on_empty

0 comments on commit f9d1b56

Please sign in to comment.