4.4.1 Input from Databases

PyPedal can load ASDx-formatted pedigrees from an SQLite database using "pedsource='db'". The pedigree will be loaded from the database and table specified in the database_name and dbtable_name variables. Consider the following example:
test = pyp_newclasses.loadPedigree(options,pedsource='db')
test.metadata.printme()
This produces the output:
Metadata for  DB Stream ()
    Records:                7
    Unique Sires:           3
    Unique Dams:            3
    Unique Gens:            1
    Unique Years:           1
    Unique Founders:        4
    Unique Herds:           1
    Pedigree Code:          ASDx
Note that user-supplied values of the pedigree format string will be over-written by the load() method and do not affect database processing. Database importation is hard-coded to accept only pedigrees in that format.

It is possible to load pedigrees from a databse with a format different than that exected by PyPedal, but it requires that you make changes to the NewPedigree class's load method. Consider the database-loading code that is located at about line 250 of pyp_newclasses.py:

251  elif pedsource == 'db':
252      self.kw['pedformat'] = 'ASDx'
253      self.kw['sepchar'] = ','
...
259      try:
260          # Connect to the database
261          if pyp_db.doesTableExist(self):
262            conn = pyp_db.connectToDatabase(self)
263              if conn:
264                  sql = 'SELECT * FROM %s' % ( self.kw['database_table'] )
265                  dbstream = conn.GetAll(sql)
In order to load data from your own database you must change the pedigree format string on line 252 to match the pedigree you want to load (see Table 3.2 for a list of pedigree format codes). You then need to change the SQL statement on line 264 to match the column names in your database and the order of fields in your pedigree format string. The animal, sire, and dam IDs, respectively, should always be the first three columns in your records. The query results are stored as a list of tuples in dbstream and will be unpacked in the preprocess method (cf. line 864).

Please note that while I will try and answer questions about the way in which PyPedal handles loading pedigrees from databases, I cannot answer detailed questions about databases to which I do not ave access. You should carefully test your custom queries in SQL to ensure that they are working correctly before adding them to PyPedal. Also, please check your pedigree format string to make sure that it matches your query.

See About this document... for information on suggesting changes.