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 : """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. """ # initialize a dictionary to hold the motifs in this sequence seq_motifs = {} for motif in self._motifs: seq_motifs[motif] = 0 # count all of the motifs we are looking for in the sequence for start in range(len(sequence)  (self._motif_size  1)): motif = sequence[start:start + self._motif_size].data if seq_motifs.has_key(motif): seq_motifs[motif] += 1 # normalize the motifs to go between zero and one min_count = min(seq_motifs.values()) max_count = max(seq_motifs.values()) # as long as we have some motifs present, normalize them # otherwise we'll just return 0 for everything if max_count > 0: for motif in seq_motifs.keys(): seq_motifs[motif] = (float(seq_motifs[motif]  min_count) / float(max_count)) # return the relative motif counts in the specified order motif_amounts = [] for motif in self._motifs: motif_amounts.append(seq_motifs[motif]) return motif_amounts
