Пример #1
0
    def _createSubSetFromClasses(self, inputClasses):
        outputClassName = self.outputClassName.get()
        
        if (outputClassName.startswith('SetOfAverages') or
            outputClassName.startswith('SetOfVolumes') or
            outputClassName.startswith('SetOfParticles')):
            # We need to distinguish two cases:
            # a) when we want to create images by grouping class images
            # b) create a subset from a particular class images
            from pyworkflow.mapper.sqlite import SqliteFlatDb
            db = SqliteFlatDb(dbName=self._dbName, tablePrefix=self._dbPrefix)
            itemClassName = db.getSelfClassName()

            if itemClassName.startswith('Class'):
                if outputClassName.startswith('SetOfParticles'):
                    return self._createImagesFromClasses(inputClasses)
                else:
                    return self._createRepresentativesFromClasses(inputClasses,
                                                                  outputClassName.split(',')[0])
            else:
                def callback(output):
                    self._copyInfoAndSetAlignment(inputClasses, output)

                return self._createSubSetFromImages(inputClasses.getImages(),
                                                    copyInfoCallback=callback)

        elif outputClassName.startswith('SetOfClasses'):
            return self._createClassesFromClasses(inputClasses)
        else:
            raise Exception("Unrecognized output type: '%s'" % outputClassName)  
Пример #2
0
    def _createSubSetFromClasses(self, inputClasses):
        outputClassName = self.outputClassName.get()

        if (outputClassName.startswith('SetOfAverages')
                or outputClassName.startswith('SetOfVolumes')
                or outputClassName.startswith('SetOfParticles')):
            # We need to distinguish two cases:
            # a) when we want to create images by grouping class images
            # b) create a subset from a particular class images
            from pyworkflow.mapper.sqlite import SqliteFlatDb
            db = SqliteFlatDb(dbName=self._dbName, tablePrefix=self._dbPrefix)
            itemClassName = db.getSelfClassName()

            if itemClassName.startswith('Class'):
                if outputClassName.startswith('SetOfParticles'):
                    return self._createImagesFromClasses(inputClasses)
                else:
                    return self._createRepresentativesFromClasses(
                        inputClasses,
                        outputClassName.split(',')[0])
            else:

                def callback(output):
                    self._copyInfoAndSetAlignment(inputClasses, output)

                return self._createSubSetFromImages(inputClasses.getImages(),
                                                    copyInfoCallback=callback)

        elif outputClassName.startswith('SetOfClasses'):
            return self._createClassesFromClasses(inputClasses)
        else:
            raise Exception("Unrecognized output type: '%s'" % outputClassName)
Пример #3
0
def loadSetFromDb(dbName, dbPrefix=''):
    from pyworkflow.mapper.sqlite import SqliteFlatDb
    db = SqliteFlatDb(dbName=dbName, tablePrefix=dbPrefix)
    setClassName = db.getProperty('self') # get the set class name
    setObj = getObjects()[setClassName](filename=dbName, prefix=dbPrefix)
    return setObj
    
Пример #4
0
def loadSetFromDb(dbName, dbPrefix=''):
    from pyworkflow.mapper.sqlite import SqliteFlatDb
    db = SqliteFlatDb(dbName=dbName, tablePrefix=dbPrefix)
    setClassName = db.getProperty('self')  # get the set class name
    setObj = Domain.getObjects()[setClassName](filename=dbName,
                                               prefix=dbPrefix)
    return setObj
Пример #5
0
    def _loadSet(self, dbName, dbPreffix):
        from pyworkflow.mapper.sqlite import SqliteFlatDb
        db = SqliteFlatDb(dbName=dbName, tablePrefix=dbPreffix)
        if dbPreffix:
            setClassName = "SetOf%ss" % db.getSelfClassName()
        else:
            setClassName = db.getProperty('self')  # get the set class name

        from pyworkflow.em import getObjects
        setObj = getObjects()[setClassName](filename=dbName, prefix=dbPreffix)
        return setObj
Пример #6
0
    def _loadSet(self, dbName, dbPreffix):
        from pyworkflow.mapper.sqlite import SqliteFlatDb
        db = SqliteFlatDb(dbName=dbName, tablePrefix=dbPreffix)
        if dbPreffix:
            setClassName = "SetOf%ss" % db.getSelfClassName()
        else:
            setClassName = db.getProperty('self') # get the set class name

        from pyworkflow.em import getObjects
        setObj = getObjects()[setClassName](filename=dbName, prefix=dbPreffix)
        return setObj
Пример #7
0
    def test_SqliteFlatDb(self):
        """ Create a SqliteDataset """
        from pyworkflow.mapper.sqlite import SqliteFlatDb

        print ">>> test_SqliteFlatDb: dbName = '%s'" % self.modelGoldSqlite
        db = SqliteFlatDb(self.modelGoldSqlite)
        # Test the 'self' class name is correctly retrieved
        self.assertEqual("Micrograph", db.getSelfClassName())
        # Check the count is equal to 3
        self.assertEqual(3, db.count())
        db.close()
Пример #8
0
 def __init__(self, filename):
     self._dbName = filename
     db = SqliteDb()
     db._createConnection(filename, 1000)
     # Tables should be at pairs:
     # PREFIX_Classes
     # PREFIX_Objects  
     # where PREFIX can be empty
     self.tablePrefixes = OrderedDict()
     tables = db.getTables()
     for t in tables:
         if t.endswith('Classes'):
             prefix = t.replace('Classes', '')
             to = prefix + 'Objects'
             if to not in tables:
                 raise Exception('SqliteDataSet: table "%s" found, but not "%s"' % (t, to))
             flatDb = SqliteFlatDb(filename, tablePrefix=prefix)
             tableName = prefix + self._getPlural(flatDb.getSelfClassName())
             self.tablePrefixes[tableName] = prefix
             #tablePrefixes.append(prefix)
     DataSet.__init__(self, self.tablePrefixes.keys())
     db.close()
Пример #9
0
 def __init__(self, filename):
     self._dbName = filename
     db = SqliteDb()
     db._createConnection(filename, 1000)
     # Tables should be at pairs:
     # PREFIX_Classes
     # PREFIX_Objects  
     # where PREFIX can be empty
     self.tablePrefixes = OrderedDict()
     tables = db.getTables()
     for t in tables:
         if t.endswith('Classes'):
             prefix = t.replace('Classes', '')
             to = prefix + 'Objects'
             if to not in tables:
                 raise Exception('SqliteDataSet: table "%s" found, but not "%s"' % (t, to))
             flatDb = SqliteFlatDb(filename, tablePrefix=prefix)
             tableName = prefix + self._getPlural(flatDb.getSelfClassName())
             self.tablePrefixes[tableName] = prefix
             #tablePrefixes.append(prefix)
     DataSet.__init__(self, self.tablePrefixes.keys())
     db.close()
Пример #10
0
 def test_SqliteFlatDb(self):
     """ Create a SqliteDataset """
     from pyworkflow.mapper.sqlite import SqliteFlatDb
     print ">>> test_SqliteFlatDb: dbName = '%s'" % self.modelGoldSqlite
     db = SqliteFlatDb(self.modelGoldSqlite)
     # Old db version 0
     self.assertEqual(0, db.getVersion())
     # Test the 'self' class name is correctly retrieved
     self.assertEqual('Micrograph', db.getSelfClassName())
     # Check the count is equal to 3
     self.assertEqual(3, db.count())
     db.close()