Back to index

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

List of all members.

Public Member Functions

def __init__
def find
def find_differences

Public Attributes

 alphabet_strict

Private Member Functions

def _get_motif_dict
def _add_motif

Detailed Description

Find motifs in a set of Sequence Records.

Definition at line 17 of file Motif.py.


Constructor & Destructor Documentation

def Bio.NeuralNetwork.Gene.Motif.MotifFinder.__init__ (   self,
  alphabet_strict = 1 
)
Initialize a finder to get motifs.

Arguments:

o alphabet_strict - Whether or not motifs should be
restricted to having all of there elements within the alphabet
of the sequences. This requires that the Sequences have a real
alphabet, and that all sequences have the same alphabet.

Definition at line 20 of file Motif.py.

00020 
00021     def __init__(self, alphabet_strict = 1):
00022         """Initialize a finder to get motifs.
00023 
00024         Arguments:
00025 
00026         o alphabet_strict - Whether or not motifs should be
00027         restricted to having all of there elements within the alphabet
00028         of the sequences. This requires that the Sequences have a real
00029         alphabet, and that all sequences have the same alphabet.
00030         """
00031         self.alphabet_strict = alphabet_strict

Here is the caller graph for this function:


Member Function Documentation

def Bio.NeuralNetwork.Gene.Motif.MotifFinder._add_motif (   self,
  motif_dict,
  motif_to_add 
) [private]
Add a motif to the given dictionary.

Definition at line 134 of file Motif.py.

00134 
00135     def _add_motif(self, motif_dict, motif_to_add):
00136         """Add a motif to the given dictionary.
00137         """
00138         # incrememt the count of the motif if it is already present
00139         if motif_to_add in motif_dict:
00140             motif_dict[motif_to_add] += 1
00141         # otherwise add it to the dictionary
00142         else:
00143             motif_dict[motif_to_add] = 1
00144 
        return motif_dict

Here is the caller graph for this function:

def Bio.NeuralNetwork.Gene.Motif.MotifFinder._get_motif_dict (   self,
  seq_records,
  motif_size 
) [private]
Return a dictionary with information on motifs.

This internal function essentially does all of the hard work for
finding motifs, and returns a dictionary containing the found motifs
and their counts. This is internal so it can be reused by
find_motif_differences.

Definition at line 50 of file Motif.py.

00050 
00051     def _get_motif_dict(self, seq_records, motif_size):
00052         """Return a dictionary with information on motifs.
00053 
00054         This internal function essentially does all of the hard work for
00055         finding motifs, and returns a dictionary containing the found motifs
00056         and their counts. This is internal so it can be reused by
00057         find_motif_differences.
00058         """
00059         if self.alphabet_strict:
00060             alphabet = seq_records[0].seq.alphabet
00061         else:
00062             alphabet = None
00063 
00064         # loop through all records to find the motifs in the sequences
00065         all_motifs = {}
00066         for seq_record in seq_records:
00067             # if we are working with alphabets, make sure we are consistent
00068             if alphabet is not None:
00069                 assert seq_record.seq.alphabet == alphabet, \
00070                        "Working with alphabet %s and got %s" % \
00071                        (alphabet, seq_record.seq.alphabet)
00072 
00073             # now start finding motifs in the sequence
00074             for start in range(len(seq_record.seq) - (motif_size - 1)):
00075                 motif = seq_record.seq[start:start + motif_size].tostring()
00076 
00077                 # if we are being alphabet strict, make sure the motif
00078                 # falls within the specified alphabet
00079                 if alphabet is not None:
00080                     motif_seq = Seq(motif, alphabet)
00081                     if _verify_alphabet(motif_seq):
00082                         all_motifs = self._add_motif(all_motifs, motif)
00083 
00084                 # if we are not being strict, just add the motif
00085                 else:
00086                     all_motifs = self._add_motif(all_motifs, motif)
00087 
00088         return all_motifs

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.NeuralNetwork.Gene.Motif.MotifFinder.find (   self,
  seq_records,
  motif_size 
)
Find all motifs of the given size in the passed SeqRecords.

Arguments:

o seq_records - A list of SeqRecord objects which the motifs
will be found from.

o motif_size - The size of the motifs we want to look for.

Returns:
A PatternRepository object that contains all of the motifs (and their
counts) found in the training sequences).

Definition at line 32 of file Motif.py.

00032 
00033     def find(self, seq_records, motif_size):
00034         """Find all motifs of the given size in the passed SeqRecords.
00035 
00036         Arguments:
00037 
00038         o seq_records - A list of SeqRecord objects which the motifs
00039         will be found from.
00040 
00041         o motif_size - The size of the motifs we want to look for.
00042 
00043         Returns:
00044         A PatternRepository object that contains all of the motifs (and their
00045         counts) found in the training sequences).
00046         """
00047         motif_info = self._get_motif_dict(seq_records, motif_size)
00048 
00049         return PatternRepository(motif_info)

Here is the call graph for this function:

def Bio.NeuralNetwork.Gene.Motif.MotifFinder.find_differences (   self,
  first_records,
  second_records,
  motif_size 
)
Find motifs in two sets of records and return the differences.

This is used for finding motifs, but instead of just counting up all
of the motifs in a set of records, this returns the differences
between two listings of seq_records.

o first_records, second_records - Two listings of SeqRecord objects
to have their motifs compared.

o motif_size - The size of the motifs we are looking for.

Returns:
A PatternRepository object that has motifs, but instead of their
raw counts, this has the counts in the first set of records
subtracted from the counts in the second set.

Definition at line 89 of file Motif.py.

00089 
00090     def find_differences(self, first_records, second_records, motif_size):
00091         """Find motifs in two sets of records and return the differences.
00092 
00093         This is used for finding motifs, but instead of just counting up all
00094         of the motifs in a set of records, this returns the differences
00095         between two listings of seq_records.
00096 
00097         o first_records, second_records - Two listings of SeqRecord objects
00098         to have their motifs compared.
00099 
00100         o motif_size - The size of the motifs we are looking for.
00101 
00102         Returns:
00103         A PatternRepository object that has motifs, but instead of their
00104         raw counts, this has the counts in the first set of records
00105         subtracted from the counts in the second set.
00106         """
00107         first_motifs = self._get_motif_dict(first_records, motif_size)
00108         second_motifs = self._get_motif_dict(second_records, motif_size)
00109 
00110         motif_diffs = {}
00111 
00112         # first deal with all of the keys from the first motif
00113         for cur_key in first_motifs:
00114             if cur_key in second_motifs:
00115                 motif_diffs[cur_key] = first_motifs[cur_key] - \
00116                                        second_motifs[cur_key]
00117             else:
00118                 motif_diffs[cur_key] = first_motifs[cur_key]
00119 
00120         # now see if there are any keys from the second motif
00121         # that we haven't got yet.
00122         missing_motifs = list(second_motifs)
00123 
00124         # remove all of the motifs we've already added
00125         for added_motif in motif_diffs:
00126             if added_motif in missing_motifs:
00127                 missing_motifs.remove(added_motif)
00128 
00129         # now put in all of the motifs we didn't get
00130         for cur_key in missing_motifs:
00131             motif_diffs[cur_key] = 0 - second_motifs[cur_key]
00132 
00133         return PatternRepository(motif_diffs)
                

Here is the call graph for this function:


Member Data Documentation

Definition at line 30 of file Motif.py.


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