'''
Created on Jun 4, 2010

@author: sau
'''
import unittest
from erange import makebedfromrds


class TestMakeBedFromRds(unittest.TestCase):

    def testGetSenseColor(self):
        senseColor = makebedfromrds.getSenseColor('+', .5)
        self.assertEqual(senseColor, makebedfromrds.MULTI_PLUS_COLOR, "incorrect color for low weight and plus sense color")

        senseColor = makebedfromrds.getSenseColor('-', .5)
        self.assertEqual(senseColor, makebedfromrds.MULTI_MINUS_COLOR, "incorrect color for low weight and non-plus sense")

        senseColor = makebedfromrds.getSenseColor('+', 5)
        self.assertEqual(senseColor, makebedfromrds.PLUS_COLOR, "incorrect color for high weight and plus sense")

        senseColor = makebedfromrds.getSenseColor('-', 5)
        self.assertEqual(senseColor, makebedfromrds.MINUS_COLOR, "incorrect color for high weight and non-plus sense")


    def testGetMultiSenseColor(self):
        senseColor = makebedfromrds.getMultiSenseColor('+')
        self.assertEqual(senseColor, makebedfromrds.MULTI_PLUS_COLOR, "incorrect color for plus sense")

        senseColor = makebedfromrds.getMultiSenseColor('-')
        self.assertEqual(senseColor, makebedfromrds.MULTI_MINUS_COLOR, "incorrect color for non-plus sense")


    def testGetSingleSenseColor(self):
        senseColor = makebedfromrds.getSingleSenseColor('+')
        self.assertEqual(senseColor, makebedfromrds.PLUS_COLOR, "incorrect color for plus sense")

        senseColor = makebedfromrds.getSingleSenseColor('-')
        self.assertEqual(senseColor, makebedfromrds.MINUS_COLOR, "incorrect color for non-plus sense")


    def testGetReadSizes(self):
        numPieces = 3
        startList = [0, 1, 2]
        stopList = [3, 4, 5]
        readSizes = makebedfromrds.getReadSizes(numPieces, startList, stopList)
        self.assertEqual(readSizes, "3,3,3", "incorrect read size list")
        
        readSizes = makebedfromrds.getReadSizes(1, startList, stopList)
        self.assertEquals(readSizes, "3", "incorrect read size list for numPieces=1")
        
        self.assertRaises(IndexError, makebedfromrds.getReadSizes, numPieces, [], stopList)
        self.assertRaises(IndexError, makebedfromrds.getReadSizes, numPieces, startList, [])
        self.assertRaises(IndexError, makebedfromrds.getReadSizes, 4, startList, stopList)


    def testGetReadCoords(self):
        numPieces = 3
        startList = [0, 1, 2]
        readCoords = makebedfromrds.getReadCoords(numPieces, startList)
        self.assertEqual(readCoords, "0,1,2", "incorrect read coords list")
        
        readCoords = makebedfromrds.getReadCoords(1, startList)
        self.assertEqual(readCoords, "0", "incorrect read coords list for numPieces=1")
        
        self.assertRaises(IndexError, makebedfromrds.getReadCoords, numPieces, [])
        self.assertRaises(IndexError, makebedfromrds.getReadCoords, 4, startList)


    def testGetSpliceColor(self):
        lpart = 1
        rpart = 2
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.SPLICE_COLOR, "incorrect first color for hacktype 1 splice")
        self.assertEqual(bColor, makebedfromrds.SPLICE_COLOR, "incorrect second color for hacktype 1 splice")
        
        lpart = 0
        rpart = 0
        leftweight = 1.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.UNIQUE_COLOR, "incorrect first color for hacktype 1 left unique")
        self.assertEqual(bColor, makebedfromrds.UNIQUE_COLOR, "incorrect second color for hacktype 1 left unique")
        
        lpart = 0
        rpart = 0
        leftweight = 0.0
        rightweight = 1.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.UNIQUE_COLOR, "incorrect first color for hacktype 1 right unique")
        self.assertEqual(bColor, makebedfromrds.UNIQUE_COLOR, "incorrect second color for hacktype 1 right unique")
        
        lpart = 0
        rpart = 0
        leftweight = 1.0
        rightweight = 1.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.UNIQUE_COLOR, "incorrect first color for hacktype 1 left and right unique")
        self.assertEqual(bColor, makebedfromrds.UNIQUE_COLOR, "incorrect second color for hacktype 1 left and right unique")
        
        lpart = 0
        rpart = 0
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.MULTI_COLOR, "incorrect first color for hacktype 1 multi")
        self.assertEqual(bColor, makebedfromrds.MULTI_COLOR, "incorrect second color for hacktype 1 multi")
        
        lpart = 1
        rpart = 1
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight, hackType="1")
        self.assertEqual(aColor, makebedfromrds.MULTI_COLOR, "incorrect first color for hacktype 1 lpart + rpart = 2")
        self.assertEqual(bColor, makebedfromrds.MULTI_COLOR, "incorrect second color for hacktype 1 lpart + rpart = 2")
        
        lpart = 2
        rpart = 0
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight)
        self.assertEqual(aColor, makebedfromrds.SPLICE_COLOR, "incorrect first color for left splice")
        self.assertEqual(bColor, makebedfromrds.SPLICE_COLOR, "incorrect second color for left splice")
        
        lpart = 0
        rpart = 0
        leftweight = 1.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight)
        self.assertEqual(aColor, makebedfromrds.UNIQUE_COLOR, "incorrect first color for left unique")
        self.assertEqual(bColor, makebedfromrds.UNIQUE_COLOR, "incorrect second color for left unique")
        
        lpart = 0
        rpart = 0
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight)
        self.assertEqual(aColor, makebedfromrds.MULTI_COLOR, "incorrect first color for multi splice")
        self.assertEqual(bColor, makebedfromrds.MULTI_COLOR, "incorrect second color for multi splice")
        
        lpart = 1
        rpart = 0
        leftweight = 0.0
        rightweight = 0.0
        aColor, bColor = makebedfromrds.getSpliceColor(lpart, rpart, leftweight, rightweight)
        self.assertEqual(aColor, makebedfromrds.MULTI_COLOR, "incorrect first color for lpart = 1 multi splice")
        self.assertEqual(bColor, makebedfromrds.MULTI_COLOR, "incorrect second color for lpart = 1 multi splice")


    def testDoNotOutputChromosome(self):
        self.assertTrue(makebedfromrds.doNotOutputChromosome("chrM", True), "chrM is output when enforceChr=True")
        self.assertTrue(makebedfromrds.doNotOutputChromosome("chrM", False), "chrM is output when enforceChr=False")
        self.assertFalse(makebedfromrds.doNotOutputChromosome("chrAny", True), "chr is not output when enforceChr=True")
        self.assertFalse(makebedfromrds.doNotOutputChromosome("chrAny", False), "chr is not output when enforceChr=False")
        self.assertTrue(makebedfromrds.doNotOutputChromosome("Bad", True), "bad name chr is output when enforceChr=True")
        self.assertFalse(makebedfromrds.doNotOutputChromosome("Bad", False), "bad name chr is not output when enforceChr=True")


def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestMakeBedFromRds))

    return suite


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()