| 1 | """ |
|---|
| 2 | Tests for `bx.wiggle`. |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | import unittest |
|---|
| 6 | from bx import wiggle |
|---|
| 7 | from StringIO import StringIO |
|---|
| 8 | |
|---|
| 9 | # A modified version of UCSC's example wiggle, taken from http://genome.ucsc.edu/goldenPath/help/wiggleExample.txt |
|---|
| 10 | test_wig = """browser position chr19:59302001-59311000 |
|---|
| 11 | browser hide all |
|---|
| 12 | browser pack refGene encodeRegions |
|---|
| 13 | browser full altGraph |
|---|
| 14 | # 5 base wide bar graph, autoScale is on by default == graphing |
|---|
| 15 | # limits will dynamically change to always show full range of data |
|---|
| 16 | # in viewing window, priority = 20 positions this as the second graph |
|---|
| 17 | # Note, zero-relative, half-open coordinate system in use for bed format |
|---|
| 18 | track type=wiggle_0 name="Bed Format" description="BED format" visibility=full color=200,100,0 altColor=0,100,200 priority=20 |
|---|
| 19 | chr19 59302000 59302005 -1.0 |
|---|
| 20 | chr19 59302300 59302305 -0.75 |
|---|
| 21 | # 4 base wide bar graph at arbitrarily spaced positions, |
|---|
| 22 | # threshold line drawn at y=11.76 |
|---|
| 23 | # autoScale off viewing range set to [0:25] |
|---|
| 24 | # priority = 10 positions this as the first graph |
|---|
| 25 | # Note, one-relative coordinate system in use for this format |
|---|
| 26 | track type=wiggle_0 name="variableStep" description="variableStep format" visibility=full autoScale=off viewLimits=0.0:25.0 color=255,200,0 yLineMark=11.76 yLineOnOff=on priority=10 |
|---|
| 27 | variableStep chrom=chr19 span=4 |
|---|
| 28 | 59304701 10.0 |
|---|
| 29 | 59304901 12.5 |
|---|
| 30 | # 3 base wide points graph at every 300 bases, 50 pixel high graph |
|---|
| 31 | # autoScale off and viewing range set to [0:1000] |
|---|
| 32 | # priority = 30 positions this as the third graph |
|---|
| 33 | # Note, one-relative coordinate system in use for this format |
|---|
| 34 | track type=wiggle_0 name="fixedStep" description="fixed step" visibility=full autoScale=off viewLimits=0:1000 color=0,200,100 maxHeightPixels=100:50:20 graphType=points priority=30 |
|---|
| 35 | fixedStep chrom=chr19 start=59307401 step=300 span=3 |
|---|
| 36 | 1000 |
|---|
| 37 | 900 |
|---|
| 38 | 800 |
|---|
| 39 | """ |
|---|
| 40 | |
|---|
| 41 | interval_reader_result = [ |
|---|
| 42 | "chr19,59302000,59302005,+,-1.0", |
|---|
| 43 | "chr19,59302300,59302305,+,-0.75", |
|---|
| 44 | "chr19,59304700,59304704,+,10.0", |
|---|
| 45 | "chr19,59304900,59304904,+,12.5", |
|---|
| 46 | "chr19,59307400,59307403,+,1000.0", |
|---|
| 47 | "chr19,59307700,59307703,+,900.0", |
|---|
| 48 | "chr19,59308000,59308003,+,800.0" |
|---|
| 49 | ] |
|---|
| 50 | |
|---|
| 51 | position_reader_result = [ |
|---|
| 52 | "chr19,59302000,-1.0", |
|---|
| 53 | "chr19,59302001,-1.0", |
|---|
| 54 | "chr19,59302002,-1.0", |
|---|
| 55 | "chr19,59302003,-1.0", |
|---|
| 56 | "chr19,59302004,-1.0", |
|---|
| 57 | "chr19,59302300,-0.75", |
|---|
| 58 | "chr19,59302301,-0.75", |
|---|
| 59 | "chr19,59302302,-0.75", |
|---|
| 60 | "chr19,59302303,-0.75", |
|---|
| 61 | "chr19,59302304,-0.75", |
|---|
| 62 | "chr19,59304700,10.0", |
|---|
| 63 | "chr19,59304701,10.0", |
|---|
| 64 | "chr19,59304702,10.0", |
|---|
| 65 | "chr19,59304703,10.0", |
|---|
| 66 | "chr19,59304900,12.5", |
|---|
| 67 | "chr19,59304901,12.5", |
|---|
| 68 | "chr19,59304902,12.5", |
|---|
| 69 | "chr19,59304903,12.5", |
|---|
| 70 | "chr19,59307400,1000.0", |
|---|
| 71 | "chr19,59307401,1000.0", |
|---|
| 72 | "chr19,59307402,1000.0", |
|---|
| 73 | "chr19,59307700,900.0", |
|---|
| 74 | "chr19,59307701,900.0", |
|---|
| 75 | "chr19,59307702,900.0", |
|---|
| 76 | "chr19,59308000,800.0", |
|---|
| 77 | "chr19,59308001,800.0", |
|---|
| 78 | "chr19,59308002,800.0" |
|---|
| 79 | ] |
|---|
| 80 | class TestWiggleReader(unittest.TestCase): |
|---|
| 81 | def test_reader(self): |
|---|
| 82 | #Test position reader |
|---|
| 83 | assert position_reader_result == [ ",".join( map( str, value ) ) for value in wiggle.Reader( StringIO( test_wig ) ) ] |
|---|
| 84 | |
|---|
| 85 | def test_interval_reader(self): |
|---|
| 86 | #Test interval reader reader |
|---|
| 87 | assert interval_reader_result == [ ",".join( map( str, value ) ) for value in wiggle.IntervalReader( StringIO( test_wig ) ) ] |
|---|
| 88 | |
|---|
| 89 | if __name__ == '__main__': |
|---|
| 90 | unittest.main() |
|---|