Ejemplo n.º 1
0
    def testExtra(self):
        tf = TrackFormat.createInstanceFromPrefixList(["start", "a", "b", "c"], "float64", 1, "float64", 1)
        self.assertTrue(tf.hasExtra(specificExtra="a"))
        self.assertFalse(tf.hasExtra(specificExtra="d"))

        self.assertEqual(["a", "b", "c"], tf.getExtraNames())

        tfq = TrackFormatReq(interval=False, extra=["a", "b"])
        self.assertFalse(tfq.isCompatibleWith(tf))
    def _assertConvertSegmentToPoint(self, targetStarts, sourceTv, converterCls):
        pointFormat = TrackFormatReq(interval=False, dense=False)
        self.assertTrue(converterCls.canHandle(sourceTv.trackFormat, pointFormat))
 
        targetTv = converterCls.convert(sourceTv)
        self.assertTrue(pointFormat.isCompatibleWith(targetTv.trackFormat))
            
        self.assertEqual(targetStarts, [el.start() for el in targetTv])
        for el in targetTv:
            self.assertEqual(el.start() + 1, el.end())
Ejemplo n.º 3
0
    def testValTypes(self):
        tf = TrackFormat.createInstanceFromPrefixList(["start", "val"], "float128", 2, "float64", 1)

        self.assertTrue(tf.isValued(specificValType="mean_sd"))
        self.assertFalse(tf.isValued(specificValType="number"))

        self.assertEqual("Mean and std.dev.", tf.getValTypeName())
        self.assertEqual("Valued points", tf.getFormatName())

        tfq = TrackFormatReq(interval=False, val="tc")
        self.assertFalse(tfq.isCompatibleWith(tf))
Ejemplo n.º 4
0
    def testWeightTypes(self):
        tf = TrackFormat.createInstanceFromPrefixList(["id", "edges", "weights"], "float64", 1, "S8", 3)

        self.assertTrue(tf.isWeighted(specificWeightType="category_vector"))
        self.assertFalse(tf.isWeighted(specificWeightType="number"))

        self.assertEqual("Vector of categories", tf.getWeightTypeName())
        self.assertEqual("Linked base pairs", tf.getFormatName())

        tfq = TrackFormatReq(linked=True, weights="number")
        self.assertFalse(tfq.isCompatibleWith(tf))
Ejemplo n.º 5
0
    def testExtra(self):
        tf = TrackFormat.createInstanceFromPrefixList(['start', 'a', 'b', 'c'],
                                                      'float64', 1, 'float64',
                                                      1)
        self.assertTrue(tf.hasExtra(specificExtra='a'))
        self.assertFalse(tf.hasExtra(specificExtra='d'))

        self.assertEqual(['a', 'b', 'c'], tf.getExtraNames())

        tfq = TrackFormatReq(interval=False, extra=['a', 'b'])
        self.assertFalse(tfq.isCompatibleWith(tf))
    def _assertConvertSegmentToPoint(self, targetStarts, sourceTv,
                                     converterCls):
        pointFormat = TrackFormatReq(interval=False, dense=False)
        self.assertTrue(
            converterCls.canHandle(sourceTv.trackFormat, pointFormat))

        targetTv = converterCls.convert(sourceTv)
        self.assertTrue(pointFormat.isCompatibleWith(targetTv.trackFormat))

        self.assertEqual(targetStarts, [el.start() for el in targetTv])
        for el in targetTv:
            self.assertEqual(el.start() + 1, el.end())
Ejemplo n.º 7
0
    def testWeightTypes(self):
        tf = TrackFormat.createInstanceFromPrefixList(
            ['id', 'edges', 'weights'], 'float64', 1, 'S8', 3)

        self.assertTrue(tf.isWeighted(specificWeightType='category_vector'))
        self.assertFalse(tf.isWeighted(specificWeightType='number'))

        self.assertEqual('Vector of categories', tf.getWeightTypeName())
        self.assertEqual('Linked base pairs', tf.getFormatName())

        tfq = TrackFormatReq(linked=True, weights='number')
        self.assertFalse(tfq.isCompatibleWith(tf))
Ejemplo n.º 8
0
    def testCompatibilityWithExceptions(self):
        tf = TrackFormat.createInstanceFromPrefixList(['start', 'val'],
                                                      'float64', 1, 'float64',
                                                      1)

        self.assertFalse(TrackFormatReq(interval=True, strand=True, val='number')\
                         .isCompatibleWith(tf))
        self.assertFalse(TrackFormatReq(interval=True, strand=True, val='number')\
                         .isCompatibleWith(tf, ['interval']))
        self.assertTrue(TrackFormatReq(interval=True, strand=True, val='number')\
                        .isCompatibleWith(tf, ['interval', 'hasStrand']))
        self.assertFalse(TrackFormatReq(interval=True, strand=True, val='tc')\
                         .isCompatibleWith(tf, ['interval', 'hasStrand']))
Ejemplo n.º 9
0
    def testValTypes(self):
        tf = TrackFormat.createInstanceFromPrefixList(['start', 'val'],
                                                      'float128', 2, 'float64',
                                                      1)

        self.assertTrue(tf.isValued(specificValType='mean_sd'))
        self.assertFalse(tf.isValued(specificValType='number'))

        self.assertEqual('Mean and std.dev.', tf.getValTypeName())
        self.assertEqual('Valued points', tf.getFormatName())

        tfq = TrackFormatReq(interval=False, val='tc')
        self.assertFalse(tfq.isCompatibleWith(tf))
Ejemplo n.º 10
0
    def testMerge(self):
        mergedTFR = TrackFormatReq.merge(TrackFormatReq(dense=False), TrackFormatReq(interval=True))
        self.assertFalse(mergedTFR.isDense())
        self.assertTrue(mergedTFR.isInterval())

        mergedTFR = TrackFormatReq.merge(
            TrackFormatReq(dense=False, val="tc"), TrackFormatReq(interval=True, val="number")
        )
        self.assertEqual(None, mergedTFR)

        mergedTFR = TrackFormatReq.merge(
            TrackFormatReq(dense=False, weights="tc"), TrackFormatReq(interval=True, weights="number")
        )
        self.assertEqual(None, mergedTFR)
Ejemplo n.º 11
0
 def addFormatReq(self, requestedTrackFormat):
     prevFormatReq = self._trackFormatReq
     self._trackFormatReq = TrackFormatReq.merge(self._trackFormatReq,
                                                 requestedTrackFormat)
     if self._trackFormatReq is None:
         raise IncompatibleTracksError(str(prevFormatReq ) + \
                                       ' is incompatible with additional ' + str(requestedTrackFormat))
Ejemplo n.º 12
0
    def testMerge(self):
        mergedTFR = TrackFormatReq.merge(TrackFormatReq(dense=False),
                                         TrackFormatReq(interval=True))
        self.assertFalse(mergedTFR.isDense())
        self.assertTrue(mergedTFR.isInterval())

        mergedTFR = TrackFormatReq.merge(
            TrackFormatReq(dense=False, val='tc'),
            TrackFormatReq(interval=True, val='number'))
        self.assertEqual(None, mergedTFR)

        mergedTFR = TrackFormatReq.merge(
            TrackFormatReq(dense=False, weights='tc'),
            TrackFormatReq(interval=True, weights='number'))
        self.assertEqual(None, mergedTFR)
Ejemplo n.º 13
0
    def _assertFunctions(self,
                         tf,
                         formatName,
                         dense,
                         valued,
                         interval,
                         linked,
                         reprDense,
                         strand,
                         id,
                         weighted,
                         hasExtra,
                         val='number',
                         weights='number',
                         extra=[]):
        self.assertEqual(dense, tf.isDense())

        self.assertEqual(valued, tf.isValued())
        if valued:
            self.assertEqual(TrackFormat.VAL_TYPE_NAME_DICT[val],
                             tf.getValTypeName())

        self.assertEqual(interval, tf.isInterval())
        self.assertEqual(linked, tf.isLinked())

        if reprDense != None:
            self.assertEqual(reprDense, tf.reprIsDense())

        self.assertEqual(strand, tf.hasStrand())
        self.assertEqual(id, tf.hasId())

        self.assertEqual(weighted, tf.isWeighted())
        if weighted:
            self.assertEqual(TrackFormat.VAL_TYPE_NAME_DICT[weights],
                             tf.getWeightTypeName())

        self.assertEqual(hasExtra, tf.hasExtra())
        if extra:
            self.assertEqual(extra, tf.getExtraNames())

        if not str(tf).startswith('Requirement'):
            self.assertEqual(formatName, tf.getFormatName())
            #To test TrackFormatReq(name=formatName) on the standard formats in an easy way
            self.assertTrue(
                TrackFormatReq(name=formatName).isCompatibleWith(tf))
Ejemplo n.º 14
0
 def testFormatsReqs(self):
     for dense in (False, True, None):
         for val in (False, 'number', 'category_vector', None):
             for interval in (False, True, None):
                 for linked in (False, True, None):
                     for strand in (False, True, None):
                         for id in (False, True, None):
                             if linked == True and id == False:
                                 continue
                             for weights in (False, 'tc', 'char_vector',
                                             None):
                                 if linked == False and weights not in [
                                         False, None
                                 ]:
                                     continue
                                 for extra in (False, ['a', 'b'], None):
                                     tfReq = TrackFormatReq(dense=dense, val=val, interval=interval, linked=linked, \
                                                            strand=strand, id=id, weights=weights, extra=extra)
                                     self._assertFormatsReqs(
                                         tfReq, dense, val, interval,
                                         linked, strand, id, weights, extra)
Ejemplo n.º 15
0
 def __init__(self, trackName, **kwArgs):
     Track.__init__(self, trackName, **kwArgs)
     self.addFormatReq(
         TrackFormatReq(allowOverlaps=False, borderHandling='crop'))
Ejemplo n.º 16
0
 def _isDenseTrack(self):
     try:
         return TrackFormatReq(name=self.trackFormatName).isDense()
     except:
         return False
Ejemplo n.º 17
0
 def _getTrack(self):
     track = Track(self._trackName)
     track.addFormatReq(TrackFormatReq(allowOverlaps=self._allowOverlaps))
     return track
 def testConvertSegmentToPointReqFails(self):
     segSourceTv = SampleTV(segments=[[2, 20], [7, 11]])
     self._assertFailedConversion(segSourceTv, \
                                  TrackFormatReq(interval=False, dense=False, val='category'))
     self._assertFailedConversion(segSourceTv, \
                                  TrackFormatReq(interval=False, dense=False, strand=True))
Ejemplo n.º 19
0
 def _getTrackView(self, trackName, region, allowOverlaps):
     track = Track(trackName)
     track.addFormatReq(TrackFormatReq(allowOverlaps=allowOverlaps))
     return track.getTrackView(region)
 def addFormatReq(self, requestedTrackFormat):
     prevFormatReq = self._trackFormatReq
     self._trackFormatReq = TrackFormatReq.merge(self._trackFormatReq, requestedTrackFormat)
     if self._trackFormatReq is None:
         raise IncompatibleTracksError(str(prevFormatReq ) + \
                                       ' is incompatible with additional ' + str(requestedTrackFormat))