def test_array_to_bedgraph_span_zeros(self):
     a = np.zeros((10000,1), dtype=np.float)
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output, span=1)
     contents = getvalue(output)        
     self.assertTrue(np.array_equal(contents['chr1'], a[:,0]))
     os.remove(filename)
 def test_array_to_bedgraph_consecutive(self):
     a = np.arange(0, 100, dtype=np.float)
     a.resize((a.shape[0],1))
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output)
     contents = getvalue(output)
     self.assertTrue(np.array_equal(contents['chr1'], a[:,0]))
     os.remove(filename)
 def test_array_to_bedgraph_zeros(self):
     a = np.array([0, 0, 0, 0, 0])
     a.resize((a.shape[0],1))
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output)
     contents = getvalue(output)
     self.assertTrue(np.array_equal(contents['chr1'], a[:,0]))
     os.remove(filename)        
 def test_array_to_bedgraph_sparse_spans(self):
     a = np.zeros((10000,1), dtype=np.float)
     a[6655] = 100
     # check that spans work too
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output, span=10)
     contents = getvalue(output)
     correct = np.zeros(10000, dtype=np.float)
     correct[6650:6660] = 10
     self.assertTrue(np.array_equal(contents['chr1'], correct))
     os.remove(filename)
 def test_array_to_bedgraph_span_jumps(self):
     a = np.array([0, 0, 2, 2, 0, 0, 4, 4, 0, 0, 0, 0, 10, 10, 10, 10], dtype=np.float)
     a.resize((a.shape[0],1))
     # span of 2
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output, span=2)
     contents = getvalue(output)
     self.assertTrue(np.array_equal(contents['chr1'], a[:,0]))
     os.remove(filename)
     # span of 4
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output, span=4)
     contents = getvalue(output)
     correct = np.array([1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0, 10, 10, 10, 10])
     self.assertTrue(np.array_equal(contents['chr1'], correct))
     os.remove(filename)
 def test_array_dtypes(self):
     # float
     a = np.array([1.25, 2.01, 3.98, 10.1, 4.02], dtype=np.float32)
     a.resize((a.shape[0],1))
     output, filename = make_temp()
     array_to_bedgraph('chr1', a, output)
     contents = getvalue(output)
     self.assertTrue(np.array_equal(contents['chr1'], a[:,0]))
     os.remove(filename)
     # int
     b = np.array([1.25, 2.01, 3.98, 10.1, 4.02], dtype=np.int32)
     b.resize((b.shape[0],1))
     bcorrect = np.array([1, 2, 3, 10, 4], dtype=np.int32)
     bcorrect.resize((b.shape[0],1))
     output, filename = make_temp()
     array_to_bedgraph('chr1', b, output)
     contents = getvalue(output)
     self.assertTrue(np.array_equal(contents['chr1'], bcorrect[:,0]))
     os.remove(filename)