def maybe_make_db(self): """Get GFFutils database from file or create from a gtf""" if self.gffutils_db is not None: copied_db = os.path.join(self.gtf_folder, os.path.basename(self.gffutils_db)) util.progress('Copying gffutils database from {} to {} ' '...'.format(self.gffutils_db, copied_db)) shutil.copyfile(self.gffutils_db, copied_db) util.done() util.progress('Reading gffutils database from {} ...'.format( copied_db)) db = gffutils.FeatureDB(copied_db) util.done() else: basename = os.path.basename(self.gtf_filename) db_filename = os.path.join(self.gtf_folder, '{}.db'.format(basename)) util.progress("Found GTF file in {}".format(self.gtf_filename)) try: db = gffutils.FeatureDB(db_filename) util.progress( "Found existing built outrigger-built gffutils database " "file in {}".format(db_filename)) except (ValueError, TypeError): util.progress( 'Creating a "gffutils" ' 'database {} ...'.format(db_filename)) db = gtf.create_db(self.gtf_filename, db_filename) util.done() return db
def test_create_db(gtf_filename, db, snap25_exon_id): from outrigger.io import gtf true = db test = gtf.create_db(gtf_filename, 'test.gtf.db') # Check that all the true db features are in the test database for featuretype in true.featuretypes(): for feature in true.features_of_type(featuretype=featuretype): try: test[feature.id] except gffutils.FeatureNotFoundError: pytest.fail('Feature in true database not found in test ' 'database') # Check that all the test db features are in the true database for featuretype in test.featuretypes(): for feature in test.features_of_type(featuretype=featuretype): try: true[feature.id] except gffutils.FeatureNotFoundError: pytest.fail('Feature in test database not found in true ' 'database') # SNAP25 should be in both the true and test databases assert true[snap25_exon_id] is not None assert test[snap25_exon_id] is not None