-
juergen authored
git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2455 5a81b35b-ba03-0410-adc8-b2c5c5119f08
juergen authoredgit-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2455 5a81b35b-ba03-0410-adc8-b2c5c5119f08
:mod:`~ost.io` - Input and Output of Sequences, Structures and Maps
The io module deals with input and output of :class:`entities <ost.mol.EntityHandle>`, :class:`alignments <ost.seq.AlignmentHandle>`, :class:`sequences <ost.seq.SequenceHandle>`, :class:`images <ost.img.ImageHandle>`. Importers for common file formats containing molecules such as PDB, SDF and CHARMM trajectory files are available. Sequence and alignment file formats such as FASTA and CLUSTALW are supported as well, alongside various image data (e.g. png, dm3) and density map files (e.g. CCP4, MRC).
Molecular Structures
Loading Molecular Structures
The :mod:`~ost.io` modules offers several ways to load molecular structures depending on your requirements. The most general way is offered by :func:`~ost.io.LoadEntity`, which will automatically detect the file format based on the file extension.
Some of the formats have a dedicated function that allows you to tweak many parameters that affect the import. PDB files can be loaded with :func:`~ost.io.LoadPDB`. It offers a tighter control over the exact loading behaviour.
Saving Molecular Structures
Saving a complete entity or a view is a matter of calling :func:`~ost.io.SaveEntity`.
ent=io.LoadEntity('protein.pdb')
# save full entity
io.SaveEntity(ent, 'full.pdb')
# only save C-alpha atoms
io.SaveEntity(ent.Select('aname=CA and peptide=true'), 'calpha.pdb')
:func:`~ost.io.SavePDB` provides a simple way to save several entities into one file:
ent=io.LoadEntity('protein.pdb')
# Save complete entity
io.SavePDB(ent, 'full.pdb')
# Save chain A and chain B separately
io.SavePDB([ent.Select('cname=A'), ent.Select('cname=B')], 'split.pdb')
Sequences and Alignments
Loading sequence or alignment files
For a list of file formats supported by :func:`LoadSequence` see :doc:`formats`.
raises: :exc:`~ost.io.IOUnknownFormatException` if the format string supplied is not recognized or the file format can not be detected based on the file extension
:exc:`~ost.io.IOException` if the import fails due to an erroneous or inexistent file
Saving Sequence Data
Saving sequence data is performed by calling :func:`SaveSequence`. For files with non-standard extensions, the format can be set explicitly specifying the 'format' parameter.
# recognizes FASTA file by file extension io.SaveSequence(myseq,'seq.fasta') # for saving a SequenceList io.SaveSequenceList(seqlist,'seqlist.fasta') # or multiple aligned fasta files io.SaveAlignment(aln,'algnm.aln',format="clustal")
For a list of file formats supported by :func:`SaveSequence` see :doc:`formats`.
raises: :exc:`~ost.io.IOUnknownFormatException` if the format string supplied is not recognized or the file format can not be detected based on the file extension
:exc:`~ost.io.IOException` if the import fails due to an erroneous or inexistent file