Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_NNGene.PatternIOTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_motif
def test_schema
def test_signature

Public Attributes

 alphabet
 test_file
 pattern_io

Detailed Description

Tests for reading and writing patterns to a file.

Definition at line 32 of file test_NNGene.py.


Member Function Documentation

Definition at line 35 of file test_NNGene.py.

00035 
00036     def setUp(self):
00037         self.alphabet = IUPAC.ambiguous_dna
00038         self.test_file = os.path.join("NeuralNetwork", "patternio.txt")
00039         #Remove any existing copy of the output file,
00040         if os.path.isfile(self.test_file):
00041             os.remove(self.test_file)
00042         self.pattern_io = Pattern.PatternIO(self.alphabet)

Definition at line 43 of file test_NNGene.py.

00043 
00044     def tearDown(self):
00045         #Clean up by removing our output file,
00046         if os.path.isfile(self.test_file):
00047             os.remove(self.test_file)

Reading and writing motifs to a file

Definition at line 48 of file test_NNGene.py.

00048 
00049     def test_motif(self):
00050         """Reading and writing motifs to a file
00051         """
00052         # write to a file
00053         motifs = ["GAC", "AAA", "TTT", "GGG"]
00054         output_handle = open(self.test_file, "w")
00055         self.pattern_io.write(motifs, output_handle)
00056         output_handle.close()
00057 
00058         # read 'em back
00059         input_handle = open(self.test_file, "r")
00060         read_motifs = self.pattern_io.read(input_handle)
00061         input_handle.close()
00062         assert read_motifs == motifs, \
00063                "Failed to get back expected motifs %s, got %s" \
00064                % (motifs, read_motifs)
00065 
00066         # write seqs
00067         seq_motifs = []
00068         for motif in motifs:
00069             seq_motifs.append(Seq(motif, self.alphabet))
00070         output_handle = open(self.test_file, "w")
00071         self.pattern_io.write_seq(seq_motifs, output_handle)
00072         output_handle.close()
00073 
00074         # read the seqs back
00075         input_handle = open(self.test_file, "r")
00076         read_motifs = self.pattern_io.read(input_handle)
00077         input_handle.close()
00078         assert read_motifs == motifs, \
00079                "Failed to get back expected motifs %s from seqs, got %s" \
00080                % (motifs, read_motifs)

Here is the call graph for this function:

Reading and writing schemas to a file.

Definition at line 81 of file test_NNGene.py.

00081 
00082     def test_schema(self):
00083         """Reading and writing schemas to a file.
00084         """
00085         schemas = ["GTR", "GAC"]
00086         # write out the schemas
00087         output_handle = open(self.test_file, "w")
00088         self.pattern_io.write(schemas, output_handle)
00089         output_handle.close()
00090 
00091         # read back the schemas
00092         input_handle = open(self.test_file, "r")
00093         read_schemas = self.pattern_io.read(input_handle)
00094         input_handle.close()
00095         assert schemas == read_schemas, \
00096                "Read incorrect schemas %s, expected %s." \
00097                % (read_schemas, schemas)
00098 
00099         # --- make sure inappropriate alphabets are reported
00100         schemas = ["GTR", "G*C"] # '*' not in the unambigous alphabet
00101         output_handle = open(self.test_file, "w")
00102         self.pattern_io.write(schemas, output_handle)
00103         output_handle.close()
00104 
00105         input_handle = open(self.test_file, "r")
00106         try:
00107             read_schemas = self.pattern_io.read(input_handle)
00108             raise AssertionError("Did not report error on bad alphabet.")
00109         except ValueError:
00110             pass # expected behavior
00111         except:
00112             raise AssertionError("Got unexpected error while reading.")
00113 
00114         input_handle.close()

Here is the call graph for this function:

Reading and writing signatures to a file.

Definition at line 115 of file test_NNGene.py.

00115 
00116     def test_signature(self):
00117         """Reading and writing signatures to a file.
00118         """
00119         signatures = [("GAC", "GAC"), ("AAA", "TTT")]
00120         output_handle = open(self.test_file, "w")
00121         self.pattern_io.write(signatures, output_handle)
00122         output_handle.close()
00123 
00124         input_handle = open(self.test_file, "r")
00125         read_sigs = self.pattern_io.read(input_handle)
00126         input_handle.close()
00127         assert read_sigs == signatures, \
00128                "Got back unexpected signatures %s, wanted %s" \
00129                % (read_sigs, signatures)

Here is the call graph for this function:


Member Data Documentation

Definition at line 36 of file test_NNGene.py.

Definition at line 41 of file test_NNGene.py.

Definition at line 37 of file test_NNGene.py.


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