diff --git a/pygenometracks/tests/generateAllOutput.sh b/pygenometracks/tests/generateAllOutput.sh index 92350ec5..deeb1fac 100644 --- a/pygenometracks/tests/generateAllOutput.sh +++ b/pygenometracks/tests/generateAllOutput.sh @@ -34,6 +34,7 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --region c bin/pgt --tracks ./pygenometracks/tests/test_data/operation_bdg.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_operation_bdg.png bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_withNA.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_withNA.png bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_negative.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_negative.png +bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_end_not_covered.ini --region chr7:100-400 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_end_not_covered.png # test bigWigTrack: bin/pgt --tracks ./pygenometracks/tests/test_data/bigwig.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bigwig.png diff --git a/pygenometracks/tests/test_bedGraphTrack.py b/pygenometracks/tests/test_bedGraphTrack.py index b488fdc7..c889522b 100644 --- a/pygenometracks/tests/test_bedGraphTrack.py +++ b/pygenometracks/tests/test_bedGraphTrack.py @@ -214,6 +214,18 @@ with open(os.path.join(ROOT, "log1pm_bedgraph.ini"), 'w') as fh: fh.write(log1p_with_neg) + +bedgraph_end_not_covered = """ +[bedgraph] +file = simple.bdg +height = 3 +summary_method = max + +[x-axis] +""" +with open(os.path.join(ROOT, "bedgraph_end_not_covered.ini"), 'w') as fh: + fh.write(bedgraph_end_not_covered) + tolerance = 13 # default matplotlib pixed difference tolerance @@ -427,3 +439,19 @@ def test_bedgraph_neg_log1p(): os.remove(ini_file) os.remove(os.path.join(ROOT, "bedgraph_chrx_2e6_5e6_m.bg")) + + +def test_bedgraph_end_not_covered(): + region = "chr7:100-400" + outfile = NamedTemporaryFile(suffix='.png', prefix='bedgraph_end_not_covered_', delete=False) + args = "--tracks {ini} --region {region} --trackLabelFraction 0.2 " \ + "--dpi 130 --outFileName {outfile}" \ + "".format(ini=os.path.join(ROOT, "bedgraph_end_not_covered.ini"), + outfile=outfile.name, region=region).split() + pygenometracks.plotTracks.main(args) + print("saving test to {}".format(outfile.name)) + res = compare_images(os.path.join(ROOT, 'master_bedgraph_end_not_covered.png'), + outfile.name, tolerance) + assert res is None, res + + os.remove(outfile.name) diff --git a/pygenometracks/tests/test_data/bedgraph_end_not_covered.ini b/pygenometracks/tests/test_data/bedgraph_end_not_covered.ini new file mode 100644 index 00000000..fbaa6f10 --- /dev/null +++ b/pygenometracks/tests/test_data/bedgraph_end_not_covered.ini @@ -0,0 +1,7 @@ + +[bedgraph] +file = simple.bdg +height = 3 +summary_method = max + +[x-axis] diff --git a/pygenometracks/tests/test_data/master_bedgraph_end_not_covered.png b/pygenometracks/tests/test_data/master_bedgraph_end_not_covered.png new file mode 100644 index 00000000..81facbd7 Binary files /dev/null and b/pygenometracks/tests/test_data/master_bedgraph_end_not_covered.png differ diff --git a/pygenometracks/tests/test_data/simple.bdg b/pygenometracks/tests/test_data/simple.bdg new file mode 100644 index 00000000..bdb29041 --- /dev/null +++ b/pygenometracks/tests/test_data/simple.bdg @@ -0,0 +1,6 @@ +track type=bedGraph name="400-404notIncluded" +chr7 100 200 1 +chr7 200 300 2 +chr7 300 350 3 +chr7 350 399 4 +chr7 405 450 5 diff --git a/pygenometracks/tracks/BedGraphTrack.py b/pygenometracks/tracks/BedGraphTrack.py index 44363426..46b5e496 100644 --- a/pygenometracks/tracks/BedGraphTrack.py +++ b/pygenometracks/tracks/BedGraphTrack.py @@ -229,7 +229,7 @@ def get_scores(self, chrom_region, start_region, end_region, return_nans=True, tbx_var='self.tbx', inttree_var='self.interval_tree'): """ Retrieves the score (or scores or whatever fields are in a bedgraph like file) and the positions - for a given region. + for a given region. If return_nans is True the pos_list goes until at least end_region. In case there is no item in the region. It returns [], [] Args: chrom_region: @@ -237,7 +237,7 @@ def get_scores(self, chrom_region, start_region, end_region, end_region: Returns: tuple: - scores_list, post_list + scores_list, pos_list """ score_list = [] pos_list = [] @@ -288,6 +288,11 @@ def get_scores(self, chrom_region, start_region, end_region, score_list.append(values) pos_list.append((start, end)) + # Add a last value if needed: + if prev_end < end_region and return_nans: + score_list.append(np.repeat(np.nan, self.num_fields)) + pos_list.append((prev_end, end_region)) + return score_list, pos_list def plot(self, ax, chrom_region, start_region, end_region):