Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sollier committed Jun 13, 2024
1 parent a2566f2 commit 9b0007e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions figeno/track_copynumber.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyBigWig
import os
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.collections import PatchCollection
Expand Down Expand Up @@ -71,7 +71,9 @@ def __init__(self,input_type=None,freec_ratios=None,freec_CNAs=None,CNAs=None,pu
self.df_ratios=None
if self.input_type=="freec":
if self.freec_ratios is not None:
self.df_ratios = pd.read_csv(self.freec_ratios,sep="\t",dtype={"Chromosome":str,"Start":float})
try:
self.df_ratios = pd.read_csv(self.freec_ratios,sep="\t",dtype={"Chromosome":str,"Start":float})
except: raise KnownException("Failed to open file "+str(self.freec_ratios))
if (not "Chromosome" in self.df_ratios.columns) or (not "Start" in self.df_ratios.columns) or (not "Ratio" in self.df_ratios.columns):
raise KnownException("Invalid format for the freec ratios file. Must be tab-separated with 3 columns (with header): "\
"Chromosome, Start, Ratio.")
Expand All @@ -95,7 +97,10 @@ def __init__(self,input_type=None,freec_ratios=None,freec_CNAs=None,CNAs=None,pu

elif self.input_type=="delly":
if self.delly_cn is not None:
self.df_ratios = pd.read_csv(self.delly_cn,sep="\t",dtype={"chr":str,"start":int,"end":int})
try:
self.df_ratios = pd.read_csv(self.delly_cn,sep="\t",dtype={"chr":str,"start":int,"end":int})
except:
raise KnownException("Failed to open file "+str(self.delly_cn))
if len(self.df_ratios.columns)!=6: raise KnownException("Expected 6 columns for the delly copy number file, but found "+str(len(self.df_ratios.columns))+".")
self.df_ratios=self.df_ratios.iloc[:,[0,1,5]]
self.df_ratios.columns=["Chromosome","Start","Ratio"]
Expand Down Expand Up @@ -341,6 +346,7 @@ def compute_min_max_cn(self,regions):

def read_cna_freec(cna_freec_filename):
CNAs={}
if not os.path.exists(cna_freec_filename): raise KnownException("CNA file does not exist: "+str(cna_freec_filename))
with open(cna_freec_filename,"r") as infile:
for line in infile:
linesplit = line.rstrip("\n").split("\t")
Expand All @@ -354,6 +360,7 @@ def read_cna_freec(cna_freec_filename):

def read_cna_delly(cna_delly_filename):
CNAs={}
if not os.path.exists(cna_delly_filename): raise KnownException("CNA file does not exist: "+str(cna_delly_filename))
with open(cna_delly_filename,"r") as infile:
for line in infile:
linesplit = line.rstrip("\n").split("\t")
Expand Down

0 comments on commit 9b0007e

Please sign in to comment.