Example #1
0
    def get(self):
        # Builder options
        builder_kwargs = {}
        for a in ['starting_reaction', 'model_name', 'map_name', 'map_json',
                  'reaction_no_data_color', 'reaction_no_data_size',
                  'metabolite_no_data_color', 'metabolite_no_data_size',
                  'hide_secondary_nodes']:
            args = self.get_arguments(a)
            if len(args)==1:
                builder_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))
        # array args
        for a in ['quick_jump', 'metabolite_size_range', 'metabolite_color_range',
                  'reaction_size_range', 'reaction_color_range', 'gene_styles']:
            args = self.get_arguments(a + '[]')
            if len(args) > 0:
                builder_kwargs[a] = args

        # js source
        args = self.get_arguments('js_source')
        js_source = args[0] if len(args) == 1 else 'web'

        # example data
        def load_data_file(rel_path):
            """Load a JSON file with relative path."""
            try:
                with open(join(root_directory, rel_path), 'r') as f:
                    return json.load(f)
            except:
                logging.warn('Could not load testing_data file: %s' % rel_path)
        if len(self.get_arguments('testing_data')) > 0:
            r_filepath = 'escher/testing_data/reaction_data_iJO1366.json'
            builder_kwargs['reaction_data'] = load_data_file(r_filepath)
            m_filepath = 'escher/testing_data/metabolite_data_iJO1366.json'
            builder_kwargs['metabolite_data'] = load_data_file(m_filepath)

        # display options
        display_kwargs = {'minified_js': True,
                          'scroll_behavior': 'pan',
                          'menu': 'all'}

        # keyword
        for a in ['menu', 'scroll_behavior', 'minified_js',
                  'auto_set_data_domain', 'never_ask_before_quit',
                  'enable_editing']:
            args = self.get_arguments(a)
            if len(args)==1:
                display_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))

        # make the builder
        builder = Builder(safe=True, **builder_kwargs)
        html = builder._get_html(js_source=js_source, enable_keys=True,
                                 html_wrapper=True, fill_screen=True,
                                 height='100%', **display_kwargs)

        self.set_header("Content-Type", "text/html")
        self.serve(html)
Example #2
0
    def get(self, dev_path, offline_path, kind, path):
        # builder vs. viewer & dev vs. not dev
        js_source = ('dev' if (dev_path is not None) else
                     ('local' if (offline_path is not None) else
                      'web'))
        enable_editing = (kind=='builder')
        
        # Builder options
        builder_kwargs = {}
        for a in ['starting_reaction', 'model_name', 'map_name', 'map_json']:
            args = self.get_arguments(a)
            if len(args)==1:
                builder_kwargs[a] = args[0]

        # make the builder
        builder = Builder(safe=True, **builder_kwargs)
            
        # display options
        display_kwargs = {'minified_js': True,
                          'scroll_behavior': 'pan',
                          'menu': 'all'}
        # keyword
        for a in ['menu', 'scroll_behavior', 'minified_js']:
            args = self.get_arguments(a)
            if len(args)==1:
                display_kwargs[a] = args[0]

        # get the html
        html = builder._get_html(js_source=js_source, enable_editing=enable_editing,
                                 enable_keys=True, html_wrapper=True, fill_screen=True,
                                 height='100%', **display_kwargs)
        
        self.set_header("Content-Type", "text/html")
        self.serve(html)
Example #3
0
    def get(self):
        # Builder options
        builder_kwargs = {}
        for a in ['starting_reaction', 'model_name', 'map_name', 'map_json',
                  'reaction_no_data_color', 'reaction_no_data_size',
                  'metabolite_no_data_color', 'metabolite_no_data_size',
                  'hide_secondary_nodes']:
            args = self.get_arguments(a)
            if len(args)==1:
                builder_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))
        # array args
        for a in ['quick_jump', 'metabolite_size_range', 'metabolite_color_range',
                  'reaction_size_range', 'reaction_color_range', 'gene_styles']:
            args = self.get_arguments(a + '[]')
            if len(args) > 0:
                builder_kwargs[a] = args

        # js source
        args = self.get_arguments('js_source')
        js_source = args[0] if len(args) == 1 else 'web'

        # example data
        def load_data_file(rel_path):
            """Load a JSON file with relative path."""
            try:
                with open(join(root_directory, rel_path), 'r') as f:
                    return json.load(f)
            except:
                logging.warn('Could not load example_data file: %s' % rel_path)
        if len(self.get_arguments('example_data')) > 0:
            r_filepath = 'escher/example_data/reaction_data_iJO1366.json'
            builder_kwargs['reaction_data'] = load_data_file(r_filepath)
            m_filepath = 'escher/example_data/metabolite_data_iJO1366.json'
            builder_kwargs['metabolite_data'] = load_data_file(m_filepath)

        # display options
        display_kwargs = {'minified_js': True,
                          'scroll_behavior': 'pan',
                          'menu': 'all'}

        # keyword
        for a in ['menu', 'scroll_behavior', 'minified_js',
                  'auto_set_data_domain', 'never_ask_before_quit',
                  'enable_editing']:
            args = self.get_arguments(a)
            if len(args)==1:
                display_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))

        # make the builder
        builder = Builder(safe=True, **builder_kwargs)
        html = builder._get_html(js_source=js_source, enable_keys=True,
                                 html_wrapper=True, fill_screen=True,
                                 height='100%', **display_kwargs)

        self.set_header("Content-Type", "text/html")
        self.serve(html)
Example #4
0
 def get(self, path):
     try:
         kind, organism, name = path.strip('/').split('/')
     except (TypeError, ValueError):
         raise Exception('invalid path %s' % path)
     if kind == 'maps':
         b = Builder(map_name=name)
         self.set_header('Content-Type', 'application/json')
         self.serve(b.loaded_map_json)
     else:
         b = Builder(model_name=name)
         self.set_header('Content-Type', 'application/json')
         self.serve(b.loaded_model_json)
Example #5
0
def generate_static_site():
    print('Generating static site at %s' % top_directory)

    # index file
    template = env.get_template('homepage.html')

    def static_rel(path):
        return 'py/' + path

    data = template.render(
        d3=static_rel(get_url('d3', 'local')),
        boot_css=static_rel(get_url('boot_css', 'local')),
        homepage_css=static_rel(get_url('homepage_css', 'local')),
        favicon=static_rel(get_url('favicon', 'local')),
        logo=static_rel(get_url('logo', 'local')),
        documentation=get_url('documentation', protocol='https'),
        github=get_url('github', protocol='https'),
        github_releases=get_url('github_releases', protocol='https'),
        homepage_js=static_rel(get_url('homepage_js', 'local')),
        version=__version__,
        map_download_url=get_url('map_download', 'local'),
        web_version=True,
        server_index_url=static_rel(get_url('server_index', 'local')))

    with open(join(top_directory, 'index.html'), 'wb') as f:
        f.write(data.encode('utf-8'))

    # viewer and builder
    # make the builder
    builder = Builder(safe=True, id='static_map')

    filepath = join(top_directory, 'builder')
    with open(join(root_directory, get_url('server_index', source='local')),
              'r') as f:
        index_json = f.read()
    html = builder.save_html(filepath=filepath,
                             overwrite=True,
                             js_source='local',
                             protocol=None,
                             minified_js=True,
                             static_site_index_json=index_json)

    # copy over the source maps
    escher_map = get_url('escher_min', 'local') + '.map'
    builder_css_map = get_url('builder_css_min', 'local') + '.map'
    shutil.copy(join(root_directory, escher_map),
                join(top_directory, 'builder', escher_map))
    shutil.copy(join(root_directory, builder_css_map),
                join(top_directory, 'builder', builder_css_map))
Example #6
0
def generate_static_site():
    print('Generating static site at %s' % root_directory)

    # index file
    template = env.get_template('index.html')

    data = template.render(d3=get_url('d3', 'local'),
                           boot_css=get_url('boot_css', 'local'),
                           index_css=get_url('index_css', 'local'),
                           favicon=get_url('favicon', 'local'),
                           logo=get_url('logo', 'local'),
                           documentation=get_url('documentation', protocol='https'),
                           github=get_url('github', protocol='https'),
                           github_releases=get_url('github_releases', protocol='https'),
                           index_js=get_url('index_js', 'local'),
                           index_gh_pages_js=get_url('index_gh_pages_js', 'local'),
                           version=__version__,
                           map_download=get_url('map_download', 'local'),
                           web_version=True,
                           server_index_url=get_url('server_index', 'local'),
                           # server_index=
                           # local_index=
                           can_dev=False,
                           # can_dev_js=
                           )

    with open(join(root_directory, 'index.html'), 'w') as f:
        f.write(data.encode('utf-8'))

    # viewer and builder
    for kind in ['viewer', 'builder']:
        for minified_js in [True, False]:
            js_source = 'local'
            enable_editing = (kind=='builder')

            # make the builder
            with open(join(root_directory, get_url('builder_embed_css', 'local')), 'r') as f:
                css = f.read()
            builder = Builder(embedded_css=css, safe=True, id='static')

            filepath = join(root_directory,
                            '%s%s.html' % (kind, '' if minified_js else '_not_minified'))
            with open(join(root_directory, get_url('server_index', source='local')), 'r') as f:
                index_json = f.read()
            html = builder.save_html(filepath=filepath,
                                     js_source=js_source,
                                     minified_js=minified_js,
                                     enable_editing=enable_editing,
                                     static_site_index_json=index_json)
Example #7
0
def generate_static_site():
    print('Generating static site at %s' % top_directory)

    # index file
    template = env.get_template('homepage.html')

    def static_rel(path):
        return 'py/' + path

    data = template.render(d3=static_rel(get_url('d3', 'local')),
                           boot_css=static_rel(get_url('boot_css', 'local')),
                           homepage_css=static_rel(get_url('homepage_css', 'local')),
                           favicon=static_rel(get_url('favicon', 'local')),
                           logo=static_rel(get_url('logo', 'local')),
                           documentation=get_url('documentation', protocol='https'),
                           github=get_url('github', protocol='https'),
                           github_releases=get_url('github_releases', protocol='https'),
                           homepage_js=static_rel(get_url('homepage_js', 'local')),
                           version=__version__,
                           map_download_url=get_url('map_download', 'local'),
                           web_version=True,
                           server_index_url=static_rel(get_url('server_index', 'local')))

    with open(join(top_directory, 'index.html'), 'wb') as f:
        f.write(data.encode('utf-8'))

    # viewer and builder
    # make the builder
    builder = Builder(safe=True, id='static_map')

    filepath = join(top_directory, 'builder')
    with open(join(root_directory, get_url('server_index', source='local')), 'r') as f:
        index_json = f.read()
    html = builder.save_html(filepath=filepath,
                             overwrite=True,
                             js_source='local',
                             protocol=None,
                             minified_js=True,
                             static_site_index_json=index_json)

    # copy over the source maps
    escher_map = get_url('escher_min', 'local') + '.map'
    builder_css_map = get_url('builder_css_min', 'local') + '.map'
    shutil.copy(join(root_directory, escher_map), join(top_directory, 'builder', escher_map))
    shutil.copy(join(root_directory, builder_css_map), join(top_directory, 'builder', builder_css_map))
Example #8
0
    def get(self, kind, path):
        # builder vs. viewer
        enable_editing = (kind=='builder')

        # Builder options
        builder_kwargs = {}
        for a in ['starting_reaction', 'model_name', 'map_name', 'map_json',
                  'reaction_no_data_color', 'reaction_no_data_size',
                  'metabolite_no_data_color', 'metabolite_no_data_size',
                  'hide_secondary_nodes']:
            args = self.get_arguments(a)
            if len(args)==1:
                builder_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))
        # array args
        for a in ['quick_jump', 'metabolite_size_range', 'metabolite_color_range',
                  'reaction_size_range', 'reaction_color_range', 'gene_styles']:
            args = self.get_arguments(a + '[]')
            if len(args) > 0:
                builder_kwargs[a] = args

        # js source
        args = self.get_arguments('js_source')
        js_source = args[0] if len(args) == 1 else 'web'

        # if the server is running locally, then the embedded css must be loaded
        # asynchronously using the same server thread.
        if js_source in ['dev', 'local']:
            global PORT
            url = get_url('builder_embed_css',
                          source='local',
                          local_host='http://localhost:%d' % PORT)
            response = yield gen.Task(AsyncHTTPClient().fetch, url)
            if response.code != 200 or response.body is None:
                raise Exception('Could not load embedded_css from %s' % url)

            builder_kwargs['embedded_css'] = (response.body
                                              .decode('utf-8')
                                              .replace('\n', ' '))

        # example data
        def load_data_file(rel_path):
            """Load a JSON file with relative path."""
            try:
                with open(join(root_directory, rel_path), 'r') as f:
                    return json.load(f)
            except:
                logging.warn('Could not load example_data file: %s' % rel_path)
        if len(self.get_arguments('example_data')) > 0:
            r_filepath = 'escher/example_data/reaction_data_iJO1366.json'
            builder_kwargs['reaction_data'] = load_data_file(r_filepath)
            m_filepath = 'escher/example_data/metabolite_data_iJO1366.json'
            builder_kwargs['metabolite_data'] = load_data_file(m_filepath)

        # make the builder
        builder = Builder(safe=True, **builder_kwargs)

        # display options
        display_kwargs = {'minified_js': True,
                          'scroll_behavior': 'pan',
                          'menu': 'all'}

        # keyword
        for a in ['menu', 'scroll_behavior', 'minified_js',
                  'auto_set_data_domain', 'never_ask_before_quit']:
            args = self.get_arguments(a)
            if len(args)==1:
                display_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))

        html = builder._get_html(js_source=js_source, enable_editing=enable_editing,
                                 enable_keys=True, html_wrapper=True, fill_screen=True,
                                 height='100%', **display_kwargs)

        self.set_header("Content-Type", "text/html")
        self.serve(html)
Example #9
0
    def get(self, dev_path, offline_path, kind, path):
        # builder vs. viewer & dev vs. not dev
        js_source = ('dev' if (dev_path is not None) else
                     ('local' if (offline_path is not None) else
                      'web'))
        enable_editing = (kind=='builder')
        
        # Builder options
        builder_kwargs = {}
        for a in ['starting_reaction', 'model_name', 'map_name', 'map_json']:
            args = self.get_arguments(a)
            if len(args)==1:
                builder_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))

        # if the server is running locally, then the embedded css must be loaded
        # asynchronously using the same server thread.
        if js_source in ['dev', 'local']:  
            global PORT          
            response = yield gen.Task(AsyncHTTPClient().fetch,
                                      join('http://localhost:%d' % PORT, urls.builder_embed_css_local))
            print response
            builder_kwargs['embedded_css'] = response.body.replace('\n', ' ')

        # example data
        def load_data_file(rel_path):
            """Load a JSON file with relative path."""
            try:
                with open(join(directory, rel_path), 'r') as f:
                    return json.load(f)
            except:
                logging.warn('Could not load example_data file: %s' % rel_path)
        if len(self.get_arguments('example_data')) > 0:
            r_filepath = 'example_data/reaction_data_iJO1366.json'
            builder_kwargs['reaction_data'] = load_data_file(r_filepath)
            m_filepath = 'example_data/metabolite_data_iJO1366.json'
            builder_kwargs['metabolite_data'] = load_data_file(m_filepath)
            
        # make the builder        
        builder = Builder(safe=True, **builder_kwargs)
            
        # display options
        display_kwargs = {'minified_js': True,
                          'scroll_behavior': 'pan',
                          'menu': 'all'}
            
        # keyword
        for a in ['menu', 'scroll_behavior', 'minified_js', 'auto_set_data_domain']:
            args = self.get_arguments(a)
            if len(args)==1:
                display_kwargs[a] = (True if args[0].lower()=='true' else
                                     (False if args[0].lower()=='false' else
                                      args[0]))

        html = builder._get_html(js_source=js_source, enable_editing=enable_editing,
                                 enable_keys=True, html_wrapper=True, fill_screen=True,
                                 height='100%', **display_kwargs)
        
        self.set_header("Content-Type", "text/html")
        self.serve(html)