def test_intervaljoins_faceted_compound(): left = (('fruit', 'sort', 'begin', 'end'), ('apple', 'cox', 1, 2), ('apple', 'fuji', 2, 4)) right = (('type', 'variety', 'start', 'stop', 'value'), ('apple', 'cox', 1, 4, 'foo'), ('apple', 'fuji', 3, 7, 'bar'), ('orange', 'mandarin', 4, 9, 'baz')) expect = (('fruit', 'sort', 'begin', 'end', 'type', 'variety', 'start', 'stop', 'value'), ('apple', 'cox', 1, 2, 'apple', 'cox', 1, 4, 'foo'), ('apple', 'fuji', 2, 4, 'apple', 'fuji', 3, 7, 'bar')) actual = intervaljoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet=('fruit', 'sort'), rfacet=('type', 'variety')) ieq(expect, actual) ieq(expect, actual) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet=('fruit', 'sort'), rfacet=('type', 'variety')) ieq(expect, actual) ieq(expect, actual)
def gff3leftjoin(table, features, seqid='seqid', start='start', end='end', proximity=1): """ Left join with a table of GFF3 features. See also :func:`petlx.interval.intervalleftjoin`. .. versionadded:: 0.2 """ return intervalleftjoin(table, features, lstart=start, lstop=end, lfacet=seqid, rstart='start', rstop='end', rfacet='seqid', proximity=proximity)
def test_intervalleftjoin_faceted_rkeymissing(): left = (('fruit', 'begin', 'end'), ('apple', 1, 2), ('orange', 5, 5)) right = (('type', 'start', 'stop', 'value'), ('apple', 1, 4, 'foo')) expect = (('fruit', 'begin', 'end', 'type', 'start', 'stop', 'value'), ('apple', 1, 2, 'apple', 1, 4, 'foo'), ('orange', 5, 5, None, None, None, None)) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet='fruit', rfacet='type') ieq(expect, actual) ieq(expect, actual)
def test_intervalleftjoin_faceted_rkeymissing(): left = (('fruit', 'begin', 'end'), ('apple', 1, 2), ('orange', 5, 5)) right = (('type', 'start', 'stop', 'value'), ('apple', 1, 4, 'foo')) expect = (('fruit', 'begin', 'end', 'type', 'start', 'stop', 'value'), ('apple', 1, 2, 'apple', 1, 4, 'foo'), ('orange', 5, 5, None, None, None, None)) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet='fruit', rfacet='type') ieq(expect, actual) ieq(expect, actual)
def test_intervalleftjoin_prefixes(): left = (('begin', 'end', 'quux'), (1, 2, 'a'), (2, 4, 'b'), (2, 5, 'c'), (9, 14, 'd'), (9, 140, 'e'), (1, 1, 'f'), (2, 2, 'g'), (4, 4, 'h'), (5, 5, 'i'), (1, 8, 'j')) right = (('start', 'stop', 'value'), (1, 4, 'foo'), (3, 7, 'bar'), (4, 9, 'baz')) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lprefix='l_', rprefix='r_') expect = (('l_begin', 'l_end', 'l_quux', 'r_start', 'r_stop', 'r_value'), (1, 2, 'a', 1, 4, 'foo'), (2, 4, 'b', 1, 4, 'foo'), (2, 4, 'b', 3, 7, 'bar'), (2, 5, 'c', 1, 4, 'foo'), (2, 5, 'c', 3, 7, 'bar'), (2, 5, 'c', 4, 9, 'baz'), (9, 14, 'd', None, None, None), (9, 140, 'e', None, None, None), (1, 1, 'f', None, None, None), (2, 2, 'g', 1, 4, 'foo'), (4, 4, 'h', 3, 7, 'bar'), (5, 5, 'i', 3, 7, 'bar'), (5, 5, 'i', 4, 9, 'baz'), (1, 8, 'j', 1, 4, 'foo'), (1, 8, 'j', 3, 7, 'bar'), (1, 8, 'j', 4, 9, 'baz')) ieq(expect, actual) ieq(expect, actual)
def test_intervalleftjoin_faceted(): left = (('fruit', 'begin', 'end'), ('apple', 1, 2), ('apple', 2, 4), ('apple', 2, 5), ('orange', 2, 5), ('orange', 9, 14), ('orange', 19, 140), ('apple', 1, 1), ('apple', 2, 2), ('apple', 4, 4), ('apple', 5, 5), ('orange', 5, 5)) right = (('type', 'start', 'stop', 'value'), ('apple', 1, 4, 'foo'), ('apple', 3, 7, 'bar'), ('orange', 4, 9, 'baz')) expect = (('fruit', 'begin', 'end', 'type', 'start', 'stop', 'value'), ('apple', 1, 2, 'apple', 1, 4, 'foo'), ('apple', 2, 4, 'apple', 1, 4, 'foo'), ('apple', 2, 4, 'apple', 3, 7, 'bar'), ('apple', 2, 5, 'apple', 1, 4, 'foo'), ('apple', 2, 5, 'apple', 3, 7, 'bar'), ('orange', 2, 5, 'orange', 4, 9, 'baz'), ('orange', 9, 14, None, None, None, None), ('orange', 19, 140, None, None, None, None), ('apple', 1, 1, None, None, None, None), ('apple', 2, 2, 'apple', 1, 4, 'foo'), ('apple', 4, 4, 'apple', 3, 7, 'bar'), ('apple', 5, 5, 'apple', 3, 7, 'bar'), ('orange', 5, 5, 'orange', 4, 9, 'baz')) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet='fruit', rfacet='type') ieq(expect, actual) ieq(expect, actual)
def test_intervalleftjoin_faceted(): left = (('fruit', 'begin', 'end'), ('apple', 1, 2), ('apple', 2, 4), ('apple', 2, 5), ('orange', 2, 5), ('orange', 9, 14), ('orange', 19, 140), ('apple', 1, 1), ('apple', 2, 2), ('apple', 4, 4), ('apple', 5, 5), ('orange', 5, 5)) right = (('type', 'start', 'stop', 'value'), ('apple', 1, 4, 'foo'), ('apple', 3, 7, 'bar'), ('orange', 4, 9, 'baz')) expect = (('fruit', 'begin', 'end', 'type', 'start', 'stop', 'value'), ('apple', 1, 2, 'apple', 1, 4, 'foo'), ('apple', 2, 4, 'apple', 1, 4, 'foo'), ('apple', 2, 4, 'apple', 3, 7, 'bar'), ('apple', 2, 5, 'apple', 1, 4, 'foo'), ('apple', 2, 5, 'apple', 3, 7, 'bar'), ('orange', 2, 5, 'orange', 4, 9, 'baz'), ('orange', 9, 14, None, None, None, None), ('orange', 19, 140, None, None, None, None), ('apple', 1, 1, None, None, None, None), ('apple', 2, 2, 'apple', 1, 4, 'foo'), ('apple', 4, 4, 'apple', 3, 7, 'bar'), ('apple', 5, 5, 'apple', 3, 7, 'bar'), ('orange', 5, 5, 'orange', 4, 9, 'baz')) actual = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', lfacet='fruit', rfacet='type') ieq(expect, actual) ieq(expect, actual)
(9, 140, 'e'), (1, 1, 'f'), (2, 2, 'g'), (4, 4, 'h'), (5, 5, 'i'), (1, 8, 'j')) right = (('start', 'stop', 'value'), (1, 4, 'foo'), (3, 7, 'bar'), (4, 9, 'baz')) from petl import look from petlx.interval import intervalleftjoin look(left) look(right) result = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop') look(result) # fromhdf5 # set up a new hdf5 table to work with import tables h5file = tables.openFile("test1.h5", mode="w", title="Test file") h5file.createGroup('/', 'testgroup', 'Test Group') class FooBar(tables.IsDescription): foo = tables.Int32Col(pos=0) bar = tables.StringCol(6, pos=2) h5table = h5file.createTable('/testgroup', 'testtable', FooBar, 'Test Table') # load some data into the table table1 = (('foo', 'bar'),
# intervalleftjoin left = (('begin', 'end', 'quux'), (1, 2, 'a'), (2, 4, 'b'), (2, 5, 'c'), (9, 14, 'd'), (9, 140, 'e'), (1, 1, 'f'), (2, 2, 'g'), (4, 4, 'h'), (5, 5, 'i'), (1, 8, 'j')) right = (('start', 'stop', 'value'), (1, 4, 'foo'), (3, 7, 'bar'), (4, 9, 'baz')) from petl import look from petlx.interval import intervalleftjoin look(left) look(right) result = intervalleftjoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop') look(result) # fromhdf5 # set up a new hdf5 table to work with import tables h5file = tables.openFile("test1.h5", mode="w", title="Test file") h5file.createGroup('/', 'testgroup', 'Test Group') class FooBar(tables.IsDescription): foo = tables.Int32Col(pos=0) bar = tables.StringCol(6, pos=2)