Beispiel #1
0
 def test_index_finder2(self):
     ''' Test finding contiguous unequal bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 10, False))
     self.assertEqual(genomeBin.findBinIndex('chr2', 0), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr2', 1), 5)
     self.assertEqual(genomeBin.findBinIndex('chr2', 9), 5)
     self.assertEqual(genomeBin.findBinIndex('chr2', 10), 6)
     self.assertEqual(genomeBin.findBinIndex('chr2', 25), 7)
     self.assertEqual(genomeBin.findBinIndex('chr2', 26), 8)
     self.assertEqual(genomeBin.findBinIndex('chr2', 33), 8)
     self.assertEqual(genomeBin.findBinIndex('chr2', 34), 'nobin')
Beispiel #2
0
 def test_index_finder1(self):
     ''' Test finding non contiguous bins '''
     genomeBin = interactionMatrix.genomeBin(self.inBed1)
     self.assertEqual(genomeBin.findBinIndex('chr1', 10), 0)
     self.assertEqual(genomeBin.findBinIndex('chr1', 9), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr1', 30), 1)
     self.assertEqual(genomeBin.findBinIndex('chr1', 29), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr1', 20), 0)
     self.assertEqual(genomeBin.findBinIndex('chr1', 21), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr1', 40), 1)
     self.assertEqual(genomeBin.findBinIndex('chr1', 41), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr3', 10), 'nochr')
Beispiel #3
0
 def test_matrix_generation(self):
     ''' Test creation of matrix '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 10, True))
     countMatrix, logArray = genomeBin.generateMatrix(self.inFrag,
                                                      threads=4)
     self.assertTrue(
         np.array_equal(
             countMatrix,
             np.array([[2, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0],
                       [0, 0, 0, 0, 2, 0, 0], [0, 1, 0, 0, 0, 0, 0],
                       [0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
                       [1, 0, 0, 0, 0, 0, 0]])))
     self.assertTrue(np.array_equal(logArray, np.array([10, 2, 3, 5])))
Beispiel #4
0
 def test_bin_generation3(self):
     ''' Test unequal bin creation with large bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 40, False))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['start'] == np.array(
             [1, 24], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['end'] == np.array([23, 46],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['index'] == np.array(
             [0, 1], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['start'] == np.array(
             [1], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['end'] == np.array([33],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['index'] == np.array(
             [2], dtype=np.uint32)))
Beispiel #5
0
 def test_bin_generation2(self):
     ''' Test unequal bin creation with small bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 11, False))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['start'] == np.array(
             [1, 11, 20, 29, 38], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['end'] == np.array(
             [10, 19, 28, 37, 46], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['index'] == np.array(
             [0, 1, 2, 3, 4], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['start'] == np.array(
             [1, 12, 23], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['end'] == np.array([11, 22, 33],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['index'] == np.array(
             [5, 6, 7], dtype=np.uint32)))
Beispiel #6
0
 def test_bin_generation7(self):
     ''' Test bin creation from bed file '''
     genomeBin = interactionMatrix.genomeBin(self.inBed1)
     self.assertTrue(
         all(genomeBin.binDict['chr1']['start'] == np.array(
             [10, 30], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['end'] == np.array([20, 40],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['index'] == np.array(
             [0, 1], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['start'] == np.array(
             [5], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['end'] == np.array([15],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['index'] == np.array(
             [2], dtype=np.uint32)))
Beispiel #7
0
 def test_bin_generation6(self):
     ''' Test unequal bin creation with small bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 41, True))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['start'] == np.array(
             [3], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['end'] == np.array([43],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['index'] == np.array(
             [0], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['start'] == np.array(
             [], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['end'] == np.array([],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['index'] == np.array(
             [], dtype=np.uint32)))
Beispiel #8
0
 def test_bin_generation6(self):
     ''' Test unequal bin creation with small bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 41, True))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['start'] == np.array(
             [2, 13, 24, 35], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['end'] == np.array([12, 23, 34, 45],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr1']['index'] == np.array(
             [0, 1, 2, 3], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['start'] == np.array(
             [1, 12, 23], dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['end'] == np.array([11, 22, 33],
                                                          dtype=np.uint32)))
     self.assertTrue(
         all(genomeBin.binDict['chr2']['index'] == np.array(
             [4, 5, 6], dtype=np.uint32)))
elif args.chrSize and args.binSize:
    binData = (args.chrSize, args.binSize, args.equal)
    print 'Parameters:\n\t%s\n\t%s\n\t%s' %(
        'max bin size: %s' %(args.binSize),
        'bin size equal: %s' %(args.equal),
        'minimum bin count: %s' %(args.minCount)
    )
else:
    raise IOError('bed file or chromosome file and bin size must be provided')
# Create output files
args.bedFile = args.outPrefix + '.bed'
args.biasFile = args.outPrefix + '.bias'
args.countMatrix = args.outPrefix + '.countMatrix'
args.normMatrix = args.outPrefix + '.normMatrix'
# Create bin object and save bed
genomeBins = interactionMatrix.genomeBin(binData)
genomeBins.writeBed(args.bedFile)
# Count interactions
countMatrix, logArray = interactionMatrix.generateMatrix(
    args.inFile, genomeBins, args.threads
)
# Save interactions
np.savetxt(args.countMatrix, countMatrix, '%s', '\t',
    header = '\t'.join(genomeBins.binNames), comments = '')
# Print Interaction Data
print '\nInteraction Data\n\t%s\n\t%s\n\t%s\n\t%s' %(
    'total: %s' %(logArray[0]),
    'accepted: %s' %(logArray[3]),
    'no chromosome: %s' %(logArray[1]),
    'no bin: %s' %(logArray[2])
)
                                       'minimum bin count: %s' %
                                       (args.minCount))
elif args.chrSize and args.binSize:
    binData = (args.chrSize, args.binSize, args.equal)
    print 'Parameters:\n\t%s\n\t%s\n\t%s' % (
        'max bin size: %s' % (args.binSize), 'bin size equal: %s' %
        (args.equal), 'minimum bin count: %s' % (args.minCount))
else:
    raise IOError('bed file or chromosome file and bin size must be provided')
# Create output files
args.bedFile = args.outPrefix + '.bed'
args.biasFile = args.outPrefix + '.bias'
args.countMatrix = args.outPrefix + '.countMatrix'
args.normMatrix = args.outPrefix + '.normMatrix'
# Create bin object and save bed
genomeBins = interactionMatrix.genomeBin(binData)
genomeBins.writeBed(args.bedFile)
# Count interactions
countMatrix, logArray = interactionMatrix.generateMatrix(
    args.inFile, genomeBins, args.threads)
# Save interactions
np.savetxt(args.countMatrix,
           countMatrix,
           '%s',
           '\t',
           header='\t'.join(genomeBins.binNames),
           comments='')
# Print Interaction Data
print '\nInteraction Data\n\t%s\n\t%s\n\t%s\n\t%s' % (
    'total: %s' % (logArray[0]), 'accepted: %s' %
    (logArray[3]), 'no chromosome: %s' % (logArray[1]), 'no bin: %s' %
Beispiel #11
0
 def test_index_finder3(self):
     ''' Test finding contiguous equal bins '''
     genomeBin = interactionMatrix.genomeBin((self.chrFile, 10, True))
     self.assertEqual(genomeBin.findBinIndex('chr1', 1), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr2', 32), 'nobin')
     self.assertEqual(genomeBin.findBinIndex('chr2', 31), 6)
Beispiel #12
0
 def test_bin_generation8(self):
     ''' Test overlapping bins in bed file '''
     with self.assertRaises(IOError):
         interactionMatrix.genomeBin(self.inBed2)