def regionsIntersection(s1, s2, collapse=True):
debug = False<EOL>s1_c = collapseRegions(s1)<EOL>s2_c = collapseRegions(s2)<EOL>if len(s1_c) == <NUM_LIT:0> or len(s2_c) == <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>res = []<EOL>j = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:0>, len(s1_c)):<EOL><INDENT>if debug:<EOL><INDENT>sys.stderr.write("<STR_LIT>" + str(s1_c[i]) + "<STR_LIT:\n>")<EOL><DEDENT>if debug:<EOL><INDENT>sys.stderr.write("<STR_LIT>" + str(i) + "<STR_LIT>" + str(j) + "<STR_LIT:\n>")<EOL><DEDENT>while (j < len(s2_c) and<EOL>(s2_c[j].chrom < s1_c[i].chrom or<EOL>(s2_c[j].chrom == s1_c[i].chrom and s2_c[j].end <= s1_c[i].start))):<EOL><INDENT>j += <NUM_LIT:1><EOL><DEDENT>if j >= len(s2_c) or s2_c[j].chrom > s1_c[i].chrom or(s2_c[j].chrom == s1_c[i].chrom and s2_c[j].start >= s1_c[i].end):<EOL><INDENT>continue<EOL><DEDENT>while s2_c[j].start < s1_c[i].end:<EOL><INDENT>s = max(s1_c[i].start, s2_c[j].start)<EOL>e = min(s1_c[i].end, s2_c[j].end)<EOL>overlap = GenomicInterval(s1_c[i].chrom, s, e, "<STR_LIT:X>", <NUM_LIT:0>, "<STR_LIT:+>")<EOL>if debug:<EOL><INDENT>sys.stderr.write("<STR_LIT>" + str(overlap) + "<STR_LIT:\n>")<EOL><DEDENT>res.append(overlap)<EOL>j += <NUM_LIT:1><EOL>if j >= len(s2_c) or s2_c[j].chrom != s1_c[i].chrom:<EOL><INDENT>break<EOL><DEDENT><DEDENT>j -= <NUM_LIT:1><EOL>if debug:<EOL><INDENT>sys.stderr.write("<STR_LIT>" + str(s2_c[j]) + "<STR_LIT:\n>")<EOL><DEDENT><DEDENT>return res<EOL>
given two lists of genomic regions with chromosome, start and end
coordinates, return a new list of regions which is the intersection of those
two sets. Lists must be sorted by chromosome and start index

:return: new list that represents the intersection of the two input lists.
         output regions will all have name "X", be on strand "+" and have
         score 0
:param s1: first list of genomic regions
:param s2: second list of genomic regions
:raise GenomicIntervalError: if the input regions are not sorted correctly
                             (by chromosome and start index)
:note: O(n) time, O(n) space; informally, might use up to 3x space of input