4.2.4 Text Streams

There are some use cases, such as web services, for which it may be desirable to load pedigrees from strings rather than from files. This is done by passing the pedsource keyword to pyp_newclasses.loadPedigree with a value of "textstream", along with a string named "pedstream":
options = {}
options['pedfile'] = ''
options['messages'] = 'verbose'
options['pedformat'] = 'ASD'

if __name__ == "__main__":
    pedstream = 'a1,s1,d1\na2,s2,d2\na3,a1,a2\n'
    test = pyp_newclasses.loadPedigree(options,pedsource='textstream',pedstream=pedstream)
Only ASD-formatted pedigrees can be loaded this way, individual IDs are separated with commas, and successive records are separated by newlines. These restrictions are hard-coded into the NewPedigree::load() method. All records must contain a newline, including the last record in the string! You must also set the "pedfile" option to some value, even if that value is just an empty string as in the example.

The expected use case is that the pedigree would be retrieved from a database, and the result set from the SQL query converted into a string. There is an upper bound on the size of pedigree that can be loaded from a stream based on the physical memory available on your platform, and extremely large pedigrees should be loaded from a text file.

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