Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.NeuralNetwork.Gene.Motif.MotifCoder Class Reference

List of all members.

Public Member Functions

def __init__
def representation

Private Attributes

 _motifs
 _motif_size

Detailed Description

Convert motifs and a sequence into neural network representations.

This is designed to convert a sequence into a representation that
can be fed as an input into a neural network. It does this by
representing a sequence based the motifs present.

Definition at line 146 of file Motif.py.


Constructor & Destructor Documentation

Initialize an input producer with motifs to look for.

Arguments:

o motifs - A complete list of motifs, in order, that are to be
searched for in a sequence.

Definition at line 153 of file Motif.py.

00153 
00154     def __init__(self, motifs):
00155         """Initialize an input producer with motifs to look for.
00156 
00157         Arguments:
00158 
00159         o motifs - A complete list of motifs, in order, that are to be
00160         searched for in a sequence.
00161         """
00162         self._motifs = motifs
00163 
00164         # check to be sure the motifs make sense (all the same size)
00165         self._motif_size = len(self._motifs[0])
00166         for motif in self._motifs:
00167             if len(motif) != self._motif_size:
00168                 raise ValueError("Motif %s given, expected motif size %s"
00169                                  % (motif, self._motif_size))

Here is the caller graph for this function:


Member Function Documentation

Represent a sequence as a set of motifs.

Arguments:

o sequence - A Bio.Seq object to represent as a motif.

This converts a sequence into a representation based on the motifs.
The representation is returned as a list of the relative amount of
each motif (number of times a motif occured divided by the total
number of motifs in the sequence). The values in the list correspond
to the input order of the motifs specified in the initializer.

Definition at line 170 of file Motif.py.

00170 
00171     def representation(self, sequence):
00172         """Represent a sequence as a set of motifs.
00173 
00174         Arguments:
00175 
00176         o sequence - A Bio.Seq object to represent as a motif.
00177 
00178         This converts a sequence into a representation based on the motifs.
00179         The representation is returned as a list of the relative amount of
00180         each motif (number of times a motif occured divided by the total
00181         number of motifs in the sequence). The values in the list correspond
00182         to the input order of the motifs specified in the initializer.
00183         """
00184         # initialize a dictionary to hold the motifs in this sequence
00185         seq_motifs = {}
00186         for motif in self._motifs:
00187             seq_motifs[motif] = 0
00188         
00189         # count all of the motifs we are looking for in the sequence
00190         for start in range(len(sequence) - (self._motif_size - 1)):
00191             motif = sequence[start:start + self._motif_size].tostring()
00192 
00193             if motif in seq_motifs:
00194                 seq_motifs[motif] += 1
00195 
00196         # normalize the motifs to go between zero and one
00197         min_count = min(seq_motifs.values())
00198         max_count = max(seq_motifs.values())
00199 
00200         # as long as we have some motifs present, normalize them
00201         # otherwise we'll just return 0 for everything 
00202         if max_count > 0:
00203             for motif in seq_motifs.keys():
00204                 seq_motifs[motif] = (float(seq_motifs[motif] - min_count)
00205                                      / float(max_count))
00206 
00207         # return the relative motif counts in the specified order
00208         motif_amounts = []
00209         for motif in self._motifs:
00210             motif_amounts.append(seq_motifs[motif])
00211 
00212         return motif_amounts
00213         

Here is the call graph for this function:


Member Data Documentation

Definition at line 164 of file Motif.py.

Definition at line 161 of file Motif.py.


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