comparison cummerbund_to_tabular.py @ 1:36f917aa4b60 draft

Uploaded corrected script
author devteam
date Mon, 16 Mar 2015 15:43:38 -0400
parents 648c27c78eed
children
comparison
equal deleted inserted replaced
0:648c27c78eed 1:36f917aa4b60
1 import os 1 import os
2 import argparse 2 import argparse
3 import sys 3 import sys
4 import string 4 import string
5 5 import sqlite3
6 from galaxy.model.orm import * 6
7 import logging 7 import logging
8 from galaxy import eggs
9 eggs.require('SQLAlchemy')
10 import sqlalchemy
11 8
12 9
13 class CummerbundParser(object): 10 class CummerbundParser(object):
14 11
15 def __init__(self, opts): 12 def __init__(self, opts):
16 self.cummerbund_db = opts.filename 13 self.cummerbund_db = opts.filename
17 self.__connect_database() 14 self.session = sqlite3.connect( os.path.abspath( self.cummerbund_db ) )
18 15
19 def generate_file( self, table ): 16 def generate_file( self, table ):
20 if hasattr( self, table ): 17 if hasattr( self, table ):
21 with open( '%s.tabular' % table, 'w' ) as self.fh: 18 with open( '%s.tabular' % table, 'w' ) as self.fh:
22 getattr( self, table )() 19 getattr( self, table )()
23 else: 20 else:
24 print 'Table %s is not supported or does not exist.' % table 21 print 'Table %s is not supported or does not exist.' % table
25
26 def __connect_database( self ):
27 database_connection = 'sqlite:///%s' % os.path.abspath( self.cummerbund_db )
28 # Initialize the database connection.
29 engine = create_engine( database_connection )
30 meta = MetaData( bind=engine )
31 sa_sesssion = Session = scoped_session( sessionmaker( bind=engine, autoflush=False, autocommit=True ) )
32 self.session = sa_sesssion
33 22
34 def __write_line(self, line): 23 def __write_line(self, line):
35 columns = [] 24 columns = []
36 for col in line: 25 for col in line:
37 if isinstance( col, float ): 26 if isinstance( col, float ):