def do_dbmgr(args, settings, dbh=None): if dbh is None: dbh = get_dbhandler(settings, initial = args.initdb) print(dbh) fatools_do_dbmgr(args, dbh, warning=False)
def postrender(buffer, node): """ return a new buffer """ dbh = get_dbhandler() nb = "" start_pos = 0 for m in pattern.finditer(buffer): nb += buffer[start_pos : m.start()] group = m.group() print(group) if group.startswith("///"): nb += node_link(group, dbh) elif group.startswith("[["): nb += run_macro(group, node, dbh) start_pos = m.end() nb += buffer[start_pos:] return nb
def action_post(request): method = request.params.get('_method', None) dbh = get_dbhandler() if method == 'delete': user_ids = [ int(x) for x in request.params.getall('user-ids') ] users = dbh.get_user( user_ids ) if len(users) == 0: return Response(modal_error) return Response( modal_delete % ''.join( '<li>%s | %s, %s | %s</li>' % (u.login, u.lastname, u.firstname, u.userclass.domain) for u in users)) elif method == 'delete/confirm': user_ids = [ int(x) for x in request.params.getall('user-ids') ] logins = [] for user in dbh.get_user( user_ids ): logins.append( user.login ) dbh.session().delete(user) dbh.session().flush() request.session.flash( ('success', 'User %s has been deleted successfully' % ','.join( logins ))) return HTTPFound( location = request.referrer or request.route_url( 'rhombus.user')) raise RuntimeError('FATAL - programming ERROR')
def do_facmd(args, settings, dbh=None): if dbh is None: dbh = get_dbhandler(settings) print(dbh) fatools_do_facmd(args, dbh)
def view(request): dbh = get_dbhandler() userclass = dbh.get_userclass( int(request.matchdict['id']) ) html = div( div(h3('Userclass: %s' % userclass.domain))) eform = edit_form(userclass, dbh, request, static=True) html.add( div(eform) ) user_table = table(class_='table table-condensed table-striped')[ thead()[ th('Login'), th('Name'), th('Primary group') ], tbody()[ tuple([ tr()[ td(a(u.login, href=request.route_url('rhombus.user-view', id=u.id))), td(u.fullname()), td(a(u.primarygroup.name, href=request.route_url('rhombus.group-view', id=u.primarygroup_id))), ] for u in userclass.users ]) ] ] html.add(user_table) return render_to_response('rhombus:templates/generics/page.mako', { 'content': str(html) }, request = request )
def do_rbmgr(args, settings, dbh = None): if not dbh: dbh = get_dbhandler(settings, initial = args.initdb) if args.initdb: do_initdb(args, dbh, settings) elif args.adduser: do_adduser(args, dbh, settings) elif args.setcred: do_setcred(args, dbh, settings) elif args.importgroup: do_importgroup(args, dbh, settings) elif args.listenumkey: do_listenumkey(args, dbh, settings) elif args.addenumkey: do_addenumkey(args, dbh, settings) else: return False return True
def index(request): dbh = get_dbhandler() userclasses = dbh.get_userclass() userclass_table = table(class_='table table-condensed table-striped')[ thead()[ th('', style="width: 2em;"), th('UserClass / Domain'), th('Users') ], tbody()[ tuple([ tr()[ td(literal('<input type="checkbox" name="userclass-ids" value="%d" />' % uc.id)), td('%s' % uc.domain), td(a('%d' % uc.users.count(), href=request.route_url('rhombus.userclass-view', id=uc.id)) ) ] for uc in userclasses ]) ] ] add_button = ( 'New userclass', request.route_url('rhombus.userclass-edit', id=0) ) bar = selection_bar('userclass-ids', action=request.route_url('rhombus.userclass-action'), add = add_button) html, code = bar.render(userclass_table) return render_to_response('rhombus:templates/generics/page.mako', { 'html': html, 'code': code }, request = request )
def do_dbmgr(args, settings, dbh=None): from spatools.lib import dbmgr if dbh is None: dbh = get_dbhandler(settings) print(dbh) dbmgr.do_dbmgr(args, dbh, warning=False)
def analysis_task(callback, userinstance, specs, namespace): # at this point, get_dbhandler() should have return proper db handler # also needs to pass userinstance.groups to sample selector dbh = get_dbhandler() q = dbh.Query(specs, dbh) ok = callback(q, userinstance, namespace) return ok
def main(args): # initialize database cerr('initialize ') settings = setup_settings(args) get_dbhandler(settings) # init taskqueue here cerr('initialize taskcache') init_taskcache(settings) # running working with Connection(): cerr('running worker') w = Worker(settings['genaf.taskqueue.name']) w.work()
def add(request, node): if request.method == 'POST': # sanity check d = parse_form(request.params) new_node = PageNode() get_workflow(new_node).set_defaults(new_node, request.user, node) new_node.update(d) if not new_node.slug: new_node.generate_slug() node.add(new_node) get_dbhandler().session().flush() new_node.ordering = 19 * new_node.id if request.params['_method'].endswith('_edit'): return HTTPFound(location = request.route_url('node-edit', path=new_node.url)) return HTTPFound(location = new_node.path) # show the edit form # create a dummy node dbh = get_dbhandler() with dbh.session().no_autoflush: new_node = PageNode() new_node.parent_id = node.id new_node.site = node.site new_node.group_id = node.group_id new_node.user_id = request.user.id new_node.mimetype_id = dbh.get_ekey('text/x-rst').id eform, jscode = edit_form(new_node, request, create=True) return render_to_response('cmsfix:templates/pagenode/edit.mako', { 'parent_url': node.path, 'node': new_node, 'toolbar': '', # new node does not have toolbar yet! 'eform': eform, 'code': jscode, }, request = request )
def _getter(inst): _id = getattr(inst, attrname) #print("*** id is", _id, "for attr", attrname) dbsession = object_session(inst) if dbsession is None: dbsession = get_dbhandler().session() key = EK._key( getattr(inst, attrname), dbsession) if not match_case and key: return key.lower() return key
def process_menu(self, node, request): """ process request """ state = int(request.params.get('state', 3)) node.state = state from rhombus.lib.utils import get_dbhandler dbsession = get_dbhandler().session() assert dbsession.user, "Fatal Error: user not properly set up" assert dbsession.user.id == request.user.id, "Fatal Error: inconsistent user id in db session"
def edit(request): userclass_id = int(request.matchdict['id']) if userclass_id < 0: return error_page(request, 'Please provide userclass ID') dbh = get_dbhandler() if request.method == 'GET': if userclass_id == 0: userclass = dbh.UserClass() userclass.id = 0 else: userclass = dbh.get_userclass(userclass_id) editform = edit_form(userclass, dbh, request) return render_to_response( "rhombus:templates/generics/page.mako", { 'html': editform, }, request = request ) elif request.POST: userclass_d = parse_form( request.POST ) if userclass_d['id'] != userclass_id: return error_page(request, "Inconsistent data!") try: if userclass_id == 0: userclass = dbh.UserClass() userclass.update( userclass_d ) dbh.session().add( userclass ) dbh.session().flush() request.session.flash( ( 'success', 'Userclass [%s] has been created.' % userclass.domain ) ) else: userclass = dbh.get_userclass(userclass_id) userclass.update( userclass_d ) dbh.session().flush() except RuntimeError as err: return error_page(request, str(err)) except: raise return HTTPFound(location = request.route_url('rhombus.userclass-view', id=userclass.id)) raise NotImplementedError()
def index_all(): dbh = get_dbhandler() index_service = get_index_service() with index_service.ix.writer() as writer: for n in dbh.get_nodes(): writer.delete_by_term('nodeid', n.id) writer.add_document(nodeid=n.id, mtime=n.stamp, text=n.search_text(), keywords=n.search_keywords()) cerr('indexing node: %d' % n.id)
def main(): greet() # preparing everything p = arg_parser('cmsfix-shell') args = p.parse_args(sys.argv[1:]) settings = setup_settings( args ) dbh = get_dbhandler(settings) set_index_service( IndexService(settings['cmsfix.whoosh.path']) ) from IPython import embed embed()
def do_analysis(query, userinstance, ns, *args, **kwargs): """ this analysis method has to be performed and detached from viewer classes as it might be executed in other process through multiprocessing pipeline where all local instances might not be available anymore. """ dbh = get_dbhandler() ns.result['title'] = 'Dummy Analysis Result' return True
def get_assay_ids(batch_id): dbh = get_dbhandler() assay_list = [] with transaction.manager: batch = dbh.get_batch_by_id(batch_id) for sample in batch.samples: for assay in sample.assays: assay_list.append( (assay.id, sample.code) ) return assay_list
def M_Img(node, components): path = components[0] if path.startswith("http") or path.startswith("ftp"): url = path elif path.startswith("//"): image_node_id = int(path[2:]) image_node = get_dbhandler().get_node_by_id(image_node_id) if not image_node: return "[[ Invalid image macro: non existent node %d]]" % image_node_id url = image_node.path elif path.startswith("/"): # check node with this path path_node = get_dbhandler().get_node_by_path(path) if not path_node: return "[[ Invalid image macro: not existent path %s ]]" % path url = path else: url = "/%s/%s" % (node.url, path) # return '[[ Invalid image macro (%s) ]]' % path return literal('<img src="%s" />' % url)
def view(request): dbh = get_dbhandler() user = dbh.get_user( int(request.matchdict['id']) ) html = div( div(h3('User View')) ) eform = edit_form(user, dbh, request, static=True) html.add( eform ) return render_to_response('rhombus:templates/generics/page.mako', { 'html': html, }, request = request )
def edit_form(node, request, create=False): dbh = get_dbhandler() eform, jscode = node_edit_form(node, request, create) eform.get('cmsfix.node-main').add( input_text('cmsfix-title', 'Title', value=node.title, offset=1), node_submit_bar(create), input_textarea('cmsfix-content', 'Content', value=node.content, offset=1, size="18x8"), input_textarea('cmsfix-summary', 'Summary', value=node.summary, offset=1, size='5x8') ) return eform, jscode
def main(): greet() # preparing everything p = arg_parser('genaf-base-shell') args = p.parse_args(sys.argv[1:]) settings = setup_settings(args) dbh = get_dbhandler(settings) from IPython import embed import transaction embed()
def view(request): batch_id = request.matchdict.get('id') batch = get_dbhandler().get_batch_by_id(batch_id) # check authorization if not request.user.in_group( batch.group ): return error_page(request, 'You are not authorized to view this batch!') # get all assay list assay_list = [] for sample in batch.samples: for assay in sample.assays: assay_list.append( (assay, sample.code) ) summaries = summarize_assay( assay_list ) assay_status_panel = div() for (label, key) in [ ('Assigned', assaystatus.assigned), ('Scanned', assaystatus.scanned), ('Preannotated', assaystatus.preannotated), ('Ladder aligned', assaystatus.aligned), ('Called', assaystatus.called), ('Binned', assaystatus.binned), ('Annotated', assaystatus.annotated), ]: if key in summaries: value = summaries[key] assay_status_panel.add( row()[ div(class_='col-md-4')[ label ], div(class_='col-md-3')[ value ] ] ) summary_content = div()[ div('FSA status:'), assay_status_panel ] summary_content.add( row()[ div(class_='col-md-3')[ a(href=request.route_url('genaf.famgr-process', id=batch_id)) [ span(class_='btn btn-success')[ 'Process FSA' ] ], a(href=request.route_url('genaf.assay', _query={'batch_id': batch_id})) [ span(class_='btn btn-default')[ 'Browse FSA files' ] ], ] ] ) return render_to_response('genaf:templates/famgr/view.mako', { 'content': summary_content, 'batch': batch, }, request = request )
def get_userobj(request): user_id = request.unauthenticated_userid db_session = get_dbhandler().session() if user_id is None: db_session.user = None return None user_id = user_id.encode('ASCII') userinstance = auth_cache.get(user_id, None) if db_session.user and userinstance and db_session.user.id != userinstance.id: cerr('WARNING PROGRAMMING ERROR: reuse of db_session.user -> %d >> %d' % (db_session.user.id, userinstance.id)) db_session.user = userinstance return userinstance
def summarize_sample(analytical_sets): results = [] dbh = get_dbhandler() for a_set in analytical_sets: d = { 'label': None, 'passive_detection': [], 'symptomatic_status': [], 'pcr_identity': [], 'microscopy_identity': [], 'blood_withdrawal': [], 'gender': [], 'imported_case': [], 'nationality_status': [], 'nationality': [], 'string1': [], } d['label'] = a_set.label for s_id in a_set.sample_ids: sample = dbh.get_sample_by_id(s_id) d['passive_detection'].append(sample.passive_case_detection) d['symptomatic_status'].append(sample.symptomatic_status) d['pcr_identity'].append(sample.pcr) d['microscopy_identity'].append(sample.microscopy) d['blood_withdrawal'].append(sample.method) d['gender'].append(sample.subject.gender) d['imported_case'].append(sample.imported_case) d['nationality_status'].append(sample.nationality_status) d['nationality'].append(sample.subject.nationality) d['string1'].append(sample.string1) d['passive_detection'] = summarize_field(d['passive_detection']) d['symptomatic_status'] = summarize_field(d['symptomatic_status']) d['pcr_identity'] = summarize_field(d['pcr_identity']) d['microscopy_identity'] = summarize_field(d['microscopy_identity']) d['blood_withdrawal'] = summarize_field(d['blood_withdrawal']) d['gender'] = summarize_field(d['gender']) d['imported_case'] = summarize_field(d['imported_case']) d['nationality_status'] = summarize_field(d['nationality_status']) d['nationality'] = summarize_field(d['nationality']) d['string1'] = summarize_field(d['string1']) results.append(d) return results
def summarize_sample(analytical_sets): results = [] dbh = get_dbhandler() for a_set in analytical_sets: d = { 'label': None, 'passive_detection': [], 'symptomatic_status': [], 'pcr_identity': [], 'microscopy_identity': [], 'blood_withdrawal': [], 'gender': [], 'imported_case': [], 'nationality_status': [], 'nationality': [], 'string1':[], } d['label'] = a_set.label for s_id in a_set.sample_ids: sample = dbh.get_sample_by_id(s_id) d['passive_detection'].append( sample.passive_case_detection ) d['symptomatic_status'].append( sample.symptomatic_status ) d['pcr_identity'].append( sample.pcr ) d['microscopy_identity'].append( sample.microscopy ) d['blood_withdrawal'].append( sample.method ) d['gender'].append( sample.subject.gender ) d['imported_case'].append( sample.imported_case ) d['nationality_status'].append( sample.nationality_status ) d['nationality'].append( sample.subject.nationality ) d['string1'].append( sample.string1 ) d['passive_detection'] = summarize_field( d['passive_detection'] ) d['symptomatic_status'] = summarize_field( d['symptomatic_status'] ) d['pcr_identity'] = summarize_field( d['pcr_identity'] ) d['microscopy_identity'] = summarize_field( d['microscopy_identity'] ) d['blood_withdrawal'] = summarize_field( d['blood_withdrawal'] ) d['gender'] = summarize_field( d['gender'] ) d['imported_case'] = summarize_field( d['imported_case'] ) d['nationality_status'] = summarize_field( d['nationality_status'] ) d['nationality'] = summarize_field( d['nationality'] ) d['string1'] = summarize_field( d['string1']) results.append( d ) return results
def mp_process_assays(settings, batch_id, login, user_id, ns): """ this function will be started in different process, so it must initialize everything from scratch, including database connection """ pid = os.getpid() cerr('mp_process_assays()[%d]: connecting to db' % pid) dbh = get_dbhandler_notsafe() if dbh is None: dbh = get_dbhandler(settings) dbh.session().global_user = dbh.get_user(user_id) cerr('mp_process_assays()[%d]: processing...' % pid) result = process_assays(batch_id, login, ns) dbh.session().global_user = None return result
def _id(key, dbsession=None, grp=None, auto=False): """ key and grp is the key name (as string) """ if dbsession is None: dbsession = get_dbhandler().session() id = dbsession.get_id((key, grp)) if id: return id ek = EK.search(key, grp, dbsession) if not ek: if not auto: raise KeyError( "Key: %s/%s is not found!" % (key, grp) ) if not grp: raise RuntimeError('EK: when set auto creation, group needs to be provided') group = EK.search(grp, dbsession=dbsession) ek = EK(key, '-', parent=group) dbsession.add( ek ) dbsession.flush([ek]) dbsession.set_key((ek.key, grp), ek.id) return ek.id
def lookup(request): """ return JSON for autocomplete """ q = request.params.get('q') if not q: return error_page(request) q = '%' + q.lower() + '%' dbh = get_dbhandler() users = dbh.User.query(dbh.session()).filter( or_( dbh.User.login.ilike(q), dbh.User.lastname.ilike(q), dbh.User.firstname.ilike(q)) ) # formating for select2 consumption result = [ { 'id': u.id, 'text': u.render()} for u in users] return result
def index(request): """ return a basic form if no """ if 'q' in request.params: q = request.params.get('q') index_service = get_index_service() qp = QueryParser('text', schema=index_service.ix.schema) query = qp.parse(q) with index_service.ix.searcher() as searcher: results = searcher.search(query) node_ids = [ r['nodeid'] for r in results ] dbh = get_dbhandler() html = div() for nodeid in node_ids: node = dbh.get_node_by_id(nodeid) html.add( div(class_='row')[ div(class_='col-md-1')[ 'Modified at:', br(), 'by', br() ], div(class_='col-md-11')[ h3(node.title), br(), node.summary ] ] ) return render_to_response('cmsfix:templates/node/generics.mako', { 'content': html, }, request = request ) raise NotImplementedError()
def __init__(self, root, request): self.root = root self.request = request self.dbh = get_dbhandler()
def process(request): batch_id = request.matchdict.get('id') if batch_id in local_procs: (procid, login, batch_code) = local_procs[batch_id] if login != request.user.login: seconds = 0 msg = div()[ p('Another task started by %s is currently running batch: %s' % ( login, batch_code )) ] else: procunit = getproc(procid) if procunit.status in ['D', 'U']: seconds = 0 if procunit.exc: msg = div()[ p('Assay processing failed. Please see the following error:'), p( procunit.exc ), ] else: result = procunit.result msg = div()[ p('Assay processing finished.'), p('Statistics: %s' % str(result[0]) ), p()[ a(href=request.route_url('genaf.famgr-view',id=batch_id))[ span(class_='btn btn-success')[ 'Continue' ] ] ] ] if result[1]: msg.add( div()[ p( *result[1] ) ] ) del local_procs[batch_id] else: seconds = 10 msg = div()[ p('Output: %s' % procunit.ns.cout), p('Processing...') ] else: batch = get_dbhandler().get_batch_by_id(batch_id) batch_code = batch.code # check authorization if not request.user.in_group( batch.group ): error_page('You are not authorized to view this batch!') if False: # set the above to True for single-process debugging purpose process_assays(batch_id, request.user.login, None) with glock: procid, msg = subproc( request.user.login, None, mp_process_assays, request.registry.settings, batch_id, request.user.login, request.user.id ) local_procs[batch_id] = (procid, request.user.login, batch_code) msg = div()[ p('Starting assay processing task') ] seconds = 10 return render_to_response('genaf:templates/famgr/process.mako', { 'msg': msg, 'batch_code': batch_code, 'seconds': seconds, }, request = request )
def process_assays(batch_id, login, comm = None, stage = 'all'): dbh = get_dbhandler() # get assay list assay_list = get_assay_ids( batch_id ) log = [] stats = {} scanning_parameter = params.Params() # scan peaks if stage in ['all', 'scan']: stats['scan'] = scan_assays(assay_list, dbh, log, scanning_parameter, comm) # preannotate peaks if stage in ['all', 'preannotate']: stats['preannotated'] = preannotate_assays(assay_list, dbh, log, scanning_parameter, comm) # align peaks if stage in [ 'all', 'align' ]: stats['aligned'] = align_assays(assay_list, dbh, log, scanning_parameter, comm) # call peaks if stage in ['all', 'call']: stats['called'] = call_assays(assay_list, dbh, log, scanning_parameter, comm) # bin peaks if stage in ['all', 'bin']: stats['binned'] = bin_assays(assay_list, dbh, log, scanning_parameter, comm) # postannotate peaks if stage in ['all', 'postannotate']: stats['postannotated'] = postannotate_assays(assay_list, dbh, log, scanning_parameter, comm) return stats, log # ladder alignment success = failed = 0 for (assay_id, sample_code) in assay_list: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) try: if assay.status == assaystatus.preannotated: retval = assay.alignladder(excluded_peaks = None) (dpscore, rss, peaks_no, ladders_no, qcscore, remarks, method) = retval if qcscore < 0.9: log.append('WARN alignladder - ' 'low qcscore %3.2f %4.2f %5.2f %d/%d %s for %s | %s' % ( qcscore, dpscore, rss, peaks_no, ladders_no, method, sample_code, assay.filename) ) success += 1 except RuntimeError as err: log.append('ERR alignladder - assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) ) ) failed += 1 if comm and (success + failed) % 10 == 0: comm.cout = 'Aligned ladder with %d successful assay(s), %d failed assay(s)' % ( success, failed ) if comm: comm.cout = 'Aligned ladder with %d successful assay(s), %d failed assay(s)' % ( success, failed ) stats['aligned'] = (success, failed) # calling peaks success = failed = 0 for (assay_id, sample_code) in assay_list: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) try: if assay.status == assaystatus.aligned: assay.call(scanning_parameter.nonladder) success += 1 except RuntimeError as err: log.append('ERR call - assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) ) ) failed += 1 if comm and (success + failed) % 10 == 0: comm.cout = 'Called %d successful assay(s), %d failed assay(s)' % ( success, failed ) if comm: comm.cout = 'Called %d successful assay(s), %d failed assay(s)' % ( success, failed ) stats['called'] = (success, failed) # binning peaks if stage in ['all', 'bin']: stats['binned'] = bin_assays(assay_list, dbh, log, scanning_parameter, comm) if stage in ['all', 'postannotate']: stats['postannotated'] = postannotate_assays(assay_list, dbh, log, scanning_parameter, comm) return stats, log
def get_userid_func(): return get_dbhandler().session().user.id
def edit(request): user_id = int(request.matchdict['id']) if user_id < 0: return error_page(request, 'Please provide userclass ID') dbh = get_dbhandler() if request.method == 'GET': if user_id == 0: user = dbh.User() user.id = 0 else: user = dbh.get_user(user_id) editform = edit_form(user, dbh, request) return render_to_response( "rhombus:templates/generics/page.mako", { 'html': editform, }, request = request ) elif request.POST: user_d = parse_form( request.POST ) if user_d['id'] != user_id: return error_page(request, "Inconsistent data!") try: if user_id == 0: # create a new user userclass = dbh.get_userclass( user_d['userclass_id']) user = userclass.add_user( login = user_d['login'], lastname = user_d['lastname'], firstname = user_d['firstname'], email = user_d['email'], primarygroup = user_d['primarygroup_id'], ) user.institution = user_d['institution'] dbh.session().flush() request.session.flash( ( 'success', 'User [%s] has been created.' % user.login ) ) else: user = dbh.get_user(user_id) user.update( user_d ) dbh.session().flush() except RuntimeError as err: return error_page(request, str(err)) except: raise return HTTPFound(location = request.route_url('rhombus.user-view', id=user.id)) raise NotImplementedError()
def passwd(request): #user_id = int(request.matchdict.get('id', -1)) dbh = get_dbhandler() #user = dbh.get_user(user_id) #if request.user.id != user_id and not request.user.has_roles(SYSADM): # return error_page(request, # 'ERR: except system administrator, user can only change his/her own password') #if user.credential == '{X}': # return error_page(request, # 'ERR: user is using external authentication scheme!') if request.POST: user = request.user eform = password_form(user) if user.has_roles(SYSADM): # set up variables login = request.POST.get('username') current_user = dbh.get_user(user.id) target_user = dbh.get_user(login) eform.get('username').value = login if not target_user: eform.get('username').add_error('User does not exist!') return render_to_response('rhombus:templates/generics/page.mako', { 'content': str(eform) }, request = request ) else: target_user = dbh.get_user(int(request.POST.get('user_id', -1))) if target_user.id != user.id: raise RuntimeError('ERR: users can only change their own passwords!') current_user = target_user curr_pass = request.POST.get('curr_pass', None) if current_user.verify_credential(curr_pass): new_pass = request.POST.get('new_pass', None) if new_pass: if new_pass == request.POST.get('new_pass2', None): target_user.set_credential(new_pass) # reset eform eform=None else: eform.get('new_pass2').add_error('Password is not verified!') else: eform.get('new_pass').add_error('Please fill the new password!') else: eform.get('curr_pass').add_error('Incorrect password!') if eform: return render_to_response('rhombus:templates/generics/page.mako', { 'content': str(eform) }, request = request ) request.session.flash( ('success', 'Successfully changed password for user %s' % target_user.login) ) return HTTPFound(location = request.referer or '/') eform = password_form(request.user) return render_to_response('rhombus:templates/generics/page.mako', { 'content': str(eform) }, request = request )
def process_assays(batch_id, login, comm = None, stage = 'all'): dbh = get_dbhandler() # get assay list assay_list = get_assay_ids( batch_id ) log = [] stats = {} scanning_parameter = params.Params() failed = scanned = preannotated = aligned = called = binned = postannotated = subtotal = 0 total = len(assay_list) start_time = time() for (assay_id, sample_code) in assay_list: subtotal += 1 if comm: comm.cout = ( 'failed: %d | scanned: %d | pre-annotated: %d | aligned: %d | ' 'called: %d | binned: %d | post-annotated: %d | remaining: %d | estimated: %s' % ( subtotal - 1 - scanned, scanned - preannotated, preannotated - aligned, aligned - called, called - binned, binned - postannotated, postannotated, total - subtotal - 1, estimate_time(start_time, time(), subtotal - 1, total - subtotal - 1)) ) if stage in ['all', 'scan']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.assigned: assay.scan( scanning_parameter ) scanned += 1 except RuntimeError as err: log.append('ERR scanning -- assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) )) continue except ZeroDivisionError as err: log.append('ERR scanning -- FSA %s | %s - error division by zero' % ( assay.filename, sample_code)) continue if stage in ['all', 'preannotate']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.scanned: assay.preannotate( scanning_parameter ) preannotated += 1 except RuntimeError as err: log.append('ERR preannotating -- assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) )) continue if stage in ['all', 'align']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.preannotated: retval = assay.alignladder(excluded_peaks = None) (dpscore, rss, peaks_no, ladders_no, qcscore, remarks, method) = retval if qcscore < 0.9: log.append('WARN alignladder - ' 'low qcscore %3.2f %4.2f %5.2f %d/%d %s for %s | %s' % ( qcscore, dpscore, rss, peaks_no, ladders_no, method, sample_code, assay.filename) ) aligned += 1 except RuntimeError as err: log.append('ERR aligning ladder - assay %s | %s - error: %s' % (assay.filename, sample_code, str(err) ) ) continue if stage in ['all', 'call']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.aligned: assay.call( scanning_parameter ) called += 1 except RuntimeError as err: log.append('ERR calling -- assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) )) continue if stage in ['all', 'bin']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.called: assay.bin( scanning_parameter ) binned += 1 except RuntimeError as err: log.append('ERR binning -- assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) )) continue if stage in ['all', 'postannotate']: try: with transaction.manager: assay = dbh.get_assay_by_id(assay_id) if assay.status == assaystatus.binned: assay.postannotate( scanning_parameter ) postannotated += 1 except RuntimeError as err: log.append('ERR postannotating -- assay %s | %s - error: %s' % ( assay.filename, sample_code, str(err) )) continue stats = { 'failed': subtotal - scanned, 'scanned': scanned - preannotated, 'preannotated': preannotated - aligned, 'aligned': aligned - called, 'called': called - binned, 'binned': binned - postannotated, 'postannotated': postannotated } if comm: comm.cout = ( 'failed: %d | scanned: %d | pre-annotated: %d | aligned: %d | ' 'called: %d | binned: %d | post-annotated: %d' % ( stats['failed'], stats['scanned'], stats['preannotated'], stats['aligned'], stats['called'], stats['binned'], stats['postannotated'], ) ) return stats, log