sfftk packages¶
sfftk.readers package¶
amreader¶
Ad hoc reader for AmiraMesh files
-
sfftk.readers.amreader.get_data(fn, *args, **kwargs)¶ Gets data (metadata and segmentation) data from an Amira file
Read EMDB Map (.map) files.
References¶
The following article is useful as it exposes many internals of map files: - ftp://ftp.wwpdb.org/pub/emdb/doc/Map-format/current/EMDB_map_format.pdf
todo:¶
modreader.py¶
Read IMOD model (.mod) files.
.mod files are chunk files and loosely follow the Interchange File Format (IFF). In summary, IFF files consist of a four-byte header (all caps chunk name e.g. ‘IMOD’) followed by an integer of the number of bytes in the chunk. The chunk is then structured according to the author’s design requirements. Not all .mod chunks follow this convention (e.g. ‘OBJT’ chunks do not include the size of the chunk immediately after the chunk ID.
A description of the structure of .mod files can be found at the following URL: http://bio3d.colorado.edu/imod/betaDoc/binspec.html
This module consists of a set of classes each identified by the respective chunk names. The following patterns are observed in the design of these classes:
The name of the class is the name of the chunk e.g. OBJT class refers to OBJT chunks.
All classes have one public method: read(f), which takes a file handle and returns a file handle at the current unread position.
Some chunks are nested (despite the serial nature of IFF files). Contained chunks are read with public methods defined as add_<chunk> e.g. OBJT objects are containers of CONT objects and therefore have a add_cont() method which takes a CONT object as argument. Internally, container objects use dictionaries to store contained objects.
- All chunk classes inherit from ‘object’ class and have the __repr__()
method implemented to print objects of that class.
In addition, there are several useful dictionary constants and functions and classes (flags) that interpret several fields within chunks.
todo¶
- unravel VIEW chunk (email from 3dmod authors unclear)
- list fiels in MESH chunk with -24 markers
- argument parsing DONE
- implementation of MOST, OBST, COST, and MEST...DONE
- empty (no field) implementation of OGRP, SKLI and SLAN (class exists but unclear how to nest it)
Version history¶
- 0.1.0, 2015-10-12, first working version
- 0.1.1, 2015-10-16, clean-up
- 0.1.2, 2015-10-20, implemented commandline arguments (and associated tests)
- 0.1.3, 2015-10-21, implemented MOST, OBST, COST, and MEST (partially) together with a generic STORE class
- 0.1.4, 2015-10-23, added conditions for OGRP, SKLI, and SLAN chunks but unable to test due to lack of data
- 0.1.6, 2016-02-26, documentation with Sphinx
-
class
sfftk.readers.modreader.CLIP_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the CLIP chunk.
-
class
sfftk.readers.modreader.CONTOUR_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the CONT chunk.
-
class
sfftk.readers.modreader.COST_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the COST chunk
-
class
sfftk.readers.modreader.FLAGS(int_value, num_bytes, endian='little')¶ Bases:
objectClass of bit flags.
Parameters: - int_value (int) – the value in base 10
- bytes (int) – the number of bytes to store
- endian (str) – one of little or big
Example usage:
>>> from readers.modreader import FLAGS >>> flag = FLAGS(10, 2) >>> flag 0000000000001010 >>> flag[0] False >>> flag[1] False >>> flag[-1] False >>> flag[-2] True
-
class
sfftk.readers.modreader.IMAT_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the IMAT chunk.
-
class
sfftk.readers.modreader.IMOD(f)¶ Bases:
objectClass encapsulating the data in an IMOD file. The top-level of an IMOD file is an IMOD chunk specifying various data members.
-
read()¶ FIXME: use zscale to fix sizes
-
-
class
sfftk.readers.modreader.MEPA_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the MEPA chunk.
-
class
sfftk.readers.modreader.MESH_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the MESH chunk.
-
class
sfftk.readers.modreader.MINX(f)¶ Bases:
objectModel to image transformation Documented as 72 bytes but works with 76 bytes
-
class
sfftk.readers.modreader.MODEL_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the MODEL chunk.
-
class
sfftk.readers.modreader.MOST(f)¶ Bases:
objectClass encapsulating storage parameters for the top-level
IMOMchunk.
-
class
sfftk.readers.modreader.OBJECT_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the OBJT chunk.
-
class
sfftk.readers.modreader.OBJECT_SYM_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSAdditional flags in the OBJT chunk.
-
class
sfftk.readers.modreader.OBJT(f)¶ Bases:
objectAn IMOD file has several
OBJTchunks, each of which contain the data either as contours (CONT) or meshes (MESH). OBJT chunks also containCLIP,IMAT,MEPAand aOBSTstorage chunk.
-
class
sfftk.readers.modreader.STORE(f)¶ Bases:
objectGeneric storage class for models (MOST), objects (OBST), contours (COST), and meshes (MEST)
-
class
sfftk.readers.modreader.VIEW_FLAGS(*args, **kwargs)¶ Bases:
sfftk.readers.modreader.FLAGSFlags in the VIEW chunk.
-
sfftk.readers.modreader.find_chunk_length(f)¶ Determine the size (in bytes) of the current chunk. Also, return the name of the next chunk.
Assumes that current position in the file is immediately after the chunk header.
Arguments: @param f: file handle
-
sfftk.readers.modreader.get_data(fn)¶ Extract chunks from IMOD model file pointed to by the handle f
Parameters: f – file handle of IMOD model file at start of file
Raises: - ValueError – if it doesn’t start with an IMOD chunk
- ValueError – if the file lacks an IEOF chunk
-
sfftk.readers.modreader.print_model(mod, output)¶ Pretty print the IMOD model
Arguments: @param mod: an object of class IMOD containing all data @param output: the name of the output to which data should be sent
-
sfftk.readers.modreader.show_chunks(fn)¶ Show the sequence and number of chunks pointed to the by file handle f.
Parameters: f – file handle to IMOD model file
-
class
sfftk.readers.segreader.SeggerSegmentation(fn, *args, **kwargs)¶ Bases:
objectEncapsulation of a Segger segmentation
-
descriptions¶ Returns a dictionary of descriptions for each region
-
format¶ Format
-
format_version¶ Format version
-
get_parent_id(region_id)¶ Provides the parent_id given a region_id
-
get_region_ids(parent_id)¶ Provides the regions_ids associated with a parent_id
-
header¶ Collate group-level attributes in a dictionary
-
ijk_to_xyz_transform¶ Image-to-physical space transform
-
map_level¶ Map level (contour level)
-
map_path¶ Path to map file
-
map_size¶ Map dimensions (I, J, K)
-
mask¶ The mask (TM)
-
name¶ Name
-
parent_ids¶ A dictionary of region_ids to parent_ids
-
ref_points¶ A dictionary of region_ids to ref_points
-
region_colours¶ A dictionary of region_ids to region_colors
-
region_ids¶ An iterable of region_ids
-
smoothing_levels¶ A dictionary of region_ids to smoothing_levels
-
-
sfftk.readers.segreader.get_data(fn, *args, **kwargs)¶ Gets segmentation data from a Segger file
-
sfftk.readers.segreader.get_root(region_parent_zip, region_id)¶ Return the penultimate parent_id for any region_id.
Parameters: - region_parent_zip – a list of 2-tuples of region_ids and parent_ids
- region_id – the region_id whose root parent_id is sought
Returns: the corresponding penultimate parent_id (one step below the root - value of 0)
The penultimate parent is one layer below the root (0). The set of penultimate parents are the distinct regions contained in the segmentation. They correspond to putative functional regions.
-
sfftk.readers.stlreader.get_data(fn)¶ Get data from an StL file
Parameters: fn (str) – filename Returns: a generator of meshes; each mesh is a tuple of a name, a dict of vertices indexed by vertex_id and a dict of polygons referring to vertices by vertex_id Return type: tuple
sfftk.readers.surfreader
Copyright 2017 EMBL - European Bioinformatics Institute Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
-
sfftk.readers.surfreader.vertices_for_patches(vertices, patches)¶ Compiles the set of vertices for the list of patches only read from an Amira HyperSurface file
Parameters: - vertices (
ahds.data_stream.VerticesDataStream) – a sequence of vertices - patches (list) – a list of patches each of class
ahds.data_stream.PatchesDataStream
Return dict patches_vertices: the vertices only referenced from this patch
- vertices (
sfftk.formats package¶
User-facing reader classes
-
class
sfftk.formats.am.AmiraMeshSegmentation(fn, *args, **kwargs)¶ Bases:
sfftk.formats.base.SegmentationClass representing an AmiraMesh segmentation
from sfftk.formats.am import AmiraMeshSegmentation am_seg = AmiraMeshSegmentation('file.am')
-
header¶ The AmiraMesh header obtained using the
ahdspackageThe header is wrapped with a generic AmiraMeshHeader class
-
User-facing reader classes
-
class
sfftk.formats.map.MapSegmentation(fn, *args, **kwargs)¶ Bases:
sfftk.formats.base.SegmentationClass representing an CCP4/MAP mask segmentation
from sfftk.formats.map import MapSegmentation map_seg = MapSegmentation('file.map')
User-facing reader classes
-
class
sfftk.formats.mod.IMODSegmentation(fn, *args, **kwargs)¶ Bases:
sfftk.formats.base.SegmentationClass representing an IMOD segmentation
from sfftk.formats.mod import IMODSegmentation mod_seg = IMODSegmentation('file.mod')
-
convert(args, *args_, **kwargs_)¶ Method to convert an IMOD file to an EMDB-SFF file
-
sfftk.formats.seg
-
class
sfftk.formats.seg.SeggerSegmentation(fn, top_level=False, *args, **kwargs)¶ Bases:
sfftk.formats.base.SegmentationClass representing an Segger segmentation
from sfftk.formats.seg import SeggerSegmentation seg_seg = SeggerSegmentation('file.seg')
-
convert(*args, **kwargs)¶ Method to convert a Segger file to an EMDB-SFF file
-
User-facing reader classes
-
class
sfftk.formats.stl.STLSegmentation(fn)¶ Bases:
sfftk.formats.base.SegmentationClass representing an STL segmentation
from sfftk.formats.stl import STLSegmentation stl_seg = STLSegmentation('file.stl')
User-facing reader classes
-
class
sfftk.formats.surf.AmiraHyperSurfaceSegmentation(fn)¶ Bases:
sfftk.formats.base.SegmentationClass representing an AmiraHyperSurface segmentation
from sfftk.formats.surf import AmiraHyperSurfaceSegmentation surf_seg = AmiraHyperSurfaceSegmentation('file.surf')
sfftk.notes package¶
-
class
sfftk.notes.find.SearchQuery(args)¶ Bases:
objectSearchQuery class
-
results¶ JSON of response from HTTP API
-
search(*args, **kwargs)¶ Do the search
Return result: search results Rtype result: SearchResults
-
-
class
sfftk.notes.find.SearchResults(json_result, search_args, *args, **kwargs)¶ Bases:
objectSearchResults class
-
class
sfftk.notes.view.HeaderView(segmentation)¶ Bases:
sfftk.notes.view.ViewHeaverView class
Display EMDB-SFF header
-
class
sfftk.notes.view.NoteView(segment, _long=False)¶ Bases:
sfftk.notes.view.ViewNoteView class
Display annotation for a single segment
-
sfftk.notes.view.list_notes(args)¶ List all notes in an EMDB-SFF file
Parameters: args ( argparse.Namespace) – parsed argumentsReturn int status: 0 is OK, else failure
-
sfftk.notes.view.show_notes(args)¶ Show notes in an EMDB-SFF file for the specified segment IDs
Parameters: args ( argparse.Namespace) – parsed argumentsReturn int status: 0 is OK, else failure
-
class
sfftk.notes.modify.AbstractGlobalNote¶ Bases:
sfftk.notes.modify.BaseNoteGlobalNote ‘abstract’ class that defines private attributes and methods
-
add_to_segmentation(segmentation)¶ Add attributes to a segmentation
Parameters: segmentation ( sfftk.schema.SFFSegmentation) – an EMDB-SFF segmentationReturn segmentation: an EMDB-SFF segmentation Rtype segmentation: sfftk.schema.SFFSegmentation
-
del_from_segmentation(segmentation)¶ Delete attributes from a segmentation
Parameters: segmentation ( sfftk.schema.SFFSegmentation) – an EMDB-SFF segmentationReturn segmentation: an EMDB-SFF segmentation Rtype segmentation: sfftk.schema.SFFSegmentation
-
edit_in_segmentation(segmentation)¶ Edit attributes in a segmentation
Parameters: segmentation ( sfftk.schema.SFFSegmentation) – an EMDB-SFF segmentationReturn segmentation: an EMDB-SFF segmentation Rtype segmentation: sfftk.schema.SFFSegmentation
-
-
class
sfftk.notes.modify.AbstractNote¶ Bases:
sfftk.notes.modify.BaseNoteNote ‘abstact’ class that defines private attributes and main methods
-
add_to_segment(segment)¶ Add the annotations found in this
Noteobject to theschema.SFFSegmentobjectParameters: segment ( sfftk.schema.SFFSegment) – single segment in EMDB-SFF
-
del_from_segment(segment)¶ Delete the annotations found in this
Noteobject to theschema.SFFSegmentobjectParameters: segment ( sfftk.schema.SFFSegment) – single segment in EMDB-SFF
-
edit_in_segment(segment)¶ Edit the annotations found in this
Noteobject to theschema.SFFSegmentobjectParameters: segment ( sfftk.schema.SFFSegment) – single segment in EMDB-SFF
-
-
class
sfftk.notes.modify.BaseNote¶ Bases:
objectNote base class
-
sfftk.notes.modify.add_note(args)¶ Add annotation to a segment specified in args
Parameters: args ( argparse.Namespace) – parsed arguments
-
sfftk.notes.modify.del_note(args)¶ Delete annotation to a segment specified in args
Parameters: args ( argparse.Namespace) – parsed arguments
-
sfftk.notes.modify.edit_note(args)¶ Edit annotation to a segment specified in args
Parameters: args ( argparse.Namespace) – parsed arguments
-
sfftk.notes.modify.merge(args)¶ Merge two EMDB-SFF files
Parameters: args ( argparse.Namespace) – parsed arguments
-
sfftk.notes.modify.save(args)¶ Save changes made
Parameters: args (argparse.Namespace) – parsed arguments
-
sfftk.notes.modify.trash(args)¶ Trash changes made
Parameters: args (argparse.Namespace) – parsed arguments
sfftk.core package¶
configs.py¶
SFFTK configs
-
sfftk.core.configs.get_configs(fn='/Users/pkorir/Documents/workspace/bioimaging-scripts/trunk/sfftk/sfftk/sff.conf')¶ Get SFFTK configs
Parameters: fn (str) – filename (default: ./sff.conf)Return dict configs: dictionary of configs
Parses command-line options
-
sfftk.core.parser.add_args(parser, the_arg)¶ Convenience function to return the argument definition to the given parser
Usage:
>>> my_arg = {'arg': ['-x'], 'kwargs': {'help': 'help'}} >>> this_parser = argparse.ArgumentParser() >>> add_args(this_parser, my_arg)
Parameters: - parser (
argparse.Parser) – a parser - the_arg (dict) – the argument specified as a dict with keys ‘args’ and ‘kwargs’
Return parser: a parser
Rtype parser: argparse.Parser- parser (
-
sfftk.core.parser.parse_args(_args)¶ Parse and check command-line arguments
Subcommand handlers defined in __main__.py (e.g. handle_conver(...)) should not have to check arguments for consistency
Parameters: _args (list) – list of arguments Returns: parsed arguments Return type: argparse.Namespace
print_tools.py¶
Utilities for printing stuff to the screen.
-
sfftk.core.print_tools.get_printable_ascii_string(s)¶ Given a string of ASCII and non-ASCII return the maximal substring with a printable ASCII prefix.
Parameters: s (str) – the string to search Return str ascii_s: the minimal ASCII string
-
sfftk.core.print_tools.print_date(print_string, stream=<open file '<stderr>', mode 'w'>, newline=True, incl_date=True)¶ Print the given string with date on the given stream
Parameters: - print_string (str) – the string to be printed
- stream (sys.stderr or sys.stdout) – the stream to write to
- newline (bool) – whether (default) or not to add a newline at the end
-
sfftk.core.print_tools.print_static(print_string, stream=<open file '<stderr>', mode 'w'>, incl_date=True)¶ Print the given string with date on the given stream
Parameters: - print_string (str) – the string to be printed
- stream (sys.stderr or sys.stdout) – the stream to write to
- newline (bool) – whether (default) or not to add a newline at the end