@@ -142,7 +142,8 @@ class DeepLC():
142142 Make predictions
143143
144144 """
145-
145+ library = {}
146+
146147 def __init__ (self ,
147148 main_path = os .path .dirname (os .path .realpath (__file__ )),
148149 path_model = None ,
@@ -189,7 +190,6 @@ def __init__(self,
189190
190191 self .use_library = use_library
191192 self .write_library = write_library
192- self .library = {}
193193
194194 if self .use_library :
195195 self .read_library ()
@@ -243,7 +243,7 @@ def read_library(self):
243243 for line_num ,line in enumerate (library_file ):
244244 split_line = line .strip ().split ("," )
245245 try :
246- self .library [split_line [0 ]] = float (split_line [1 ])
246+ DeepLC .library [split_line [0 ]] = float (split_line [1 ])
247247 except :
248248 logger .warning (
249249 "Could not use this library entry due to an error: %s" , line
@@ -433,7 +433,7 @@ def make_preds_core(self,
433433 all_mods = [m_name for m_group_name ,m_name in self .model .items ()]
434434
435435 # TODO check if .keys() object is the same as set (or at least for set operations)
436- idents_in_lib = set (self .library .keys ())
436+ idents_in_lib = set (DeepLC .library .keys ())
437437
438438 if self .use_library :
439439 for ident in seq_df ["idents" ]:
@@ -479,6 +479,7 @@ def make_preds_core(self,
479479 cnn_verbose = 0
480480
481481 # If we need to apply deep NN
482+ del self .library
482483 if len (seq_df .index ) > 0 :
483484 if self .cnn_model :
484485 if self .verbose :
@@ -504,6 +505,10 @@ def make_preds_core(self,
504505
505506 ret_preds = []
506507 ret_preds2 = []
508+
509+ self .library = {}
510+ if self .use_library :
511+ self .read_library ()
507512
508513 # If we need to calibrate
509514 if calibrate :
@@ -554,7 +559,7 @@ def make_preds_core(self,
554559 p = list (self .calibration_core (uncal_preds ,self .calibrate_dict [m_name ],self .calibrate_min [m_name ],self .calibrate_max [m_name ]))
555560 ret_preds .append (p )
556561
557- p2 = list (self .calibration_core ([self .library [ri + "|" + m_name ] for ri in rem_idents ],self .calibrate_dict [m_name ],self .calibrate_min [m_name ],self .calibrate_max [m_name ]))
562+ p2 = list (self .calibration_core ([DeepLC .library [ri + "|" + m_name ] for ri in rem_idents ],self .calibrate_dict [m_name ],self .calibrate_min [m_name ],self .calibrate_max [m_name ]))
558563 ret_preds2 .append (p2 )
559564
560565 ret_preds = np .array ([sum (a )/ len (a ) for a in zip (* ret_preds )])
@@ -597,7 +602,7 @@ def make_preds_core(self,
597602
598603 ret_preds = self .calibration_core (uncal_preds ,self .calibrate_dict ,self .calibrate_min ,self .calibrate_max )
599604
600- p2 = list (self .calibration_core ([self .library [ri + "|" + mod_name ] for ri in rem_idents ],self .calibrate_dict ,self .calibrate_min ,self .calibrate_max ))
605+ p2 = list (self .calibration_core ([DeepLC .library [ri + "|" + mod_name ] for ri in rem_idents ],self .calibrate_dict ,self .calibrate_min ,self .calibrate_max ))
601606 ret_preds2 .extend (p2 )
602607 else :
603608 # first get uncalibrated prediction
@@ -649,7 +654,7 @@ def make_preds_core(self,
649654 lib_file .close ()
650655 if self .reload_library : self .read_library ()
651656
652- p2 = [self .library [ri + "|" + m_name ] for ri in rem_idents ]
657+ p2 = [DeepLC .library [ri + "|" + m_name ] for ri in rem_idents ]
653658 ret_preds2 .append (p2 )
654659
655660 ret_preds = np .array ([sum (a )/ len (a ) for a in zip (* ret_preds )])
@@ -677,7 +682,7 @@ def make_preds_core(self,
677682 lib_file .close ()
678683 if self .reload_library : self .read_library ()
679684
680- ret_preds2 = np .array ([self .library [ri + "|" + mod_name ] for ri in rem_idents ])
685+ ret_preds2 = np .array ([DeepLC .library [ri + "|" + mod_name ] for ri in rem_idents ])
681686 elif isinstance (self .model , str ):
682687 # No library write!
683688 mod_name = self .model
@@ -703,7 +708,7 @@ def make_preds_core(self,
703708 lib_file .close ()
704709 if self .reload_library : self .read_library ()
705710
706- ret_preds2 = np .array ([self .library [ri + "|" + mod_name ] for ri in rem_idents ])
711+ ret_preds2 = np .array ([DeepLC .library [ri + "|" + mod_name ] for ri in rem_idents ])
707712 else :
708713 raise DeepLCError ('No CNN model defined.' )
709714 else :
@@ -732,7 +737,7 @@ def make_preds_core(self,
732737 if self .reload_library : self .read_library ()
733738 except :
734739 pass
735- ret_preds2 = [self .library [ri + "|" + mod_name ] for ri in rem_idents ]
740+ ret_preds2 = [DeepLC .library [ri + "|" + mod_name ] for ri in rem_idents ]
736741
737742 else :
738743 # No library write!
0 commit comments