Back to index

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

List of all members.

Public Member Functions

def __init__
def write
def write_seq
def read

Public Attributes

 separator

Private Attributes

 _alphabet

Detailed Description

Allow reading and writing of patterns to files.

This just defines a simple persistance class for patterns, making
it easy to write them to a file and read 'em back.

Definition at line 15 of file Pattern.py.


Constructor & Destructor Documentation

def Bio.NeuralNetwork.Gene.Pattern.PatternIO.__init__ (   self,
  alphabet = None 
)
Intialize the reader and writer class.

Arguments:

o alphabet - An optional argument specifying the alphabet
which patterns should follow. If an alphabet is set it'll be used
to verify that all patterns follow it.

Attributes:
o separator - A character to use in separating items in a signature
when it is written to a file and read back. This character should
not be in the possible alphabet of the sequences, or there will
be trouble.

Definition at line 21 of file Pattern.py.

00021 
00022     def __init__(self, alphabet = None):
00023         """Intialize the reader and writer class.
00024 
00025         Arguments:
00026 
00027         o alphabet - An optional argument specifying the alphabet
00028         which patterns should follow. If an alphabet is set it'll be used
00029         to verify that all patterns follow it.
00030 
00031         Attributes:
00032         o separator - A character to use in separating items in a signature
00033         when it is written to a file and read back. This character should
00034         not be in the possible alphabet of the sequences, or there will
00035         be trouble.
00036         """
00037         self._alphabet = alphabet
00038 
00039         self.separator = ";"

Here is the caller graph for this function:


Member Function Documentation

def Bio.NeuralNetwork.Gene.Pattern.PatternIO.read (   self,
  input_handle 
)
Read patterns from the specified handle.

Definition at line 74 of file Pattern.py.

00074 
00075     def read(self, input_handle):
00076         """Read patterns from the specified handle.
00077         """
00078         all_patterns = []
00079         
00080         while 1:
00081             cur_line = input_handle.readline()
00082 
00083             if not(cur_line):
00084                 break
00085 
00086             cur_pattern = cur_line.rstrip()
00087             # split up signatures
00088             if cur_pattern.find(self.separator) >= 0:
00089                 cur_pattern = tuple(cur_pattern.split(self.separator))
00090 
00091             if self._alphabet is not None:
00092                 # make single patterns (not signatures) into lists, so we
00093                 # can check signatures and single patterns the same
00094                 if type(cur_pattern) != type(tuple([])):
00095                     test_pattern = [cur_pattern]
00096                 else:
00097                     test_pattern = cur_pattern
00098                 for pattern_item in test_pattern: 
00099                     pattern_seq = Seq(pattern_item, self._alphabet)
00100                     if not(_verify_alphabet(pattern_seq)):
00101                         raise ValueError("Pattern %s not matching alphabet %s"
00102                                          % (cur_pattern, self._alphabet))
00103 
00104             all_patterns.append(cur_pattern)
00105 
00106         return all_patterns

Here is the call graph for this function:

def Bio.NeuralNetwork.Gene.Pattern.PatternIO.write (   self,
  pattern_list,
  output_handle 
)
Write a list of patterns to the given handle.

Definition at line 40 of file Pattern.py.

00040 
00041     def write(self, pattern_list, output_handle):
00042         """Write a list of patterns to the given handle.
00043         """
00044         for pattern in pattern_list:
00045             # deal with signatures, concatentate them with the separator
00046             if (type(pattern) == type([]) or 
00047                 type(pattern) == type(tuple([]))):
00048                 string_pattern = self.separator.join(pattern)
00049             # deal with the normal cases
00050             else:
00051                 string_pattern = pattern
00052                 
00053             output_handle.write("%s\n" % string_pattern)
            

Here is the caller graph for this function:

def Bio.NeuralNetwork.Gene.Pattern.PatternIO.write_seq (   self,
  seq_pattern_list,
  output_handle 
)
Convenience function to write Seq objects to a file.

This can take Seqs and MutableSeqs, and write them to a file
as strings.

Definition at line 54 of file Pattern.py.

00054 
00055     def write_seq(self, seq_pattern_list, output_handle):
00056         """Convenience function to write Seq objects to a file.
00057 
00058         This can take Seqs and MutableSeqs, and write them to a file
00059         as strings.
00060         """
00061         # convert the seq patterns into just string patterns
00062         all_patterns = []
00063 
00064         for seq_pattern in seq_pattern_list:
00065             if isinstance(seq_pattern, MutableSeq):
00066                 seq = seq_pattern.toseq()
00067                 all_patterns.append(seq.tostring())
00068             elif isinstance(seq_pattern, Seq):
00069                 all_patterns.append(seq_pattern.tostring())
00070             else:
00071                 raise ValueError("Unexpected pattern type %r" % seq_pattern)
00072 
00073         self.write(all_patterns, output_handle)

Here is the call graph for this function:


Member Data Documentation

Definition at line 36 of file Pattern.py.

Definition at line 38 of file Pattern.py.


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