Mercurial > repos > pieterlukasse > prims_metabolomics
changeset 5:b1d339e0147e
files in library reader
author | pieter.lukasse@wur.nl |
---|---|
date | Tue, 21 Jan 2014 15:47:39 +0100 |
parents | 80075a4c6543 |
children | eabfda6213ae |
files | match_library.py |
diffstat | 1 files changed, 52 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/match_library.py Fri Jan 17 12:43:05 2014 +0100 +++ b/match_library.py Tue Jan 21 15:47:39 2014 +0100 @@ -17,15 +17,19 @@ GC-column types. Used by the library_lookup.xml tool @param library_file: given library file from which the list of GC-column types is extracted ''' - (data, header) = read_library(library_file) - - if 'columntype' not in header: - raise IOError('Missing columns in ', library_file) - - # Filter data on column type - column_type = header.index("columntype") - amounts_in_list_dict = count_occurrence([row[column_type] for row in data]) - galaxy_output = [(str(a) + "(" + str(b) + ")", a, False) for a, b in amounts_in_list_dict.items()] + if library_file == "": + galaxy_output = [("", "", False)] + else: + (data, header) = read_library(library_file) + + if 'columntype' not in header: + raise IOError('Missing columns in ', library_file) + + # Filter data on column type + column_type = header.index("columntype") + amounts_in_list_dict = count_occurrence([row[column_type] for row in data]) + galaxy_output = [(str(a) + "(" + str(b) + ")", a, False) for a, b in amounts_in_list_dict.items()] + return(galaxy_output) @@ -35,19 +39,23 @@ @param library_file: file containing the database @param column_type_name: column type to filter on ''' - (data, header) = read_library(library_file) - - if ('columntype' not in header or - 'columnphasetype' not in header): - raise IOError('Missing columns in ', library_file) - - column_type = header.index("columntype") - statphase = header.index("columnphasetype") - - # Filter data on colunn type name - statphase_list = [line[statphase] for line in data if line[column_type] == column_type_name] - amounts_in_list_dict = count_occurrence(statphase_list) - galaxy_output = [(str(a) + "(" + str(b) + ")", a, False)for a, b in amounts_in_list_dict.items()] + if library_file == "": + galaxy_output = [("", "", False)] + else: + (data, header) = read_library(library_file) + + if ('columntype' not in header or + 'columnphasetype' not in header): + raise IOError('Missing columns in ', library_file) + + column_type = header.index("columntype") + statphase = header.index("columnphasetype") + + # Filter data on colunn type name + statphase_list = [line[statphase] for line in data if line[column_type] == column_type_name] + amounts_in_list_dict = count_occurrence(statphase_list) + galaxy_output = [(str(a) + "(" + str(b) + ")", a, False)for a, b in amounts_in_list_dict.items()] + return(sorted(galaxy_output)) @@ -58,22 +66,26 @@ @param column_type_name: column type to filter on @param statphase: stationary phase of the column to filter on ''' - (data, header) = read_library(library_file) - - if ('columntype' not in header or - 'columnphasetype' not in header or - 'columnname' not in header): - raise IOError('Missing columns in ', library_file) - - column_type_column = header.index("columntype") - statphase_column = header.index("columnphasetype") - column_name_column = header.index("columnname") - - # Filter data on given column type name and stationary phase - statphase_list = [line[column_name_column] for line in data if line[column_type_column] == column_type_name and - line[statphase_column] == statphase] - amounts_in_list_dict = count_occurrence(statphase_list) - galaxy_output = [(str(a) + "(" + str(b) + ")", a, False)for a, b in amounts_in_list_dict.items()] + if library_file == "": + galaxy_output = [("", "", False)] + else: + (data, header) = read_library(library_file) + + if ('columntype' not in header or + 'columnphasetype' not in header or + 'columnname' not in header): + raise IOError('Missing columns in ', library_file) + + column_type_column = header.index("columntype") + statphase_column = header.index("columnphasetype") + column_name_column = header.index("columnname") + + # Filter data on given column type name and stationary phase + statphase_list = [line[column_name_column] for line in data if line[column_type_column] == column_type_name and + line[statphase_column] == statphase] + amounts_in_list_dict = count_occurrence(statphase_list) + galaxy_output = [(str(a) + "(" + str(b) + ")", a, False)for a, b in amounts_in_list_dict.items()] + return(sorted(galaxy_output)) @@ -98,7 +110,8 @@ ''' files = glob.glob(dir_name + "/*.txt") if len(files) == 0: - raise Exception("Configuration error: no library files found in <galaxy-home-dir>/" + dir_name) + # Configuration error: no library files found in <galaxy-home-dir>/" + dir_name : + galaxy_output = [("Configuration error: no library files found", "", False)] else: galaxy_output = [(str(get_file_name_no_ext(file_name)), str(os.path.abspath(file_name)), False) for file_name in files] return(galaxy_output)