root/galaxy-central/scripts/cleanup_datasets/update_metadata.py

リビジョン 2, 3.1 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2#Dan Blankenberg
3"""
4Updates metadata in the database to match rev 1891.
5
6Remember to backup your database before running.
7"""
8
9import sys, os, ConfigParser
10import galaxy.app
11from galaxy.util.bunch import Bunch
12import galaxy.datatypes.tabular
13
14assert sys.version_info[:2] >= ( 2, 4 )
15
16def main():
17    ini_file = sys.argv.pop(1)
18    conf_parser = ConfigParser.ConfigParser({'here':os.getcwd()})
19    conf_parser.read(ini_file)
20    configuration = {}
21    for key, value in conf_parser.items("app:main"): configuration[key] = value
22    app = galaxy.app.UniverseApplication( global_conf = ini_file, **configuration )
23   
24    #Step through Database, turning metadata bunches into dictionaries.
25    #print "Changing metadata bunches to dictionaries."
26    #for row in app.model.Dataset.table.select().execute():
27    #    if isinstance (row.metadata, Bunch):
28    #        print row.id
29    #        app.model.Dataset.table.update(app.model.Dataset.table.c.id == row.id).execute( _metadata = row.metadata.__dict__ )
30   
31    #Make sure all metadata is jsonified
32    #print "Rewriting all metadata to database, setting metadata dbkey, to ensure JSONified storage."
33    #for row in app.model.Dataset.table.select().execute():
34    #    print row.id
35    #    data = app.model.Dataset.get(row.id)
36    #    dbkey = data.old_dbkey
37    #    if not dbkey or data.metadata.dbkey not in ["?", ["?"], None, []]:
38    #        dbkey = data.metadata.dbkey
39    #    if not dbkey: dbkey = "?"
40    #    #change dbkey then flush, then change to real value and flush, ensures that metadata is rewritten to database
41    #    data.dbkey="~"
42    #    data.flush()
43    #    data.dbkey=dbkey
44    #    data.flush()
45   
46   
47    #Search out tabular datatypes (and subclasses) and initialize metadata
48    print "Seeking out tabular based files and initializing metadata"
49    for row in app.model.Dataset.table.select().execute():
50        data = app.model.Dataset.get(row.id)
51        if issubclass(type(data.datatype), type(app.datatypes_registry.get_datatype_by_extension('tabular'))):
52            print row.id, data.extension
53            #Call meta_data for all tabular files
54            #special case interval type where we do not want to overwrite chr, start, end, etc assignments
55            if issubclass(type(data.datatype), type(app.datatypes_registry.get_datatype_by_extension('interval'))):
56                galaxy.datatypes.tabular.Tabular().set_meta(data)
57            else:
58                data.set_meta()
59            app.model.context.add( data )
60            app.model.context.flush()
61           
62    #Search out maf datatypes and make sure that available species is set.
63    #print "Seeking out maf files and setting available species."
64    #for row in app.model.Dataset.table.select(app.model.Dataset.table.c.extension == 'maf').execute():
65    #    print row.id
66    #    sys.stdout.flush()
67    #    data = app.model.Dataset.get(row.id)
68    #    if data.missing_meta:
69    #        data.set_meta() #Call maf set metadata method, setting available species
70    #        data.flush()
71   
72    app.shutdown()
73    sys.exit(0)
74
75if __name__ == "__main__":
76    main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。