Beispiel #1
0
 def _postCalculation(self):
     if not self._resultAllowOverlap:
         track = self._result
         # Overlap not allowed in the result. Using merge to remove it
         m = Merge(track, useStrands=self._useStrands,
                   treatMissingAsNegative=self._treatMissingAsNegative)
         res = m.calculate()
         self._result = res
Beispiel #2
0
    def _runTest(self, starts=None, ends=None, strands=None, values=None,
                 ids=None, edges=None, weights=None, extras=None,
                 expStarts=None, expEnds=None,expValues=None,
                 expStrands=None, expIds=None, expEdges=None,
                 expWeights=None, expExtras=None, expTrackFormatType=None,
                 useStrands=False, treatMissingAsNegative=False,
                 mergeValuesFunction=None, debug=False):

        track = createSimpleTestTrackContent(startList=starts, endList=ends,
                                             strandList=strands,
                                             valList=values, idList=ids,
                                             edgeList=edges,
                                             weightsList=weights)

        m = Merge(track, useStrands=useStrands,
                  treatMissingAsNegative=treatMissingAsNegative,
                  mergeValuesFunction=mergeValuesFunction, debug=debug)

        self.assertTrue((m is not None))

        result = m.calculate()

        resFound = False

        for (k, v) in result.getTrackViews().items():

            newStarts = v.startsAsNumpyArray()
            newEnds = v.endsAsNumpyArray()
            newVals = v.valsAsNumpyArray()
            newStrands = v.strandsAsNumpyArray()
            newIds = v.idsAsNumpyArray()
            newEdges = v.edgesAsNumpyArray()
            newWeights = v.weightsAsNumpyArray()
            #newExtras = v.extrasAsNumpyArray()

            if cmp(k, self.chr1) == 0:

                if expTrackFormatType is not None:
                    points = ['Points', 'Valued points', 'Linked points',
                              'Linked valued points']

                    # Todo fix for segments and partitions
                    if expTrackFormatType in points:
                        # Point type track, we create the expected "virtual"
                        # ends.
                        self.assertTrue(v.trackFormat.getFormatName() == \
                               expTrackFormatType)
                        self.assertTrue(expEnds is None)
                        expEnds = np.array(expStarts) + 1

                # All test tracks are in chr1
                if debug:
                    print("**************************************")
                    print("Result and expected results:")
                    print("expStarts: {}".format(expStarts))
                    print("newStarts: {}".format(newStarts))
                    print("expEnds: {}".format(expEnds))
                    print("newEnds: {}".format(newStarts))
                    print("expStrands: {}".format(expStrands))
                    print("newStrands: {}".format(newStrands))
                    print("expValues: {}".format(expValues))
                    print("newValues: {}".format(newVals))
                    print("expIds: {}".format(expIds))
                    print("newIds: {}".format(newIds))
                    print("expEdges: {}".format(expEdges))
                    print("newEdges: {}".format(newEdges))
                    print("expWeights: {}".format(expWeights))
                    print("newWeights: {}".format(newWeights))
                    print("**************************************")

                resFound = True

                if expStarts is not None:
                    self.assertTrue(newStarts is not None)
                    self.assertTrue(np.array_equal(newStarts, expStarts))
                else:
                    self.assertTrue(newStarts is None)

                if expEnds is not None:
                    self.assertTrue(newEnds is not None)
                    self.assertTrue(np.array_equal(newEnds, expEnds))
                else:
                    self.assertTrue(newEnds is None)

                if expValues is not None:
                    self.assertTrue(newVals is not None)
                    self.assertTrue(np.array_equal(newVals, expValues))
                else:
                    self.assertTrue(newVals is None)

                if expStrands is not None:
                    self.assertTrue(newStrands is not None)
                    self.assertTrue(np.array_equal(newStrands, expStrands))
                else:
                    self.assertTrue(newStrands is None)

                if expIds is not None:
                    self.assertTrue(newIds is not None)
                    self.assertTrue(np.array_equal(newIds, expIds))
                else:
                    self.assertTrue(newIds is None)

                if expEdges is not None:
                    self.assertTrue(newEdges is not None)
                    self.assertTrue(np.array_equal(newEdges, expEdges))
                else:
                    self.assertTrue(newEdges is None)

                if expWeights is not None:
                    self.assertTrue(newWeights is not None)
                    self.assertTrue(np.array_equal(newWeights, expWeights))
                else:
                    self.assertTrue(newWeights is None)

                #if expExtras is not None:
                #    self.assertTrue(newExtras is not None)
                #    self.assertTrue(np.array_equal(newExtras, expExtras))
                #else:
                #    self.assertTrue(newExtras is None)

            else:
                # Tests if all tracks no in chr1 have a size of 0.
                if newStarts is not None:
                    self.assertEqual(newStarts, 0)
                if newEnds is not None:
                    self.assertEqual(newEnds, 0)
                if newStrands is not None:
                    self.assertEqual(newStrands, 0)
                if newVals is not None:
                    self.assertEqual(newVals, 0)
                if newIds is not None:
                    self.assertEqual(newIds, 0)
                if newEdges is not None:
                    self.assertEqual(newEdges, 0)
                if newWeights is not None:
                    self.assertEqual(newWeights, 0)
                #if newExtras is not None:
                #    self.assertEqual(newExtras, 0)

        self.assertTrue(resFound)
Beispiel #3
0
 def _postCalculation(self):
     if not self._resultAllowOverlap and not self._result.isEmpty():
         m = Merge(self._result, useStrands=self._useStrands,
                   treatMissingAsNegative=self._treatMissingAsNegative)
         self._result = m.calculate()