From b539d663b48ca9f5671ef7c4990c4fc1e05d8c2a Mon Sep 17 00:00:00 2001 From: Art Eschenlauer Date: Wed, 9 Jun 2021 12:00:39 -0500 Subject: [PATCH 1/2] handle custom polarity column and data matrix upper left hand column --- vkmz/read.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vkmz/read.py b/vkmz/read.py index 113cc7d..ab9cf52 100644 --- a/vkmz/read.py +++ b/vkmz/read.py @@ -230,13 +230,14 @@ def xcmsTabular(sample_file, variable_file, matrix_file): polarity = {} with open(sample_file, "r") as f: sample_data = csv.reader(f, delimiter="\t") - next(sample_data) # skip header + header = next(sample_data) # skip header + polarity_index = header.index("polarity") for row in sample_data: sample = row[0] if POLARITY: polarity[sample] = POLARITY else: - polarity[sample] = polaritySanitizer(row[2]) + polarity[sample] = polaritySanitizer(row[polarity_index]) except IOError: print(f"Error while reading the XCMS tabular file {sample_file}") raise @@ -285,6 +286,9 @@ def xcmsTabular(sample_file, variable_file, matrix_file): with open(matrix_file, "r") as f: matrix_data = csv.reader(f, delimiter="\t") header = next(matrix_data) # list of samples + if header[0] == "": + header[0] = "X" + i = 0 # remove empty columns # required for W4M-XCMS 1.7 # TODO: check W4M-XCMS 3.0 From 2eba095f6121fc938a91647531780c674974fa4d Mon Sep 17 00:00:00 2001 From: Art Eschenlauer Date: Wed, 9 Jun 2021 12:51:58 -0500 Subject: [PATCH 2/2] use column 2 if polarity is not specified in the header --- vkmz/read.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vkmz/read.py b/vkmz/read.py index ab9cf52..0fd907b 100644 --- a/vkmz/read.py +++ b/vkmz/read.py @@ -231,7 +231,10 @@ def xcmsTabular(sample_file, variable_file, matrix_file): with open(sample_file, "r") as f: sample_data = csv.reader(f, delimiter="\t") header = next(sample_data) # skip header - polarity_index = header.index("polarity") + if 'polarity' in header: + polarity_index = header.index("polarity") + else: + polarity_index = 2 for row in sample_data: sample = row[0] if POLARITY: