-
Notifications
You must be signed in to change notification settings - Fork 3
multiplierz.mzReport
mzReport is an interface to multiple formats of tabular data, including the multiplierz-native mzResults database (.mzD) format. It is geared towards interpreting the results of database searches performed through mzSearch, but it is a general-purpose tool that can open any supported file type.
The following formats are supported. In all cases (except .mzD), it is assumed that the first row of the data is a header containing the names of all columns.
- Comma-Separated Value (CSV) files
- Excel .XLSX and .XLS (97-2003) formats.
- Multiplierz Results Database (mzD)
All of mzReport is accessed through two base classes, reader() and writer().
Opens a data file for reading; the reader object is a generator that iterates row-by-row through the file. Each row is returned as a column_name->cell_value dict.
Excel files take an additional sheet_name argument that specifies the sheet to be read; if not specified, mzReport will look for a sheet named 'Data' (which will, in a standard mzSearch result file, contain the PSM data) and otherwise emit a warning.
Methods/attributes:
-
columns: A list of the column header titles in order. -
.close(): Closes the file.
Opens a data file for writing. In addition to the file path, a list of columns must be specified. All rows written into the file must be dicts with keys corresponding to the specified columns.
Methods/attributes:
-
write(row) : Writes a row to the file. -
.close(): Closes the file; in some formats (notably Excel) the file is not fully written until this is called!
from multiplierz.mzReport import reader, writer
rdr = reader(r'C:\Users\Max\Desktop\Projects\example_input.xlsx')
wtr = writer(r'C:\Users\Max\Desktop\Projects\example_output.mzD',
columns = rdr.columns + ['Row Number'])
i = 0
for row in rdr:
i += 1
row['Row Number'] = i
wtr.write(row)
wtr.close()
rdr.close()