nmrglue.table
nmrglue table functions
nmrglue uses numpy records array as stores of various data (peak tables,
trajectories,etc). This module provides functions to read and write records
arrays from disk. Formatting of the numeric values is left to Python’s str
function and only the data type need be specified. In addition this module
contains functions to convert nmrglue’s comments to and from NMRPipe’s
pcomments,pformats lists.
This modules is imported as nmrglue.pipe and can be called as such.
High-Level Functions
These are the functions most users will use from the table module.
-
nmrglue.fileio.table.read(filename)
Read a table (.tbl) file.
Parameters:
- filename Name of table file to read
Returns: (comments,rec)
- comments List of comments (strings terminated with newline)
- rec Records array with named fields.
-
nmrglue.fileio.table.write(filename, comments, rec, overwrite=False)
Write a nmrglue table to file (.tbl).
Parameters:
- filename Name of table file to write.
- comments List of comments (strings terminated with newline).
- rec Records array to write to file.
- overwrite Set True to overwrite file if it exists.
-
nmrglue.fileio.table.insert_row(rec, N, row)
Insert a row into a records array before row number N.
Parameters:
- rec Records array.
- N Row number to insert new row before, integer.
- row Tuple, etc which will be converted into a new row.
Returns: new_rec (new records array with inserted row)
-
nmrglue.fileio.table.append_row(rec, row)
Append a row to the end of a records array
Parameters:
- rec Records array.
- row Tuple, etc which will be converted into a new row.
Returns: new_rec (new records array with appeneded row)
-
nmrglue.fileio.table.delete_row(rec, N)
Delete row N from records array.
Parameters:
- rec Records array.
- N Row number to delete, integer.
Returns: new_rec (new records array with row deleted)
Use reorder_rows to delete multiple rows in a single call.
-
nmrglue.fileio.table.reorder_rows(rec, new_order)
Reorder rows in a records array.
This function can also be used to delete multiple rows from a records
array, only the rows in the new_order list are retained in the new records
array.
Parameters:
- rec Records array.
- new_order List of row indices and order in new records array.
Returns: new_rec (new records array with row reordered)
-
nmrglue.fileio.table.insert_column(rec, N, col, name=None, format=None)
Insert a column into a records array before column number N.
Parameters:
- rec Records array.
- col Array which will be converted into the new column.
- N Number of the column to insert new column before.
- name Name of the column (if Name must be given in col.dtype.names)
- format Data type to convert the new column into before appending.
Returns: new_rec (new records array with column inserted)
-
nmrglue.fileio.table.append_column(rec, col, name=None, format=None)
Append a column to the end of a records array.
Parameters:
- rec Records array.
- col Array which will be converted into the new column.
- name Name of the column (if Name must be given in col.dtype.names)
- format Data type to convert the new column into before appending.
Returns: new_rec (new records array with column appended)
-
nmrglue.fileio.table.delete_column(rec, N)
Delete a column from a records array
Parameters:
- rec Records array.
- N Number of the column to delete.
Returns: new_rec (new records array with column inserted)
-
nmrglue.fileio.table.reorder_columns(rec, new_order)
Reorder columns in a records array
Parameters:
- rec Records array.
- new_order List of column indices to order in new records array.
Returns: new_rec (new records array with columns reordered)
-
nmrglue.fileio.table.pipe2glue(pcomments, pformat, rec)
Convert a NMRPipe table to nmrglue table
Parameters:
- pcomments List of NMRPipe comment lines.
- pformats List of NMRPipe table column formats strings.
- rec Records array with named fields.
Returns: comments,rec
- comments List of comments
- rec Records array with named fields.
-
nmrglue.fileio.table.glue2pipe(comments, rec)
Convert a nmrglue table to a NMRPipe table
The pformats list is a guess from data type and precision in the records
array. You may want to edit this to your liking.
Parameters:
- comments List of comments
- rec Records array with named fields.
Returns: pcomments,pformat,rec
- pcomments List of NMRPipe comment lines.
- pformats List of NMRPipe table column formats strings.
- rec Records array with named fields.
-
nmrglue.fileio.table.guess_pformat(col)
Guess a NMRPipe table column format string given a column
Parameters:
- col Array from records array
Returns string for formatting NMRPipe table