Пример #1
0
    def post(self):
        vienna_data = self.get_argument('data', default=None)

        log = {
            'path': self.request.uri,
            'ip': self.request.remote_ip,
            'tool': 'rnaplot',
            'method': self.request.method,
            'date': datetime.datetime.now(),
            'status': 'running'
        }

        logs_db['webservices'].insert(log)

        rnas, base_pairs = parse_vienna(vienna_data)
        rnaplot = Rnaplot()
        plot = rnaplot.plot(base_pairs[0], rnas[0])
        coords = []
        for (index, row) in plot.iterrows():
            coords.append([row['x'], row['y']])
        logs_db['webservices'].update(
            {'_id': log['_id']},
            {'$set': {
                'status': 'done',
                'date': datetime.datetime.now()
            }})
        self.write(json_encode(coords))
Пример #2
0
    def post(self):
        log = {
            '_id': str(ObjectId()),
            'path': self.request.uri,
            'tool': 'rnaplot',
            'ip': self.request.remote_ip,
            'method': self.request.method,
            'date': datetime.datetime.now()
        }

        logs_db['webservices'].insert(log)

        secondary_structure = self.get_argument('secondary_structure', default = None)
        api_key = self.get_argument('api_key', default = None)

        if not is_registered_user(api_key) or not 'rnaplot' in enabled_algorithms:
            self.send_error(status_code=401)
        else:
            rnas, secondary_structures = parse_vienna(secondary_structure)
            self.write(Rnaplot().plot(secondary_structures[0], rnas[0], raw_output = True))
Пример #3
0
    def post(self):
        vienna_data = self.get_argument('data', default = None)

        log = {
            'path': self.request.uri,
            'ip': self.request.remote_ip,
            'tool': 'rnaplot',
            'method': self.request.method,
            'date': datetime.datetime.now(),
            'status': 'running'
        }

        logs_db['webservices'].insert(log)

        rnas, base_pairs = parse_vienna(vienna_data)
        rnaplot = Rnaplot()
        plot =  rnaplot.plot(base_pairs[0], rnas[0])
        coords = []
        for (index, row) in plot.iterrows():
            coords.append([row['x'], row['y']])
        logs_db['webservices'].update({ '_id': log['_id'] }, {'$set': { 'status' : 'done', 'date':datetime.datetime.now()}})
        self.write(json_encode(coords))
Пример #4
0
    def post(self):
        log = {
            '_id': str(ObjectId()),
            'path': self.request.uri,
            'tool': 'rnaplot',
            'ip': self.request.remote_ip,
            'method': self.request.method,
            'date': datetime.datetime.now(),
            'status': 'running'
        }

        logs_db['webservices'].insert(log)

        secondary_structure = self.get_argument('secondary_structure', default = None)
        api_key = self.get_argument('api_key', default = None)

        if not is_registered_user(api_key) or not 'rnaplot' in enabled_algorithms:
            logs_db['webservices'].update({ '_id': log['_id'] }, {'$set': { 'status' : 'error', 'date':datetime.datetime.now()}})
            self.send_error(status_code=401)
        else:
            rnas, secondary_structures = parse_vienna(secondary_structure)
            logs_db['webservices'].update({ '_id': log['_id'] }, {'$set': { 'status' : 'done', 'date':datetime.datetime.now()}})
            self.write(Rnaplot().plot(secondary_structures[0], rnas[0], raw_output = True))
Пример #5
0
    def on_message(self, message):
        message = ujson.loads(message)
        if message['header'] == 'new external tool':
            for websocket in websockets:
                if self == websocket:
                    external_tools_2_websockets[message['id']] = websocket
        elif message['header'] == 'plot 2d':
            #rnas, secondary_structures = parse_vienna(message['data'])
            #self.write_message( {
            #        'header': '2d plot',
            #            'data': Rnaplot().plot(secondary_structures[0], rnas[0], raw_output = True)
            #            })
            rnas, secondary_structures = parse_vienna(message['data'])
            rna = rnas[0]
            base_pairs = secondary_structures[0]
            ss = base_pairs_to_secondary_structure(rna, base_pairs)
            ss.find_junctions()

            coords = Rnaplot().plot(base_pairs, rna)

            ss_json = {'rna': {'name': rna.name, 'sequence': rna.sequence}}

            helices_descriptions = []
            for helix in ss.helices:
                helices_descriptions.append(helix)
            ss_json['helices'] = helices_descriptions

            sstrand_descriptions = []
            for sstrand in ss.single_strands:
                sstrand_descriptions.append(sstrand)
            ss_json['single-strands'] = sstrand_descriptions

            tertiary_descriptions = []
            for tertiary in ss.tertiary_interactions:
                sstrand_descriptions.append(tertiary)
            ss_json['single-strands'] = sstrand_descriptions

            ss_json['coords'] = []
            for index, row in coords.iterrows():
                ss_json['coords'].append([int(row['x']), int(row['y'])])

            self.write_message({'header': '2d plot', 'data': ss_json})
        elif message['header'] == 'server load':
            db = mongodb['logs']
            now = datetime.datetime.now()
            data = []
            for i in xrange(1, 61):
                counts = {'y': "-%im" % i}
                time_range = {
                    "$gt": now - datetime.timedelta(minutes=i),
                    "$lte": now - datetime.timedelta(minutes=i - 1)
                }

                counts['running'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'running'
                }).count()

                counts['error'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'error'
                }).count()

                counts['done'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'done'
                }).count()

                data.append(counts)
            answer = {'header': 'server load', 'data': data}
            self.write_message(answer, binary=False)
        elif message['header'] == 'init booquet':
            junction_diameter = 20
            rfam = Rfam(use_website=True)
            aligned_rnas, species, consensus2D = rfam.get_entry(
                rfam_id=message['rfam_id'], nse_labels=0)
            print consensus2D
            structural_alignment = to_clustalw(consensus2D, aligned_rnas)
            booquet_json = consensus2d_to_booquet(
                structural_alignment, junction_diameter=junction_diameter)
            answer = {'header': 'init booquet'}
            answer['booquet_json'] = booquet_json
            answer['junction_diameter'] = junction_diameter
            self.write_message(answer, binary=False)
Пример #6
0
    def on_message(self, message):
        message = ujson.loads(message)
        if message['header'] == 'new external tool':
            for websocket in websockets:
                if self == websocket:
                    external_tools_2_websockets[message['id']] = websocket
        elif message['header'] == 'plot 2d':
            #rnas, secondary_structures = parse_vienna(message['data'])
            #self.write_message( {
        #        'header': '2d plot',
    #            'data': Rnaplot().plot(secondary_structures[0], rnas[0], raw_output = True)
#            })
            rnas, secondary_structures = parse_vienna(message['data'])
            rna = rnas[0]
            base_pairs = secondary_structures[0]
            ss = base_pairs_to_secondary_structure(rna, base_pairs)
            ss.find_junctions()

            coords = Rnaplot().plot(base_pairs, rna)

            ss_json = {
                'rna': {
                    'name': rna.name,
                    'sequence': rna.sequence
                }
            }

            helices_descriptions = []
            for helix in ss.helices:
                helices_descriptions.append(helix)
            ss_json['helices'] = helices_descriptions

            sstrand_descriptions = []
            for sstrand in ss.single_strands:
                sstrand_descriptions.append(sstrand)
            ss_json['single-strands'] = sstrand_descriptions

            tertiary_descriptions = []
            for tertiary in ss.tertiary_interactions:
                sstrand_descriptions.append(tertiary)
            ss_json['single-strands'] = sstrand_descriptions

            ss_json['coords'] = []
            for index, row in coords.iterrows():
                ss_json['coords'].append([int(row['x']), int(row['y'])])

            self.write_message( {
                'header': '2d plot',
                'data': ss_json
            })
        elif message['header'] == 'server load':
            db = mongodb['logs']
            now = datetime.datetime.now()
            data = []
            for i in xrange(1, 61):
                counts = {'y': "-%im"%
                i}
                time_range = {
                    "$gt": now - datetime.timedelta(minutes = i),
                    "$lte": now - datetime.timedelta(minutes = i-1)
                    }

                counts['running'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'running'
                }).count()

                counts['error'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'error'
                }).count()

                counts['done'] = db['webservices'].find({
                    "date": time_range,
                    "status": 'done'
                }).count()

                data.append(counts)
            answer = {
                'header': 'server load',
                'data': data
                }
            self.write_message(answer, binary = False)
        elif message['header'] == 'init booquet':
            junction_diameter = 20
            rfam = Rfam(use_website = True)
            aligned_rnas, species, consensus2D = rfam.get_entry(rfam_id = message['rfam_id'], nse_labels = 0)
            print consensus2D
            structural_alignment = to_clustalw(consensus2D, aligned_rnas)
            booquet_json = consensus2d_to_booquet(structural_alignment, junction_diameter = junction_diameter)
            answer = {'header': 'init booquet'}
            answer['booquet_json'] = booquet_json
            answer['junction_diameter'] = junction_diameter
            self.write_message(answer, binary = False)
Пример #7
0
    def on_message(self, message):
        message = ujson.loads(message)
        if message['header'] == 'new external tool':
            for websocket in websockets:
                if self == websocket:
                    external_tools_2_websockets[message['id']] = websocket
        elif message['header'] == 'plot 2d':
            #rnas, secondary_structures = parse_vienna(message['data'])
            #self.write_message( {
        #        'header': '2d plot',
    #            'data': Rnaplot().plot(secondary_structures[0], rnas[0], raw_output = True)
#            })
            rnas, secondary_structures = parse_vienna(message['data'])
            rna = rnas[0]
            base_pairs = secondary_structures[0]
            ss = base_pairs_to_secondary_structure(rna, base_pairs)
            ss.find_junctions()

            coords = Rnaplot().plot(base_pairs, rna)

            ss_json = {
                'rna': {
                    'name': rna.name,
                    'sequence': rna.sequence
                }
            }

            helices_descriptions = []
            for helix in ss.helices:
                helices_descriptions.append(helix)
            ss_json['helices'] = helices_descriptions

            sstrand_descriptions = []
            for sstrand in ss.single_strands:
                sstrand_descriptions.append(sstrand)
            ss_json['single-strands'] = sstrand_descriptions

            tertiary_descriptions = []
            for tertiary in ss.tertiary_interactions:
                sstrand_descriptions.append(tertiary)
            ss_json['single-strands'] = sstrand_descriptions

            ss_json['coords'] = []
            for index, row in coords.iterrows():
                ss_json['coords'].append([int(row['x']), int(row['y'])])

            self.write_message( {
                'header': '2d plot',
                'data': ss_json
            })
        elif message['header'] == 'webservices usage':
            db = mongodb['logs']
            now = datetime.datetime.now()
            data = []
            for i in xrange(1, 24):
                counts = {'y': "-%ih"%
                i}
                time_range = {
                    "$gt": now - datetime.timedelta(hours = i),
                    "$lte": now - datetime.timedelta(hours = i-1)
                    }
                counts['RNAfold'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'rnafold'
                }).count()

                counts['RNAsubopt'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'rnasubopt'
                }).count()

                counts['RNAalifold'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'rnaalifold'
                }).count()

                counts['Contrafold'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'contrafold'
                }).count()

                counts['RNAplot'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'rnaplot'
                }).count()

                counts['Mlocarna'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'mlocarna'
                }).count()

                counts['RNAVIEW'] = db['webservices'].find({
                    "date": time_range,
                    "tool": 'rnaview'
                }).count()

                data.append(counts)
            answer = {
                'header': 'webservices usage',
                'data': data
                }
            self.write_message(answer, binary = False)