Biskit :: ProfileCollection :: ProfileCollection :: Class ProfileCollection
[hide private]
[frames] | no frames]

Class ProfileCollection

source code

Manage profiles (arrays or lists of values) for trajectory frames or atoms/residues in PDBModel. ProfileCollection resembles a 2-dimensional array where the first axis (let's say row) is accessed by a string key and each row has an additional info dictionary assigned to it. The take() and concat() methods operate on the columns, i.e. they are applied to all profiles at the same time.

By default, profiles of numbers are stored and returned as Numeric.array and all others are stored and returned as ordinary list. This behaviour can be modified with the option asarray of ProfileCollection.set(). Using both lists and arrays is a compromise between the efficiency of Numeric arrays and the problem that arrays of objects cannot be unpickled (Numeric bug) and that arrays of strings would end up as 2-D arrays of char. The 'isarray' entry of a profile's info dictionary tells whether the profile is stored as array or as list.

ProfileCollection p can be accessed like a dictionary of lists:
 len( p )          -> number of profiles (== len( p.profiles ) )
 p['prof1']        -> list with values of profile 'prof1'
 del p['prof1']    -> remove a profile
 p['prof1'] = [..] -> add a profile without additional infos
 for k in p        -> iterate over profile keys
 'prof1' in p      -> 1, if collection contains key 'prof1'
But it is more than that - each key also has a dictionary of info values assigned to it (see getInfo(), setInfo(), p.infos). These can be accessed like:
 p['prof1','date']   -> date of creation of profile named 'prof1'
 p.getInfo('prof1')  -> returns all info records
 p['prof1','comment'] = 'first prof'  -> add/change single info value


Instance Methods [hide private]
  __init__(self, version=None, profiles=None, infos=None)
str version(self)
Class version.
any __getitem__(self, k)
Get profile item:
any __setitem__(self, k, v)
Set profile item:
  __delitem__(self, k)
Delete profile item:
int __len__(self)
Length of profile
1|0 __contains__(self, k)
Check if profile contains key:
list __iter__(self)
Iterate over profile:
  keys(self)
  has_key(self, k)
  values(self)
list items(self)
Get list of tuples of profile names and profiles:
list OR array __array_or_list(self, prof, asarray)
Convert to array or list depending on asarray option
list OR array __expand(self, prof, mask, default)
Expand profile to have a value also for masked positions.
  set(self, name, prof, mask=None, default=None, asarray=1, comment=None, **moreInfo)
Add/override a profile.
  setInfo(self, name, **args)
Add/Override infos about a given profile:
  setMany(self, profileDict, infos={})
setMany( dict, [infoDict] ) Add/Override many profiles
  get(self, name, default=None)
get( profKey, [default] ) -> list of values OR get( (profKey, infoKey), [default] ) -> single value of info dict
dict getInfo(self, name)
Use:
[1|0] profile2mask(self, profName, cutoff_min=None, cutoff_max=None)
Convert profile into a mask based on the max and min cutoff values.
profile take(self, indices)
Take on profile using provided indices:
1|0 remove(self, *key)
Remove profile OR info values of profile:
profileCollection concat(self, *profiles)
Concatenate all profiles in this with corresponding profiles in the given ProfileCollection(s).
  update(self, other, stickyChanged=1)
Merge other ProfileCollection into this one, replacing existing profiles and info values.
  updateMissing(self, source, copyMissing=1, allowEmpty=0)
Merge other ProfileCollection into this one but do not replace / update existing profiles and info records.
ProfileCollection clone(self)
Clone (deepcopy) profile:
  clear(self)
Delete all:
int profLength(self)
Length of profile:
biggles.FramedPlot plot(self, *name, **arg)
Plot one or more profiles using Biggles:
  __shortString(self, s, maxLen)
str __repr__(self)
Returns string representation within interactive python interpreter.

Method Details [hide private]

__init__(self, version=None, profiles=None, infos=None)
(Constructor)

source code 

version(self)

source code 

Class version.
Returns: str
class version number

__getitem__(self, k)
(Indexing operator)

source code 

Get profile item:
 p['prof1']         <==>  p.get( 'prof1' )         
 p['prof1','info1]  <==>  p.get( 'prof1','info1' ) 
Returns: any
item

__setitem__(self, k, v)
(Index assignment operator)

source code 

Set profile item:
 p['prof1'] = range(10)      <==> p.set( 'prof1', range(10) )      
 p['prof1','info1]='comment' <==> p.setInfo('prof1',info1='comment')
Returns: any
item

__delitem__(self, k)
(Index deletion operator)

source code 

Delete profile item:
 del p['prof1']         <==>  p.remove( 'prof1' )          
 del p['prof1','info1'] <==>  p.remove( 'prof1', 'info1' ) 

__len__(self)
(Length operator)

source code 

Length of profile
Returns: int
profile length

__contains__(self, k)
(In operator)

source code 

Check if profile contains key:
 k in self  <==>  p.has_key( k ) 
Returns: 1|0
True or False

__iter__(self)

source code 

Iterate over profile:
 for k in self  <==>  for k in p.keys()
Returns: list
list of items

keys(self)

source code 

has_key(self, k)

source code 

values(self)

source code 

items(self)

source code 

Get list of tuples of profile names and profiles:
 p.items() -> [ (key1, [any]), (key2, [any]), ..) ]
Returns: list
list of tuples of profile names and profiles

__array_or_list(self, prof, asarray)

source code 

Convert to array or list depending on asarray option
Parameters:
  • prof (list OR array) - profile
  • asarray (2|1|0) - 1.. autodetect type, 0.. force list, 2.. force array
Returns: list OR array
profile
Raises:

__expand(self, prof, mask, default)

source code 

Expand profile to have a value also for masked positions.
Parameters:
  • prof (list OR array) - profile
  • mask ([int]) - atom mask
  • default (any) - default value
Returns: list OR array
profile

set(self, name, prof, mask=None, default=None, asarray=1, comment=None, **moreInfo)

source code 

Add/override a profile. None is allowed as special purpose value - in which case all other parameters are ignored. Otherwise, the two info records 'version', 'changed' and 'isarray' are always modified but can be overridden by key=value pairs to this function.
Parameters:
  • name (str) - profile name (i.e. key)
  • prof ([any] OR None) - list of values OR None
  • mask ([int]) - list 1 x N_items of 0|1, if there are less values than items, provide mask with 0 for missing values, N.sum(mask)==N_items
  • default (any) - value for items masked. (default: None for lists, 0 for arrays]
  • asarray (0|1|2) - store as list (0), as array (2) or store numbers as array but everything else as list (1) (default: 1)
  • comment (str) - goes into info[name]['comment']
  • moreInfo (key=value) - additional key-value pairs for info[name]
Raises:
  • ProfileError - if length of prof != length of other profiles
  • ProfileError - if mask is given but N.sum(mask) != len(prof)

setInfo(self, name, **args)

source code 

Add/Override infos about a given profile:
 e.g. setInfo('relASA', comment='new', params={'bin':'whatif'})
Raises:

setMany(self, profileDict, infos={})

source code 

setMany( dict, [infoDict] ) Add/Override many profiles
Parameters:
  • profileDict (dict) - dict with name:profile pairs
  • infos (dict of dict) - info dicts for each profile, indexed by name

get(self, name, default=None)

source code 

get( profKey, [default] ) -> list of values OR get( (profKey, infoKey), [default] ) -> single value of info dict
Parameters:
  • name (str OR (str, str)) - profile key or profile and info key
  • default (any) - default result if no profile is found, if None and no profile is found, raise exception
Raises:

getInfo(self, name)

source code 

Use:
  getInfo( name ) -> dict with infos about profile::
Guaranteed infos: 'version'->str, 'comment'->str, 'changed'->1|0
Parameters:
  • name (str) - profile name
Returns: dict
dict with infos about profile
Raises:

profile2mask(self, profName, cutoff_min=None, cutoff_max=None)

source code 

Convert profile into a mask based on the max and min cutoff values.
Parameters:
  • profName (str) - profile name
  • cutoff_min (float) - lower limit
  • cutoff_max (float) - upper limit
Returns: [1|0]
mask len( get(profName) ) x 1|0

take(self, indices)

source code 

Take on profile using provided indices:
 take( indices ) -> ProfileCollection with extract of all profiles
Parameters:
  • indices - list of indices @type indices [int]
Returns: profile
new profile from indices
Raises:

remove(self, *key)

source code 

Remove profile OR info values of profile:
 remove( profKey ) -> 1|0, 1 if complete entry has been removed
 remove( profKey, infoKey ) -> 1|0, 1 if single info value was removed
Parameters:
  • key (str OR str, str) - profile name OR name, infoKey
Returns: 1|0
sucess status

concat(self, *profiles)

source code 

Concatenate all profiles in this with corresponding profiles in the given ProfileCollection(s). Profiles that are not found in all ProfileCollections are skipped:
 p0.concat( p1 [, p2, ..]) -> single ProfileCollection with the
 same number of profiles as p0 but with the length of p0+p1+p2..
Parameters:
  • profiles (profileCollection(s)) - profile(s) to concatenate
Returns: profileCollection
concatenated profile(s)

update(self, other, stickyChanged=1)

source code 

Merge other ProfileCollection into this one, replacing existing profiles and info values. This is the obvious translation of dict.update(). The changed flag of each profile is set to 1 if:
  • an existing profile is overridden with different values
  • the profile is marked 'changed' in the other collection
  • Parameters:
    • other (ProfileCollection) - profile
    • stickyChanged (0|1) - mark all profiles 'changed' that are marked 'changed' in the other collection (default: 1)

    updateMissing(self, source, copyMissing=1, allowEmpty=0)

    source code 

    Merge other ProfileCollection into this one but do not replace / update existing profiles and info records. There is one exception: Empty profiles (None or []) are replaced but their info records stay untouched. If copyMissing=0, profiles that are existing in source but not in this collection, are NOT copied (i.e. only empty profiles are replaced).
    Parameters:
    • source (ProfileCollection) - profile
    • copyMissing (0|1) - copy missing profiles that exist in source (default: 1)
    • allowEmpty (0|1) - tolerate zero-length profiles after update (default: 0)
    Raises:
    • ProfileError - if allowEmpty is 0 and some empty profiles cannot be found in source

    clone(self)

    source code 

    Clone (deepcopy) profile:
     clone() -> ProfileCollection (or sub-class, actually a deepcopy)
    
    Returns: ProfileCollection
    profile

    clear(self)

    source code 

    Delete all:
     clear() -> None; delete all profiles and infos.
    

    profLength(self)

    source code 

    Length of profile:
     profLength() -> int; length of first non-None profile or 0
    
    Returns: int
    length of first non-None profile or 0

    plot(self, *name, **arg)

    source code 

    Plot one or more profiles using Biggles:
     plot( name1, [name2, ..],[arg1=x, arg2=y]) -> biggles.FramedPlot
    
    Parameters:
    • name (str) - one or more profile names
    • arg () - key=value pairs for Biggles.Curve() function
    Returns: biggles.FramedPlot
    plot, view using plot.show()
    Raises:
    • TypeError - if profile contains non-number items
    • ImportError - If biggles module could not be imported

    __shortString(self, s, maxLen)

    source code 

    __repr__(self)
    (Representation operator)

    source code 
    Returns: str
    string representation within interactive python interpreter.