1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-02-06 11:41:52 +00:00
freebsd-ports/biology/haplohseq/files/patch-src_FreqPhase.cpp
Jason W. Bacon eb0d9154a7 biology/haplohseq: Resurrect and fix python2 dependency
Move upstream to Github fork
2021-01-14 15:51:19 +00:00

30 lines
886 B
C++

--- src/FreqPhase.cpp.orig 2019-11-13 14:19:06 UTC
+++ src/FreqPhase.cpp
@@ -5,6 +5,7 @@
* Email: sanlucas@gmail.com
*/
+#include <sysexits.h>
#include "FreqPhase.h"
namespace haplohseq {
@@ -180,10 +181,17 @@ double FreqPhase::meanValue(const std::v
double FreqPhase::medianValue(const std::vector<double>& values) {
double median;
size_t size = values.size();
+
+ // We can probably detect this condition earlier while loading the VCF
+ if ( size == 0 ) {
+ std::cerr << "FreqPhase::medianValue(): values vector is empty." << std::endl;
+ std::cerr << "Make sure your VCF has all of GT:AD:DP in the FORMAT column." << std::endl;
+ exit(EX_DATAERR);
+ }
std::vector<double> tempFreqs(values);
sort(tempFreqs.begin(), tempFreqs.end());
- if (size % 2 == 0) {
+ if (size % 2 == 0) {
median = (tempFreqs[size / 2 - 1] + tempFreqs[size / 2]) / 2;
}
else {