I/O package

I/O interface for file reading, writing and conversions

convert(fname_in, format_in, fname_out, format_out, kwargs_in=None, kwargs_out=None)[source]

Convert a file in format x to file in format y

Parameters:
  • fname_in (filehandle, filename) – A file path or open file handle
  • format_in (str) – File format of f_in
  • fname_out (filehandle, filename) – A file path or open file handle
  • format_out (str) – File format of f_out

Examples

  1. Convert a sequence file from A3M format to FASTA format:
>>> from conkit import io
>>> with open('example.a3m', 'r') as f_in, open('example.fas', 'w') as f_out:
...     io.convert(f_in, 'a3m', f_out, 'fasta')

Note

A3M format comes by default WITHOUT insert states, these are removed. To obtain an alignment WITH insert states, use format a3m-inserts.

  1. Convert a PconsC3 contact prediction file to the standard Casp RR format:
>>> from conkit import io
>>> with open('example.out', 'r') as f_in, open('example.rr', 'w') as f_out:
...     io.convert(f_in, 'pconsc3', f_out, 'casprr'))
read(fname, format, f_id='conkit', **kwargs)[source]

Parse a file handle to read into structure

Parameters:
  • fname (filehandle, filename) – A file path or open file handle
  • format (str) – File format of handle
  • f_id (str) – Identifier for the returned file
Returns:

The hierarchy instance of the requested file

Return type:

hierarchy

Examples

  1. Read a Multiple Sequence Alignment file into a ConKit hierarchy:
>>> from conkit import io
>>> with open('example.a3m', 'r') as f_in:
...     hierarchy = io.read(f_in, 'a3m')
  1. Read a contact prediction file into a conkit hierarchy:
>>> from conkit import io
>>> with open('example.mat', 'r') as f_in:
...     hierarchy = io.read(f_in, 'ccmpred')
write(fname, format, hierarchy, **kwargs)[source]

Parse a file handle to read into structure

Parameters:
  • fname (filehandle, filename) – A file path or open file handle
  • format (str) – File format of handle
  • hierarchy – ConKit hierarchy to write

Examples

  1. Write a ConKit hierarchy into a Multiple Sequence Alignment file:
>>> from conkit import io
>>> with open('example.fas', 'r') as f_in, open('example.a3m', 'w') as f_out:
...     hierarchy = io.read(f_in, 'fasta')
...     io.write(f_out, 'a3m', hierarchy)
  1. Write a ConKit hierarchy into a contact prediction file:
>>> from conkit import io
>>> with open('example.txt', 'r') as f_in, open('example.rr', 'w') as f_out:
...     hierarchy = io.read(f_in, 'psicov')
...     io.write(f_out, 'casprr', hierarchy)