def add_new_sequence(sequence): ''' Method called when a new sequence is created on GDV. It should import fast from JBrowse ''' print 'add new sequence' file_url = Assembly(sequence).get_sqlite_url() print file_url out = os.path.join(filemanager.temporary_directory(), 'Genes.sql') fileinfo = filemanager.FileInfo(inputtype='url', inpath=file_url, trackname='Genes', extension='sql', outpath=out, admin=True) print fileinfo user = DBSession.query(User).filter(User.key == constants.admin_user_key()).first() user_info = {'id': user.id, 'name': user.name, 'email': user.email} sequence_info = {'id': sequence.id, 'name': sequence.name} # track t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() # send task async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id) t.task_id = async.task_id DBSession.add(t) sequence.default_tracks.append(t) DBSession.add(sequence) DBSession.flush()
def callback(self, *args, **kw): print kw job = DBSession.query(Job).filter(Job.ext_task_id == kw['task_id']).first() project = DBSession.query(Project).filter(Project.id == int(kw['pid'])).first() if project is None or project.key != str(kw['pkey']): raise Exception('Project not valid') if job.project_id != project.id: raise Exception('Job not valid') status = str(kw['status']) job.status = status if status.lower() in ['error', 'failed']: job.traceback = kw['error'] elif status == 'SUCCESS': results = json.loads(kw['results']) for result in results: bres = Bresults() bres.job_id = job.id bres.output_type = str(result.get('type', 'not defined')) bres.is_file = result.get('is_file', False) path = str(result.get('path', '')) bres.path = path bres.data = str(result.get('value', '')) is_track = result.get('type', '') == 'track' if is_track: out = os.path.join(filemanager.temporary_directory(), os.path.split(path)[-1]) fileinfo = filemanager.FileInfo(inputtype='fsys', inpath=path, outpath=out, admin=False) sequence = project.sequence user = DBSession.query(User).filter(User.key == str(kw['key'])).first() if user.email != str(kw['mail']): raise Exception("Wrong user") user_info = {'id': user.id, 'name': user.name, 'email': user.email} sequence_info = {'id': sequence.id, 'name': sequence.name} t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id, project.id) t.task_id = async.task_id bres.track_id = t.id bres.is_track = is_track DBSession.add(bres) DBSession.flush() return {}
def add_new_sequence(sequence): ''' Method called when a new sequence is created on GDV. It should import fast from JBrowse ''' print 'add new sequence' file_url = Assembly(sequence).get_sqlite_url() print file_url out = os.path.join(filemanager.temporary_directory(), 'Genes.sql') fileinfo = filemanager.FileInfo(inputtype='url', inpath=file_url, trackname='Genes', extension='sql', outpath=out, admin=True) print fileinfo user = DBSession.query(User).filter( User.key == constants.admin_user_key()).first() user_info = {'id': user.id, 'name': user.name, 'email': user.email} sequence_info = {'id': sequence.id, 'name': sequence.name} # track t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() # send task async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id) t.task_id = async .task_id DBSession.add(t) sequence.default_tracks.append(t) DBSession.add(sequence) DBSession.flush()
def callback(self, *args, **kw): print kw job = DBSession.query(Job).filter( Job.ext_task_id == kw['task_id']).first() project = DBSession.query(Project).filter( Project.id == int(kw['pid'])).first() if project is None or project.key != str(kw['pkey']): raise Exception('Project not valid') if job.project_id != project.id: raise Exception('Job not valid') status = str(kw['status']) job.status = status if status.lower() in ['error', 'failed']: job.traceback = kw['error'] elif status == 'SUCCESS': results = json.loads(kw['results']) for result in results: bres = Bresults() bres.job_id = job.id bres.output_type = str(result.get('type', 'not defined')) bres.is_file = result.get('is_file', False) path = str(result.get('path', '')) bres.path = path bres.data = str(result.get('value', '')) is_track = result.get('type', '') == 'track' if is_track: out = os.path.join(filemanager.temporary_directory(), os.path.split(path)[-1]) fileinfo = filemanager.FileInfo(inputtype='fsys', inpath=path, outpath=out, admin=False) sequence = project.sequence user = DBSession.query(User).filter( User.key == str(kw['key'])).first() if user.email != str(kw['mail']): raise Exception("Wrong user") user_info = { 'id': user.id, 'name': user.name, 'email': user.email } sequence_info = {'id': sequence.id, 'name': sequence.name} t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id, project.id) t.task_id = async .task_id bres.track_id = t.id bres.is_track = is_track DBSession.add(bres) DBSession.flush() return {}
def create(self, *args, **kw): user = handler.user.get_user_in_session(request) # get sequence sequence = None project_id = None debug('Create track %s' % kw) debug('Find sequence', 1) if 'assembly' in kw and kw.get('assembly'): assembly = int(kw.get('assembly')) sequence = DBSession.query(Sequence).filter(Sequence.id == assembly).first() elif 'sequence_id' in kw and kw.get('sequence_id'): sequence_id = int(kw.get('sequence_id')) sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first() elif 'sequence_id' in kw and kw.get('sequence_id'): sequence_id = int(kw.get('sequence_id')) sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first() elif 'project_id' in kw and kw.get('project_id'): project_id = int(kw.get('project_id')) project = DBSession.query(Project).filter(Project.id == project_id).first() if project is None: return reply.error(request, 'Project with id %s not found on GDV.' % project_id, tg.url('./new', {'pid': project_id}), {}) sequence = DBSession.query(Sequence).filter(Sequence.id == project.sequence_id).first() if not sequence: return reply.error(request, 'Sequence not found on GDV.', tg.url('./new'), {'pid': project_id}) debug('%s' % sequence.name, 2) # know if file is comming from url, fileupload or filsystem filetoget = None inputtype = None debug('Find inputtype', 1) if 'url' in kw and kw.get('url'): debug('from url', 2) filetoget = kw.get('url') if not filetoget.startswith('http://'): filetoget = 'http://%s' % filetoget inputtype = 'url' elif 'fsys' in kw and kw.get('fsys'): debug('fsys', 2) filetoget = kw.get('fsys') inputtype = 'fsys' elif 'file_upload' in kw and kw.get('file_upload') is not None and kw['file_upload'] != '': debug('file upload %s' % kw.get('file_upload'), 2) filetoget = kw.get('file_upload') inputtype = 'fu' if filetoget is None: return reply.error(request, 'No file to upload', tg.url('./new'), {'pid': project_id}) debug('file2get: %s, intype: %s' % (filetoget, inputtype), 2) # get file name debug('Find track name', 1) trackname = None if 'trackname' in kw and kw.get('trackname'): debug('i params', 2) trackname = kw.get('trackname') else: if inputtype == 'url': debug('trackname from url', 2) trackname = os.path.split(filetoget)[1].split('?')[0] elif inputtype == 'fsys': debug('trackname from fsys', 2) trackname = os.path.split(filetoget)[-1] elif inputtype == 'fu': debug('trackname from fu', 2) trackname = filetoget.filename if trackname is None: return reply.error(request, 'No trackname found', tg.url('./new'), {'pid': project_id}) debug('%s' % trackname, 2) # get extension extension = None if 'extension' in kw and kw.get('extension'): extension = kw.get('extension') elif 'ext' in kw and kw.get('ext'): extension = kw.get('ext') else: extension = os.path.splitext(trackname)[-1] if extension is None or extension == '': if inputtype == 'url': debug('extension from url', 2) extension = os.path.splitext(os.path.split(filetoget)[1].split('?')[0])[-1] elif inputtype == 'fsys': debug('extension from fsys', 2) extension = os.path.splitext(os.path.split(filetoget)[-1])[-1] elif inputtype == 'fu': debug('extension from fu', 2) extension = os.path.splitext(filetoget.filename)[-1] if extension is None or extension == '': return reply.error(request, 'No extension found', tg.url('./new'), {'pid': project_id}) if extension.startswith('.'): extension = extension[1:] extension = extension.lower() # is the track "admin" admin = False if 'track_admin' in kw and kw.get('track_admin'): # check if really admin group_admin = DBSession.query(Group).filter(Group.id == constants.group_admins_id).first() if user in group_admin.users: admin = True debug('admin: %s' % admin, 1) #store information in a dummy object out = os.path.join(filemanager.temporary_directory(), trackname) fileinfo = filemanager.FileInfo(inputtype=inputtype, inpath=filetoget, trackname=trackname, extension=extension, outpath=out, admin=admin) debug('fileinfo: %s' % fileinfo, 1) # get additionnal information user_info = {'id': user.id, 'name': user.name, 'email': user.email} sequence_info = {'id': sequence.id, 'name': sequence.name} #upload the track it's from file_upload if inputtype == 'fu': debug('Download', 1) fileinfo.download() debug('fileinfo: %s' % fileinfo, 1) # create a track that the user can see something t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() # send task async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id, project_id) t.task_id = async.task_id DBSession.add(t) DBSession.flush() debug('End create') return reply.normal(request, 'Processing launched.', '/tracks/', {'track_id': t.id, 'pid': project_id})