def testRegionsIntersection(self):
    """Test getting the intersection of a set of regions."""
    debug = False
    s1_elements = ["\t".join(["chr1", "40", "90", "R11", "0", "+"]),
                   "\t".join(["chr1", "100", "120", "R12", "3", "+"]),
                   "\t".join(["chr1", "160", "190", "R13", "1", "-"]),
                   "\t".join(["chr1", "200", "210", "R14", "0", "-"]),
                   "\t".join(["chr2", "10", "20", "R15", "0", "-"]),
                   "\t".join(["chr3", "10", "80", "R16", "1", "+"]),
                   "\t".join(["chr4", "20", "30", "R17", "1", "+"]),
                   "\t".join(["chr4", "40", "50", "R18", "1", "-"]),
                   "\t".join(["chr5", "40", "50", "R19", "1", "-"])]
    s2_elements = ["chr1" + "\t" + "10" + "\t" + "20" + "\t" + "R21" + "\t" +
                   "0" + "\t" + "+",
                   "chr1" + "\t" + "30" + "\t" + "50" + "\t" + "R22" + "\t" +
                   "1" + "\t" + "-",
                   "chr1" + "\t" + "60" + "\t" + "70" + "\t" + "R23" + "\t" +
                   "0" + "\t" + "+",
                   "chr1" + "\t" + "80" + "\t" + "110" + "\t" + "R24" + "\t" +
                   "4" + "\t" + "+",
                   "chr1" + "\t" + "130" + "\t" + "140" + "\t" + "R25" + "\t" +
                   "0" + "\t" + "+",
                   "chr1" + "\t" + "150" + "\t" + "170" + "\t" + "R26" + "\t" +
                   "1" + "\t" + "-",
                   "chr1" + "\t" + "180" + "\t" + "220" + "\t" + "R27" + "\t" +
                   "0" + "\t" + "-",
                   "chr2" + "\t" + "30" + "\t" + "40" + "\t" + "R28" + "\t" +
                   "0" + "\t" + "-",
                   "chr3" + "\t" + "20" + "\t" + "30" + "\t" + "R29" + "\t" +
                   "0" + "\t" + "-",
                   "chr3" + "\t" + "40" + "\t" + "50" + "\t" + "R210" + "\t" +
                   "0" + "\t" + "-",
                   "chr3" + "\t" + "60" + "\t" + "70" + "\t" + "R211" + "\t" +
                   "0" + "\t" + "+",
                   "chr4" + "\t" + "10" + "\t" + "60" + "\t" + "R212" + "\t" +
                   "0" + "\t" + "+",
                   "chr5" + "\t" + "10" + "\t" + "20" + "\t" + "R213" + "\t" +
                   "1" + "\t" + "-"]
    expect_str = ["chr1" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "60" + "\t" + "70" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "80" + "\t" + "90" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "100" + "\t" + "110" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "160" + "\t" + "170" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "180" + "\t" + "190" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr1" + "\t" + "200" + "\t" + "210" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr3" + "\t" + "20" + "\t" + "30" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr3" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr3" + "\t" + "60" + "\t" + "70" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr4" + "\t" + "20" + "\t" + "30" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+",
                  "chr4" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" +
                  "0" + "\t" + "+"]
    input_s1 = [parseBEDString(x) for x in s1_elements]
    input_s2 = [parseBEDString(x) for x in s2_elements]
    expect = [parseBEDString(x) for x in expect_str]
    got = regionsIntersection(input_s1, input_s2)
    if debug:
      sys.stderr.write("expect:\n")
      sys.stderr.write("\n".join([str(x) for x in expect]) + "\n")
      sys.stderr.write("got:\n")
      sys.stderr.write("\n".join([str(x) for x in got]) + "\n")
    self.assertEqual(expect, got)
def testRegionsIntersection ( self ) : debug = False s1_elements = [ "\t" . join ( [ "chr1" , "40" , "90" , "R11" , "0" , "+" ] ) , "\t" . join ( [ "chr1" , "100" , "120" , "R12" , "3" , "+" ] ) , "\t" . join ( [ "chr1" , "160" , "190" , "R13" , "1" , "-" ] ) , "\t" . join ( [ "chr1" , "200" , "210" , "R14" , "0" , "-" ] ) , "\t" . join ( [ "chr2" , "10" , "20" , "R15" , "0" , "-" ] ) , "\t" . join ( [ "chr3" , "10" , "80" , "R16" , "1" , "+" ] ) , "\t" . join ( [ "chr4" , "20" , "30" , "R17" , "1" , "+" ] ) , "\t" . join ( [ "chr4" , "40" , "50" , "R18" , "1" , "-" ] ) , "\t" . join ( [ "chr5" , "40" , "50" , "R19" , "1" , "-" ] ) ] s2_elements = [ "chr1" + "\t" + "10" + "\t" + "20" + "\t" + "R21" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "30" + "\t" + "50" + "\t" + "R22" + "\t" + "1" + "\t" + "-" , "chr1" + "\t" + "60" + "\t" + "70" + "\t" + "R23" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "80" + "\t" + "110" + "\t" + "R24" + "\t" + "4" + "\t" + "+" , "chr1" + "\t" + "130" + "\t" + "140" + "\t" + "R25" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "150" + "\t" + "170" + "\t" + "R26" + "\t" + "1" + "\t" + "-" , "chr1" + "\t" + "180" + "\t" + "220" + "\t" + "R27" + "\t" + "0" + "\t" + "-" , "chr2" + "\t" + "30" + "\t" + "40" + "\t" + "R28" + "\t" + "0" + "\t" + "-" , "chr3" + "\t" + "20" + "\t" + "30" + "\t" + "R29" + "\t" + "0" + "\t" + "-" , "chr3" + "\t" + "40" + "\t" + "50" + "\t" + "R210" + "\t" + "0" + "\t" + "-" , "chr3" + "\t" + "60" + "\t" + "70" + "\t" + "R211" + "\t" + "0" + "\t" + "+" , "chr4" + "\t" + "10" + "\t" + "60" + "\t" + "R212" + "\t" + "0" + "\t" + "+" , "chr5" + "\t" + "10" + "\t" + "20" + "\t" + "R213" + "\t" + "1" + "\t" + "-" ] expect_str = [ "chr1" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "60" + "\t" + "70" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "80" + "\t" + "90" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "100" + "\t" + "110" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "160" + "\t" + "170" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "180" + "\t" + "190" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr1" + "\t" + "200" + "\t" + "210" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr3" + "\t" + "20" + "\t" + "30" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr3" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr3" + "\t" + "60" + "\t" + "70" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr4" + "\t" + "20" + "\t" + "30" + "\t" + "X" + "\t" + "0" + "\t" + "+" , "chr4" + "\t" + "40" + "\t" + "50" + "\t" + "X" + "\t" + "0" + "\t" + "+" ] input_s1 = [ parseBEDString ( x ) for x in s1_elements ] input_s2 = [ parseBEDString ( x ) for x in s2_elements ] expect = [ parseBEDString ( x ) for x in expect_str ] got = regionsIntersection ( input_s1 , input_s2 ) if debug : sys . stderr . write ( "expect:\n" ) sys . stderr . write ( "\n" . join ( [ str ( x ) for x in expect ] ) + "\n" ) sys . stderr . write ( "got:\n" ) sys . stderr . write ( "\n" . join ( [ str ( x ) for x in got ] ) + "\n" ) self . assertEqual ( expect , got )
Test getting the intersection of a set of regions.