diff --git a/oncodriveclustl/main.py b/oncodriveclustl/main.py index 8d1b771..739478f 100644 --- a/oncodriveclustl/main.py +++ b/oncodriveclustl/main.py @@ -282,7 +282,24 @@ def main(input_file, logger.info('Validated elements with mutations: {}'.format(elem)) logger.info('Total substitution mutations: {}'.format(mut)) if not element_mutations_cutoff: - raise excep.UserInputError('No element found with enough mutations to perform analysis') + logger.warning('No element found with enough mutations to perform analysis. Writing empty results.') + sorted_list_elements = postp.write_element_results( + genome=genome, + results=({}, {}), + directory=output_directory, + file=elements_output_file, + is_gzip=gzip + ) + postp.write_cluster_results( + genome=genome, + results=({}, {}), + directory=output_directory, + file=clusters_output_file, + sorter=sorted_list_elements, + is_gzip=gzip + ) + logger.info('Finished') + return # Signature file_prefix = input_file.split('/')[-1].split('.')[0] diff --git a/oncodriveclustl/utils/postprocessing.py b/oncodriveclustl/utils/postprocessing.py index b87d1a3..a96dbdb 100644 --- a/oncodriveclustl/utils/postprocessing.py +++ b/oncodriveclustl/utils/postprocessing.py @@ -71,6 +71,31 @@ def write_element_results(genome, results, directory, file, is_gzip): 'P_ANALYTICAL', 'P_TOPCLUSTER', 'CGC'] + column_order = ['SYMBOL', + 'ENSID', + 'CGC', + 'CHROMOSOME', + 'STRAND', + 'LENGTH', + 'TOTAL_MUT', + 'CLUSTERED_MUT', + 'CLUSTERS', + 'SIM_CLUSTERS', + 'SCORE', + 'P_EMPIRICAL', + 'Q_EMPIRICAL', + 'P_ANALYTICAL', + 'Q_ANALYTICAL', + 'P_TOPCLUSTER', + 'Q_TOPCLUSTER'] + + if not elements_results: + df = pd.DataFrame(columns=column_order) + if is_gzip is True: + df.to_csv(path_or_buf=file, sep='\t', na_rep='', index=False, compression='gzip') + else: + df.to_csv(path_or_buf=file, sep='\t', na_rep='', index=False) + return [] df = pd.DataFrame(columns=header, index=[i for i in range(len(elements_results))]) @@ -119,23 +144,7 @@ def write_element_results(genome, results, directory, file, is_gzip): df = pd.concat([df_nonempty, df_empty]) # Reorder columns - df = df[['SYMBOL', - 'ENSID', - 'CGC', - 'CHROMOSOME', - 'STRAND', - 'LENGTH', - 'TOTAL_MUT', - 'CLUSTERED_MUT', - 'CLUSTERS', - 'SIM_CLUSTERS', - 'SCORE', - 'P_EMPIRICAL', - 'Q_EMPIRICAL', - 'P_ANALYTICAL', - 'Q_ANALYTICAL', - 'P_TOPCLUSTER', - 'Q_TOPCLUSTER']] + df = df[column_order] # Create a sorted list of elements to order the clusters file df.sort_values(by=['Q_ANALYTICAL', 'P_ANALYTICAL', 'SCORE', 'CGC'],