Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.SubsMat.FreqTable.FreqTable Class Reference

A class to handle frequency tables Copyright Iddo Friedberg idoer.nosp@m.g@cc.nosp@m..huji.nosp@m..ac..nosp@m.il Biopython (http://biopython.org) license applies Methods to read a letter frequency or a letter count file: Example files for a DNA alphabet: More...

List of all members.

Public Member Functions

def __init__

Public Attributes

 alphabet
 count

Private Member Functions

def _freq_from_count
def _alphabet_from_input

Detailed Description

A class to handle frequency tables Copyright Iddo Friedberg idoer.nosp@m.g@cc.nosp@m..huji.nosp@m..ac..nosp@m.il Biopython (http://biopython.org) license applies Methods to read a letter frequency or a letter count file: Example files for a DNA alphabet:

A count file (whitespace seperated):

A 50 C 37 G 23 T 58

The same info as a frequency file:

A 0.2976 C 0.2202 G 0.1369 T 0.3452

Functions: read_count(f): read a count file from stream f. Then convert to frequencies read_freq(f): read a frequency data file from stream f. Of course, we then don't have the counts, but it is usually the letter frquencies which are interesting.

Methods: (all internal) Attributes: alphabet: The IUPAC alphabet set (or any other) whose letters you are using. Common sets are: IUPAC.protein (20-letter protein), IUPAC.unambiguous_dna (4-letter DNA). See Bio/alphabet for more. data: frequency dictionary. count: count dictionary. Empty if no counts are provided.

Example of use:

from SubsMat import FreqTable ftab = FreqTable.FreqTable(my_frequency_dictionary,FreqTable.FREQ) ftab = FreqTable.FreqTable(my_count_dictionary,FreqTable.COUNT) ftab = FreqTable.read_count(open('myDNACountFile'))

Definition at line 49 of file FreqTable.py.


Constructor & Destructor Documentation

def Bio.SubsMat.FreqTable.FreqTable.__init__ (   self,
  in_dict,
  dict_type,
  alphabet = None 
)

Definition at line 62 of file FreqTable.py.

00062 
00063     def __init__(self,in_dict,dict_type,alphabet=None):
00064         self.alphabet = alphabet
00065         if dict_type == COUNT:
00066             self.count = in_dict
00067             self._freq_from_count()
00068         elif dict_type == FREQ:
00069             self.count = {}
00070             self.update(in_dict)
00071         else:
00072             raise ValueError("bad dict_type")
00073         if not alphabet:
00074             self.alphabet = Alphabet.Alphabet()
00075             self.alphabet.letters = self._alphabet_from_input()


Member Function Documentation

Definition at line 56 of file FreqTable.py.

00056 
00057     def _alphabet_from_input(self):
00058         s = ''
00059         for i in sorted(self):
00060             s += i
00061         return s

Definition at line 51 of file FreqTable.py.

00051 
00052     def _freq_from_count(self):
00053         total = float(sum(self.count.values()))
00054         for i, v in self.count.iteritems():
00055             self[i] = v / total


Member Data Documentation

Definition at line 63 of file FreqTable.py.

Definition at line 65 of file FreqTable.py.


The documentation for this class was generated from the following file: