sfftk.formats package

AmiraMesh format

sfftk.formats.am

User-facing reader classes for AmiraMesh files

class sfftk.formats.am.AmiraMeshAnnotation(material)[source]

Bases: Annotation

Annotation class

property colour

Segment colour

Colour may or may not exist. Return None if it doesn’t and the caller will determine what to do

convert(**kwargs)[source]

Convert to sfftkrw.SFFBiologicalAnnotation object

property description

Segment description

property name

Segment name

class sfftk.formats.am.AmiraMeshHeader(header)[source]

Bases: object

Class defining the header of an AmiraMesh segmentation file

convert(**kwargs)[source]

Convert an AmiraMeshHeader object into an EMDB-SFF segmentation header

Currently empty

class sfftk.formats.am.AmiraMeshMesh[source]

Bases: object

Mesh class

convert(**kwargs)[source]

Convert to sfftkrw.SFFMesh object

property triangles

Triangles in mesh

property vertices

Vertices in mesh

class sfftk.formats.am.AmiraMeshSegment(fn, header, segment_id)[source]

Bases: Segment

Segment class

property annotation

Segment annotation

convert(**kwargs)[source]

Convert to sfftkrw.SFFSegment object

property material

Material may or may not exist. Return None if it doesn’t and the caller will determine what to do

property volume

The segmentation as a volume

class sfftk.formats.am.AmiraMeshSegmentation(fn, *args, **kwargs)[source]

Bases: Segmentation

Class representing an AmiraMesh segmentation

from sfftk.formats.am import AmiraMeshSegmentation
am_seg = AmiraMeshSegmentation('file.am')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The AmiraMesh header obtained using the ahds package

The header is wrapped with a generic ahds.header class

property segments

Segments in this segmentation

class sfftk.formats.am.AmiraMeshVolume(fn, header)[source]

Bases: object

Class defining the 3D volume of an AmiraMesh segmentation file

Parameters:
convert(**kwargs)[source]

Convert to sfftkrw.SFFThreeDVolume object

SuRVoS format

sfftk.formats.survos

class sfftk.formats.survos.SuRVoSSegment(segment_id, segmentation)[source]

Bases: Segment

A single SuRVoS segment

convert(name=None, colour=None)[source]

Convert to a sfftkrw.SFFSegment object

property segment_id

As usual, segment IDs start from 1 (not 0)

class sfftk.formats.survos.SuRVoSSegmentation(fn, *args, **kwargs)[source]

Bases: Segmentation

SuRVoS segmentation adapter

from sfftk.formats.survos import SuRVoSSegmentation
am_seg = SuRVoSSegmentation('predictions.h5')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property segments

A list of segments

CCP4 mask format

sfftk.formats.map

User-facing reader classes for CCP4/MRC masks.

There are three classes (one of which will be deprecated beginning in v0.8.0).

1 - :py:class:

class sfftk.formats.map.BinaryMaskSegment(map_obj)[source]

Bases: Segment

Class representing an individual binary mask segment

property annotation

Segment annotation

convert()[source]

Convert to a sfftkrw.SFFSegment object

class sfftk.formats.map.BinaryMaskSegmentation(fns, *args, **kwargs)[source]

Bases: Segmentation

A segmentation consisting of one or more binary masks

Warning

Results in large files

This class works by compiling a set of binary masks into a single file. The resulting file is much smaller than the original individual masks combined at the expense of the compute time required to zip and base64-encode the volume data.

Users are strongly encouraged to first merge all binary masks into a single mask using the Merging Masks then using the sfftk.formats.map.MergedMaskSegmentation class instead of this one.

from sfftk.formats.map import BinaryMaskSegmentation
map_seg = BinaryMaskSegmentation('binary_mask.mrc')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The header is all the data from the CCP4/MRC header

property segments

An iterable of segments

class sfftk.formats.map.MapAnnotation(map_obj)[source]

Bases: Annotation

Annotation class

property colour

Segment colour

convert()[source]

Convert to a sfftkrw.SFFBiologicalAnnotation object

property description

Segment description (concat all labels)

property name

Segment name (filename since we have a segment per file)

class sfftk.formats.map.MapHeader(segment)[source]

Bases: Header

Class defining the header in a CCP4 file

class sfftk.formats.map.MapSegment(map_obj)[source]

Bases: Segment

Segment class

property annotation

Segment annotation

convert()[source]

Convert to a sfftkrw.SFFSegment object

class sfftk.formats.map.MapSegmentation(fns, *args, **kwargs)[source]

Bases: Segmentation

Class representing an CCP4/MAP mask segmentation

Deprecated since version v0.8.0: For future versions of sfftk, please use the MaskSegmentation class for one or more binary masks and MergedMaskSegmentation from merged masks. See also Merging Masks.

A PendingDeprecationWarning is raised for sfftk earlier than v0.8.0.

from sfftk.formats.map import MapSegmentation
map_seg = MapSegmentation('file.map')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

Segmentation metadata must be exactly as in one segment

property segments

The segments in this segmentation

class sfftk.formats.map.MaskAnnotation(map_obj, name=None)[source]

Bases: Annotation

Class representing annotation for individual segments

property colour

Segment colour

convert()[source]

Convert to a sfftkrw.SFFBiologicalAnnotation object

property description

Segment description (concat all labels)

property name

Segment name (filename since we have a segment per file)

class sfftk.formats.map.MaskHeader(map_obj)[source]

Bases: Header

Class representing mask header

class sfftk.formats.map.MergedMaskSegment(label, parent_label, map_obj, name=None)[source]

Bases: Segment

Class representing an individual segment from a merged mask

property annotation

Segment annotation

convert()[source]

Convert to a sfftkrw.SFFSegment object

class sfftk.formats.map.MergedMaskSegmentation(fn, label_tree='merged_mask.json')[source]

Bases: Segmentation

A segmentation constructed from a merged mask derived from multiple binary masks

from sfftk.formats.map import MergedMaskSegmentation
map_seg = MergedMaskSegmentation('merged_mask.mrc', label_tree='merged_mask.json')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The header is all the data from the CCP4/MRC header

property segments

An iterable of segments

IMOD format

sfftk.formats.mod

User-facing reader classes for IMOD files

class sfftk.formats.mod.IMODAnnotation(header, objt)[source]

Bases: Annotation

Annotation class

property colour

Segment colour

convert()[source]

Convert to sfftkrw.SFFBiologicalAnnotation object

property description

Segment description

class sfftk.formats.mod.IMODEllipsoid(radius, x, y, z)[source]

Bases: object

Class definition fo an ellipsoid shape primitive

convert()[source]

Convert to sfftkrw.SFFEllipsoid object

property radius

Ellipsoid radius

property transform

A (3,4) transformation matrix that locates the shape in the space from the origin

class sfftk.formats.mod.IMODHeader(segmentation)[source]

Bases: Header

Class definition for the header in an IMOD segmentation file

convert(**kwargs)[source]

Convert to an EMDB-SFF segmentation header object

Currently not implemented

class sfftk.formats.mod.IMODMesh(imod_mesh)[source]

Bases: object

Mesh class

convert(**kwargs)[source]

Convert this to an EMDB-SFF object

property normals

The normal vertices defining surface smoothness for shading

property polygons

The polygons constituting this mesh

property triangles

Polygons are triangles

property vertices

The surface vertices defining this mesh’s geometry

class sfftk.formats.mod.IMODMeshes(header, imod_meshes, args=None, *_args, **_kwargs)[source]

Bases: UserList

Container class for IMOD meshes

convert(**kwargs)[source]

Convert the set of meshes for this segment into a container of mesh objects

class sfftk.formats.mod.IMODSegment(header, objt)[source]

Bases: object

Segment class

property annotation

The annotation for this segment

convert()[source]

Convert to sfftkrw.SFFSegment object

property meshes

The meshes in this segment

property shapes

The shapes in this segment

class sfftk.formats.mod.IMODSegmentation(fn, *args, **kwargs)[source]

Bases: Segmentation

Class representing an IMOD segmentation

from sfftk.formats.mod import IMODSegmentation
mod_seg = IMODSegmentation('file.mod')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Method to convert an IMOD file to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property has_mesh_or_shapes

Check whether the segmentation has meshes or shapes

If it only has contours this property is False Do not convert segmentations that only have contours

property header

Header in segmentation

property segments

Segments in segmentation

class sfftk.formats.mod.IMODShapes(header, objt, *args, **kwargs)[source]

Bases: UserList

Container class for shapes

convert()[source]

Convert to sfftkrw.SFFShapePrimitiveList object

Segger format

sfftk.formats.seg

User-facing reader classes for Segger files

class sfftk.formats.seg.SeggerAnnotation(segmentation, region_id)[source]

Bases: Annotation

Annotation class

convert(**kwargs)[source]

Convert to a sfftkrw.SFFBiologicalAnnotation object

class sfftk.formats.seg.SeggerHeader(segmentation)[source]

Bases: Header

Header class

property file_path

The path to the .seg file

property ijk_to_xyz_transform

The image-to-physical transform

property map_path

The path to the original segmented map

property map_size

Map dimensions

property name

The name of segmentation

property parent_ids

All parent IDs

property region_ids

All region IDs

property root_parent_ids

Parent IDs for root segments

property version

The version of Segger used

class sfftk.formats.seg.SeggerSegment(segmentation, region_id)[source]

Bases: Segment

Segment class

convert(**kwargs)[source]

Convert to a sfftkrw.SFFSegment object

class sfftk.formats.seg.SeggerSegmentation(fn, top_level=True, *args, **kwargs)[source]

Bases: Segmentation

Class representing an Segger segmentation

from sfftk.formats.seg import SeggerSegmentation
seg_seg = SeggerSegmentation('file.seg')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Method to convert a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The header for this segmentation

property segments

The segments in this segmentation

class sfftk.formats.seg.SeggerVolume(segmentation)[source]

Bases: Volume

Volume class

convert(**kwargs)[source]

Convert to a sfftkrw.SFFThreeDVolume object

Stereolithography format

sfftk.formats.stl

User-facing reader classes for Stereolithography files

class sfftk.formats.stl.STLAnnotation(name)[source]

Bases: Annotation

Annotation class

convert()[source]

Convert to a sfftkrw.SFFBiologicalAnnotation object

class sfftk.formats.stl.STLHeader(segmentation)[source]

Bases: Header

Class definition for header in an STL segmentation file

convert()[source]

Convert to an EMDB-SFF segmentation header

Currently not implemented

class sfftk.formats.stl.STLMesh(vertices, polygons)[source]

Bases: Mesh

Mesh class

convert()[source]

Convert to a sfftkrw.SFFMesh object

property polygons

Polygons in this mesh

property vertices

Vertices in this mesh

class sfftk.formats.stl.STLSegment(name, vertices, polygons)[source]

Bases: Segment

Segment class

property annotation

Segmentation annotation

convert()[source]

Convert to a sfftkrw.SFFSegment object

property meshes

Segment meshes

property name

Segment name

class sfftk.formats.stl.STLSegmentation(fns, *args, **kwargs)[source]

Bases: Segmentation

Class representing an STL segmentation

from sfftk.formats.stl import STLSegmentation
stl_seg = STLSegmentation('file.stl')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The header in the segmentation

property segments

The segments in the segmentation

Amira HyperSurface format

sfftk.formats.surf

User-facing reader classes for Amira HxSurface files

class sfftk.formats.surf.AmiraHyperSurfaceAnnotation(segment)[source]

Bases: Annotation

Annotation class

property colour

Segment colour

convert()[source]

Convert to a sfftkrw.SFFBiologicalAnnotation object

property name

Segment name

class sfftk.formats.surf.AmiraHyperSurfaceHeader(header)[source]

Bases: Header

Class definition for an AmiraHyperSurface segmentation file

convert()[source]

Convert to an EMDB-SFF segmentation header object

Currently not implemented

class sfftk.formats.surf.AmiraHyperSurfaceMesh(segment)[source]

Bases: Mesh

Mesh class

convert(**kwargs)[source]

Convert to a sfftkrw.SFFMesh object

property polygons

List of (v1, v2, v3) (triangles)

static translate_indexes(triangle_list, lut)[source]

Translate the values of the list of 3-tuples according to the provided look-up table

Is a generator.

Parameters:
  • triangle_list (list) – a list of 3-tuples of integers

  • lut (dict) – a dictionary mapping current to new values

property vertices

Dictionary of vertex_id to (x, y, z)

class sfftk.formats.surf.AmiraHyperSurfaceSegment(segment)[source]

Bases: Segment

Segment class

property annotation

Segment annotation

convert(**kwargs)[source]

Convert to a sfftkrw.SFFSegment object

property id

Segment ID

property meshes

Segment meshes

class sfftk.formats.surf.AmiraHyperSurfaceSegmentation(fn)[source]

Bases: Segmentation

Class representing an AmiraHyperSurface segmentation

from sfftk.formats.surf import AmiraHyperSurfaceSegmentation
surf_seg = AmiraHyperSurfaceSegmentation('file.surf')
convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert to a sfftkrw.SFFSegmentation object

Parameters:
  • name (str) – optional name of the segmentation used in <name/>

  • software_version (str) – optional software version for Amira use in <software><version/></software>

  • processing_details (str) – optional processings used in Amira used in <software><processingDetails/></software>

  • details (str) – optional details associated with this segmentation used in <details/>

  • verbose (bool) – option to determine whether conversion should be verbose

  • transform (numpy.ndarray) – a 3x4 numpy.ndarray for the image-to-physical space transform

property header

The header in the segmentation

property segments

The segments in the segmentation

RELION STAR format

Working with STAR files

STAR files are CIF files. To use STAR files with sfftk, the user needs to provide at least:

  • a STAR file

  • a map file (MRC, REC, MAP, CCP4, etc.)

sff convert <starfile> [--subtomogram-average <mrcfile>] -o <outputfile> [other options]

The presence of the --star flag tells sfftk that what is about to be generated is a refinement model plus transforms.

class sfftk.formats.star.RelionMultiStarSegmentation(fn_list, particle_fn, euler_angle_convention='ZYZ', degrees=True, *_args, **_kwargs)[source]

Bases: Segmentation

convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert the segmentation to an EMDB-SFF segmentation

property header

Return the header

property segments

Return the segments

class sfftk.formats.star.RelionStarHeader(map_obj)[source]

Bases: MaskHeader

Class representing a Relion STAR file header

class sfftk.formats.star.RelionStarSegment(particles: StarTable, euler_angle_convention='ZYZ', degrees=True, verbose=False, name='Particle refined using subtomogram averaging')[source]

Bases: Segment

Class representing a Relion STAR file segment

convert(**kwargs)[source]

Convert the segment to an EMDB-SFF segment

class sfftk.formats.star.RelionStarSegmentation(fn, particle_fn, euler_angle_convention='ZYZ', degrees=True, *_args, **_kwargs)[source]

Bases: Segmentation

Class that represents a Relion STAR file segmentation

convert(name=None, software_version=None, processing_details=None, details=None, verbose=False, transform=None)[source]

Convert the segmentation to an EMDB-SFF segmentation

property header

Return the header

property segments

Return the segments