Script to ensure that MAF metadata is set.

This commit is contained in:
Daniel Blankenberg
2007-08-30 14:46:52 +00:00
parent dae7fd96cb
commit 42a90ea1f0
2 changed files with 42 additions and 38 deletions
+7 -14
View File
@@ -54,23 +54,16 @@ class Maf( Alignment ):
"""
species = []
try:
maf_reader = bx.align.maf.Reader( open(dataset.file_name) )
for i, m in enumerate( maf_reader ):
l = m.components
for c in l:
for i, m in enumerate( bx.align.maf.Reader( open(dataset.file_name) ) ):
for c in m.components:
spec,chrom = bx.align.maf.src_split( c.src )
if not spec or not chrom:
spec = chrom = c.src
if spec not in species:
species.append(spec)
#only check first million blocks for species
if i > 1000000:
break
except:
pass
if not spec or not chrom: spec = chrom = c.src
if spec not in species: species.append(spec)
#only check first 100,000 blocks for species
if i > 100000: break
except: pass
dataset.metadata.species = species
class Axt( Alignment ):
"""Class describing an axt alignment"""
+35 -24
View File
@@ -20,35 +20,46 @@ def main():
for key, value in conf_parser.items("app:main"): configuration[key] = value
app = galaxy.app.UniverseApplication( global_conf = ini_file, **configuration )
# Step through Database, turning metadata bunches into dictionaries.
print "Changing metadata bunches to dictionaries."
for row in app.model.Dataset.table.select().execute():
if isinstance (row.metadata, Bunch):
print row.id
app.model.Dataset.table.update(app.model.Dataset.table.c.id == row.id).execute( _metadata = row.metadata.__dict__ )
#Step through Database, turning metadata bunches into dictionaries.
#print "Changing metadata bunches to dictionaries."
#for row in app.model.Dataset.table.select().execute():
# if isinstance (row.metadata, Bunch):
# print row.id
# app.model.Dataset.table.update(app.model.Dataset.table.c.id == row.id).execute( _metadata = row.metadata.__dict__ )
print "Rewriting all metadata to database, setting metadata dbkey, to ensure JSONified storage."
#Make sure all metadata is jsonified
for row in app.model.Dataset.table.select().execute():
print row.id
data = app.model.Dataset.get(row.id)
dbkey = data.old_dbkey
if not dbkey or data.metadata.dbkey not in ["?", ["?"], None, []]:
dbkey = data.metadata.dbkey
if not dbkey: dbkey = "?"
#change dbkey then flush, then change to real value and flush, ensures that metadata is rewritten to database
data.dbkey="~"
data.flush()
data.dbkey=dbkey
data.flush()
#print "Rewriting all metadata to database, setting metadata dbkey, to ensure JSONified storage."
#for row in app.model.Dataset.table.select().execute():
# print row.id
# data = app.model.Dataset.get(row.id)
# dbkey = data.old_dbkey
# if not dbkey or data.metadata.dbkey not in ["?", ["?"], None, []]:
# dbkey = data.metadata.dbkey
# if not dbkey: dbkey = "?"
# #change dbkey then flush, then change to real value and flush, ensures that metadata is rewritten to database
# data.dbkey="~"
# data.flush()
# data.dbkey=dbkey
# data.flush()
print "Seeking out tabular based files and setting number of columns."
#Search out tabular datatypes and make sure that number of columns is set.
for row in app.model.Dataset.table.select().execute():
#print "Seeking out tabular based files and setting number of columns."
#for row in app.model.Dataset.table.select().execute():
# data = app.model.Dataset.get(row.id)
# if issubclass(type(data.datatype), type(app.datatypes_registry.get_datatype_by_extension('tabular'))):
# print row.id
# galaxy.datatypes.tabular.Tabular().set_meta( data ) #Call tabular set metadata method for all Classes, this will set number of columns.
# data.flush()
#Search out maf datatypes and make sure that available species is set.
print "Seeking out maf files and setting available species."
for row in app.model.Dataset.table.select(app.model.Dataset.table.c.extension == 'maf').execute():
print row.id
sys.stdout.flush()
data = app.model.Dataset.get(row.id)
if issubclass(type(data.datatype), type(app.datatypes_registry.get_datatype_by_extension('tabular'))):
print row.id
galaxy.datatypes.tabular.Tabular().set_meta( data ) #Call tabular set metadata method for all Classes, this will set number of columns.
if data.missing_meta:
data.set_meta() #Call maf set metadata method, setting available species
data.flush()
app.shutdown()