def __output_files_exist_with_current_output_basename(self): b_files_exist=False ls_files=pgut.get_list_files_and_dirs_from_glob( self.__output.basename + "*" ) if len( ls_files ) != 0: b_files_exist=True #end if len not zero return b_files_exist
def __params_look_valid( self, b_show_message=False ): ''' As of 2016_08_09, this is rudimentary validation. May need to be more fine-grained checking, as users encounter problem using the interface. ''' b_valid=True s_base_msg="The program is not ready for Ne estimation. " \ + "Please note the invalid parameter values:\n\n" ls_bad_filenames=self.__get_list_bad_genepop_file_names() ls_invalidity_messages=[] ''' Should collect all errors and present all to user at once, but for now will just abort on the first encountered invalid param. ''' BULLET="**" if len( ls_bad_filenames ) > 0: ls_invalidity_messages.append( BULLET + "Genepop files:\n" \ + "\n".join( [ s_name for s_name in ls_bad_filenames ] ) ) b_valid=False #end if one or more bad file names s_seperator=pgut.get_separator_character_for_current_os() s_current_output_dir=self.__output_directory.get() s_dir_and_basename=s_seperator.join( [ s_current_output_dir, self.output_base_name ] ) ls_existing_outfiles=pgut.get_list_files_and_dirs_from_glob( \ s_dir_and_basename + "*" ) if len( ls_existing_outfiles ) > 0: ls_invalidity_messages.append( \ BULLET + "Files matching the output " \ + "directory and basename already exist.\n" \ + "Please rename either the existing files " \ + "or the basename/directory params. " \ + "Existing files: " \ + "\n".join( ls_existing_outfiles ) ) b_valid=False #end if outfiles exist #If one or more of the loaded genepop files #has existing intermiediate files produced #by a pgdriveneestimator.py run, then we want #to abort, since behavior of the NeEstimator given #existing files can cause errors, and intermediate #genepop files may have been (however unlikely) #truncated or mangled in an interrupted run: ls_existing_intermediate_files=self.__get_output_file_names() if len( ls_existing_outfiles ) > 0: ls_invalidity_messages.append( BULLET + "Intermedate files from " \ + "an interrupted run exist:\n" \ + "\n".join( ls_existing_intermediate_files ) + "\nPlease either move/remove the intermediate files " \ + "or load genepop files whose names do not prefix the " + "intermediate files." ) #end if we have existing intermediate files if self.__sampscheme not in ( "percent", "remove" ): ls_invalidity_messages.append( BULLET + "Unknown sample scheme value: " \ + self.__sampscheme + "." ) b_valid=False #end if bad sample scheme if self.__minpopsize < 0: ls_invalidity_messages.append( BULLET + "Minimum population size (must be >= 0). " \ + "Current value: " + str( self.__minpopsize ) + "." ) b_valid=False #end if invalid min pop size if self.__minallelefreq > 1.0 or self.__minallelefreq < 0: ls_invalidity_messages.append( BULLET + "Minimum allele frequence " \ + "value must be > 0.0 and <= 1.0.\n" \ + "Current value: " + str( self.__minallelefreq ) + "." ) b_valid=False #end if invalid min allele freq i_num_cpus=pgut.get_cpu_count() #if no reported cpus, assume 1 if i_num_cpus < 1: i_num_cpus = 1 #end if nu cpus < 1 if self.__processes < 1 or self.__processes > i_num_cpus: ls_invalidity_messages.append( BULLET + "Number of prcesses must be at least 1 and " \ + "no more than " + str( i_num_cpus ) + ". " \ + "Current value: " + str( self.__processes ) + "." ) b_valid=False #end if process total invalid if self.__runmode not in [ "default" ] + pgdn.DebugMode.MODES: ls_invalidity_messages.append( BULLET + "Unknown run mode: " + self.__runmode + "." ) b_valid=False #end if if not b_valid: s_info_msg=s_base_msg + "\n\n".join( ls_invalidity_messages ) PGGUIInfoMessage( self, s_info_msg ) #end if any invalidity return b_valid
def __get_life_table_file_list( self, s_glob_expression ): self.__life_table_files = \ pgut.get_list_files_and_dirs_from_glob( s_glob_expression ) return
def __get_output_file_names( self ): s_path_sep=pgut.get_separator_character_for_current_os() s_output_base_with_path=self.__output_directory.get() \ + s_path_sep \ + self.output_base_name ls_output_file_names=[ s_output_base_with_path + "." \ + pgut.NE_ESTIMATION_MAIN_TABLE_FILE_EXT, s_output_base_with_path + "." \ + pgut.NE_ESTIMATION_SECONDARY_OUTPUT_FILE_EXT ] s_genepop_files=self.__genepopfiles.get() ls_genepop_files=s_genepop_files.split( DELIMITER_GENEPOP_FILES ) for s_genepop_file in ls_genepop_files: for s_tag in pgdn.NE_ESTIMATOR_OUTPUT_FILE_TAGS: s_reformatted_filename = \ self.__convert_genepop_file_to_neestimator_basename ( \ s_genepop_file ) #glob basename plus wildcard, ending #with ne-estimator file tag. (Wildcard #is needed because pgdriveneestimator.py #will have added sample/replicate/popnun fields #to the ouput file basename: s_glob=s_reformatted_filename + "*" + s_tag ls_nefiles=pgut.get_list_files_and_dirs_from_glob( s_glob ) if VERY_VERBOSE: print ( "with glob: " + s_glob ) print ( "got files: " + str( ls_nefiles ) ) #end if very verbose ls_output_file_names += ls_nefiles #end for each NeEstimator file tag #to remove the intermediate genepop file names #(note that this glob, if preceeded by the #reformatted genepop filename, would match #all of the intermediate files, but we keep the #NE_ESTIMATOR_OUTPUT_FILE_TAGS loop in order #to retain that precision, to make it easier #to simply remove this code, to retain the #intermediate genepop files s_glob=s_reformatted_filename + "*" \ + pgdn.GLOB_INTERMEDIATE_GENEPOP_FILE_TAGS ls_intermediate_genepop_files_and_other_matches = \ pgut.get_list_files_and_dirs_from_glob( s_glob ) for s_file in ls_intermediate_genepop_files_and_other_matches: #we only want files not already fetched using the NE_ESTIMATOR_OUTPUT_FILE_TAGS: if s_file not in ls_output_file_names: ls_output_file_names.append( s_file ) #end if new intermediate file (we infer it must be #an intermediate genepop file, if it matches the glob, but was not #already caught using the tags), then add #end for each file matched #end for each genepop file input, make glob for #ne-estimator intermediate output files return ls_output_file_names