Back to index

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

List of all members.

Public Member Functions

def __init__
def setUp
def test_easy_from_motifs
def test_hard_from_motifs
def test_schema_representation

Public Attributes

 schema_bank
 factory
 test_file
 schema

Private Member Functions

def _load_schema_repository

Detailed Description

Test the SchemaFactory for generating Schemas.

Definition at line 485 of file test_NNGene.py.


Constructor & Destructor Documentation

def test_NNGene.SchemaFactoryTest.__init__ (   self,
  method 
)

Definition at line 488 of file test_NNGene.py.

00488 
00489     def __init__(self, method):
00490         unittest.TestCase.__init__(self, method)
00491 
00492         # a cached schema bank, so we don't have to load it multiple times
00493         self.schema_bank = None
    

Member Function Documentation

Helper function to load a schema repository from a file.

This also caches a schema bank, to prevent having to do this
time consuming operation multiple times.

Definition at line 534 of file test_NNGene.py.

00534 
00535     def _load_schema_repository(self):
00536         """Helper function to load a schema repository from a file.
00537 
00538         This also caches a schema bank, to prevent having to do this
00539         time consuming operation multiple times.
00540         """
00541         # if we already have a cached repository, return it
00542         if self.schema_bank is not None:
00543             return self.schema_bank
00544         
00545         # otherwise, we'll read in a new schema bank
00546 
00547         # read in the all of the motif records
00548         motif_handle = open(self.test_file, 'r')
00549         seq_records = list(SeqIO.parse(motif_handle, "fasta",
00550                                        alphabet=IUPAC.unambiguous_dna))
00551         motif_handle.close()
00552 
00553         # find motifs from the file
00554         motif_finder = Motif.MotifFinder()
00555         motif_size = 9
00556 
00557         motif_bank = motif_finder.find(seq_records, motif_size)
00558         
00559         schema_bank = self.factory.from_motifs(motif_bank, .1, 2)
00560 
00561         # cache the repository
00562         self.schema_bank = schema_bank
00563 
00564         return schema_bank

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 494 of file test_NNGene.py.

00494 
00495     def setUp(self):
00496         self.factory = Schema.SchemaFactory()
00497 
00498         self.test_file = os.path.join(os.getcwd(), "NeuralNetwork", "enolase.fasta")
00499 
00500         ambiguity_chars = {"G" : "G",
00501                            "A" : "A",
00502                            "T" : "T",
00503                            "C" : "C",
00504                            "R" : "AG",
00505                            "*" : "AGTC"}
00506 
00507         self.schema = Schema.Schema(ambiguity_chars)

Generating schema from a simple list of motifs.

Definition at line 508 of file test_NNGene.py.

00508 
00509     def test_easy_from_motifs(self):
00510         """Generating schema from a simple list of motifs.
00511         """
00512         motifs = {"GATCGAA" : 20,
00513                   "GATCGAT" : 15,
00514                   "GATTGAC" : 25,
00515                   "TTTTTTT" : 10}
00516 
00517         motif_bank = Pattern.PatternRepository(motifs)
00518 
00519         schema_bank = self.factory.from_motifs(motif_bank, .5, 2)
00520         if VERBOSE:
00521             print "\nSchemas:"
00522             for schema in schema_bank.get_all():
00523                 print "%s: %s" % (schema, schema_bank.count(schema))

Generating schema from a real life set of motifs.

Definition at line 524 of file test_NNGene.py.

00524 
00525     def test_hard_from_motifs(self):
00526         """Generating schema from a real life set of motifs.
00527         """
00528         schema_bank = self._load_schema_repository()
00529 
00530         if VERBOSE:
00531             print "\nSchemas:"
00532             for schema in schema_bank.get_top(5):
00533                 print "%s: %s" % (schema, schema_bank.count(schema))

Here is the call graph for this function:

Convert sequences into schema representations.

Definition at line 565 of file test_NNGene.py.

00565 
00566     def test_schema_representation(self):
00567         """Convert sequences into schema representations.
00568         """
00569         # get a set of schemas we want to code the sequence in
00570         schema_bank = self._load_schema_repository()
00571         top_schemas = schema_bank.get_top(25)
00572         schema_coder = Schema.SchemaCoder(top_schemas, self.schema)
00573 
00574         # get the sequences one at a time, and encode them
00575         fasta_handle = open(self.test_file, 'r')
00576         for seq_record in SeqIO.parse(fasta_handle, "fasta",
00577                                       alphabet=IUPAC.unambiguous_dna):
00578             schema_values = schema_coder.representation(seq_record.seq)
00579             if VERBOSE:
00580                 print "Schema values:", schema_values
00581         fasta_handle.close()
00582 
# --- Tests for Signatures

Here is the call graph for this function:


Member Data Documentation

Definition at line 495 of file test_NNGene.py.

Definition at line 506 of file test_NNGene.py.

Definition at line 492 of file test_NNGene.py.

Definition at line 497 of file test_NNGene.py.


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