Skip to content

multiplierz.mzReport

Max Alexander edited this page May 10, 2017 · 1 revision

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.

Supported Formats

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().

multiplierz.mzReport.reader(file_name)

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.

multiplierz.mzReport.writer(file_name, columns)

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!

Example usage:

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()

Clone this wiki locally