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 gff3join(table, features, seqid='seqid', start='start', end='end', proximity=1): """ Join with a table of GFF3 features. See also :func:`petlx.interval.intervaljoin`. .. versionadded:: 0.2 """ return intervaljoin(table, features, lstart=start, lstop=end, lfacet=seqid, rstart='start', rstop='end', rfacet='seqid', proximity=proximity)
def test_intervaljoin_proximity(): 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 = intervaljoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop', proximity=1) expect = (('begin', 'end', 'quux', 'start', 'stop', 'value'), (1, 2, 'a', 1, 4, 'foo'), (2, 4, 'b', 1, 4, 'foo'), (2, 4, 'b', 3, 7, 'bar'), (2, 4, 'b', 4, 9, 'baz'), (2, 5, 'c', 1, 4, 'foo'), (2, 5, 'c', 3, 7, 'bar'), (2, 5, 'c', 4, 9, 'baz'), (9, 14, 'd', 4, 9, 'baz'), (9, 140, 'e', 4, 9, 'baz'), (1, 1, 'f', 1, 4, 'foo'), (2, 2, 'g', 1, 4, 'foo'), (4, 4, 'h', 1, 4, 'foo'), (4, 4, 'h', 3, 7, 'bar'), (4, 4, 'h', 4, 9, 'baz'), (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_intervaljoin_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'), ('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 = intervaljoin(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 intervaljoin look(left) look(right) result = intervaljoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop') look(result) # intervaljoin with facet 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),
lkp['orange'][8] # intervaljoin 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 intervaljoin look(left) look(right) result = intervaljoin(left, right, lstart='begin', lstop='end', rstart='start', rstop='stop') look(result) # intervaljoin with facet 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')) from petl import look from petlx.interval import intervaljoin