From e210bcb9747a99387c942f1d81b4854a929dfbe4 Mon Sep 17 00:00:00 2001 From: Lennart Date: Thu, 30 Jul 2020 12:52:12 +0200 Subject: [PATCH] fixed #58 --- setup.py | 2 +- wisecondorX/include/plotter.R | 10 +++++----- wisecondorX/overall_tools.py | 10 ++++++++-- wisecondorX/predict_output.py | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 8917ba2..6cd90bd 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #! /usr/bin/env python from setuptools import setup, find_packages -version = '1.1.5' +version = '1.1.6' dl_version = 'master' if 'dev' in version else '{}'.format(version) setup( diff --git a/wisecondorX/include/plotter.R b/wisecondorX/include/plotter.R index d8267c7..7f9ffe1 100644 --- a/wisecondorX/include/plotter.R +++ b/wisecondorX/include/plotter.R @@ -168,12 +168,12 @@ for (ab in input$results_c){ dot.cols[start:end] = color.C } } else { - if (z < -zcutoff){ - dot.cols[start:end] = color.B - } - if (z > zcutoff){ - dot.cols[start:end] = color.C + if (is.na(z)){ + dot.cols[start:end] = 'grey' + next } + if (z < -zcutoff) dot.cols[start:end] = color.B + if (z > zcutoff) dot.cols[start:end] = color.C } } diff --git a/wisecondorX/overall_tools.py b/wisecondorX/overall_tools.py index ef9392c..7579295 100644 --- a/wisecondorX/overall_tools.py +++ b/wisecondorX/overall_tools.py @@ -5,6 +5,7 @@ import os import subprocess import sys +import math import numpy as np @@ -69,7 +70,6 @@ def exec_R(json_dict): except subprocess.CalledProcessError as e: logging.critical('Rscript failed: {}'.format(e)) sys.exit() - os.remove(json_dict['infile']) if 'outfile' in json_dict.keys(): json_out = json.load(open(json_dict['outfile'])) @@ -89,13 +89,19 @@ def get_z_score(results_c, results): segment_nr = results_nr[segment[0]][segment[1]:segment[2]] segment_rr = results_r[segment[0]][segment[1]:segment[2]] segment_nr = [segment_nr[i] for i in range(len(segment_nr)) if segment_rr[i] != 0] + for i in range(len(segment_nr)): + for ii in range(len(segment_nr[i])): + if not np.isfinite(segment_nr[i][ii]): + segment_nr[i][ii] = np.nan segment_w = results_w[segment[0]][segment[1]:segment[2]] segment_w = [segment_w[i] for i in range(len(segment_w)) if segment_rr[i] != 0] - null_segments = [np.ma.average(x, weights=segment_w) for x in np.transpose(segment_nr)] + null_segments = [np.ma.average(np.ma.masked_array(x, np.isnan(x)), weights=segment_w) for x in np.transpose(segment_nr)] null_mean = np.ma.mean([x for x in null_segments if np.isfinite(x)]) null_sd = np.ma.std([x for x in null_segments if np.isfinite(x)]) z = (segment[3] - null_mean) / null_sd z = min(z, 1000) ; z = max(z, -1000) + if math.isnan(null_mean) or math.isnan(null_sd): + z = 'NaN' zs.append(z) return zs diff --git a/wisecondorX/predict_output.py b/wisecondorX/predict_output.py index 328b758..89f213d 100644 --- a/wisecondorX/predict_output.py +++ b/wisecondorX/predict_output.py @@ -97,6 +97,8 @@ def _generate_segments_and_aberrations_bed(rem_input, results): abberations_file.write('{}\tgain\n'.format('\t'.join([str(x) for x in row]))) elif float(segment[4]) < __get_aberration_cutoff(rem_input['args'].beta, ploidy)[0]: abberations_file.write('{}\tloss\n'.format('\t'.join([str(x) for x in row]))) + elif isinstance(segment[3], str): + continue else: if float(segment[3]) > rem_input['args'].zscore: abberations_file.write('{}\tgain\n'.format('\t'.join([str(x) for x in row])))