Ejemplo n.º 1
0
def pretty(value):
    if isinstance(value, dict):
        page = markup.page()
        page.ul(_class='dict')
        for k, v in value.items():
            if isinstance(v, list) and v:
                pretty_value = Markup.escape(', '.join(v))
            elif isinstance(v, dict) and v:
                subul = markup.page()
                subul.ul(_class='subdict')
                for subk, subv in v.items():
                    subul.li()
                    subul.span('%s: ' % subk)
                    subul.span(Markup.escape(subv))
                    subul.li.close()
                subul.ul.close()
                pretty_value = subul()
            elif v:
                pretty_value = Markup.escape(v)
            else:
                continue
            page.li()
            page.span('%s:' % k.capitalize().replace('_', ' '))
            page.span(pretty_value)
            page.li.close()
        page.ul.close()
        return page()
    elif isinstance(value, list):
        return Markup.escape(', '.join(value))
    else:
        page = markup.page()
        page.span(Markup.escape(value), _class='simple')
        return page()
Ejemplo n.º 2
0
    def __call__(self, form_field, **kwargs):
        fields = [f for f in form_field if 'csrf_token' not in f.id ]
        data_keys = [i[0] for i in self.data]
        data_keys = self.update_keys(form_field, data_keys)
        self.data = self.update_data(form_field, self.data)

        page = markup.page()
        page.label(self.label)
        page.table(id=self.id, class_='matrix')
        page.thead()
        page.tr()
        page.th(self.title, class_='category-left')
        for i, f in enumerate(fields):
            page.th(f.label.text.capitalize(), class_=i%2 and 'odd' or 'even',
                    id="%s-%d" % (self.id, i))
        page.tr.close()
        page.thead.close()

        page.tbody()
        page.tr()
        page.td(e.div(data_keys), class_='category-left')
        for i, field in enumerate(fields):
            field.choices = [(k, v) for k, v in self.data]
            odd_even = i % 2 and 'odd' or 'even'
            page.td(field(**kwargs), class_=('check-column %s' % odd_even))
        page.tr.close()

        page.tbody.close()
        page.table.close()

        return page
Ejemplo n.º 3
0
    def __call__(self, form_field, **kwargs):
        fields = [f for f in form_field if 'csrf_token' not in f.id ]
        data_keys = [i[0] for i in self.data]
        data_keys = self.update_keys(form_field, data_keys)
        self.data = self.update_data(form_field, self.data)

        page = markup.page()
        page.label(self.label)
        page.table(id='ecosystem-service-types', class_='ecosystem-service-types ecosystem')

        page.thead()
        page.tr()
        page.th('', class_='category-left')
        for i, f in enumerate(fields):
            page.th(f.label.text, class_=i%2 and 'odd' or 'even')
        page.tr.close()
        page.thead.close()

        page.tbody()
        page.tr(e.th('Type of ecosystems', colspan=form_field.COLSPAN, class_='category'))
        page.tr()
        page.td(e.div(data_keys), class_='category-left')
        for i, field in enumerate(fields):
            field.choices = [(k, v) for k, v in self.data]
            odd_even = i%2 and 'odd' or 'even'
            page.td(field(**kwargs), class_=('check-column %s' % odd_even))
        page.tr.close()

        page.tbody.close()
        page.table.close()

        return page
Ejemplo n.º 4
0
    def __call__(self, form_field, **kwargs):
        fields = [f for f in form_field if 'csrf_token' not in f.id]
        data_keys = [i[0] for i in self.data]
        data_keys = self.update_keys(form_field, data_keys)
        self.data = self.update_data(form_field, self.data)

        page = markup.page()
        page.label(self.label)
        page.table(id=self.id, class_='matrix')
        page.thead()
        page.tr()
        page.th(self.title, class_='category-left')
        for i, f in enumerate(fields):
            page.th(f.label.text.capitalize(),
                    class_=i % 2 and 'odd' or 'even',
                    id="%s-%d" % (self.id, i))
        page.tr.close()
        page.thead.close()

        page.tbody()
        page.tr()
        page.td(e.div(data_keys), class_='category-left')
        for i, field in enumerate(fields):
            field.choices = [(k, v) for k, v in self.data]
            odd_even = i % 2 and 'odd' or 'even'
            page.td(field(**kwargs), class_=('check-column %s' % odd_even))
        page.tr.close()

        page.tbody.close()
        page.table.close()

        return page
Ejemplo n.º 5
0
    def __call__(self, field, **kwargs):
        page = markup.page()
        page.ul(id=field.id)

        for subfield in field:
            page.li()
            value = field.data.get(subfield.data, '') if field.data else ''
            page.input(name=subfield.name, id=subfield.id, value=value)
            page.li.close()
        page.ul.close()
        return page()
Ejemplo n.º 6
0
    def __call__(self, field, **kwargs):
        page = markup.page()
        page.ul(id=field.id)

        for subfield in field:
            page.li()
            value = field.data.get(subfield.data, '') if field.data else ''
            page.input(name=subfield.name, id=subfield.id, value=value)
            page.li.close()
        page.ul.close()
        return page()
Ejemplo n.º 7
0
    def __call__(self, field, **kwargs):
        page = markup.page()
        page.ul(id=field.id)

        for subfield in field:
            page.li()
            value = field.data.get(subfield.data, '') if field.data else ''
            page.textarea(value, name=subfield.name, id=subfield.id,
                          class_='cell visible')
            #page.textarea.close()
            page.li.close()
        page.ul.close()
        return page()
Ejemplo n.º 8
0
    def __call__(self, field, **kwargs):
        page = markup.page()
        page.ul(id=field.id)

        for subfield in field:
            page.li()
            value = field.data.get(subfield.data, '') if field.data else ''
            page.textarea(value,
                          name=subfield.name,
                          id=subfield.id,
                          class_='cell visible')
            #page.textarea.close()
            page.li.close()
        page.ul.close()
        return page()
Ejemplo n.º 9
0
 def __call__(self, field, **kwargs):
    result = super(CustomFileInput, self).__call__(field, **kwargs)
    values = field.data
    if values and isinstance(values, list):
         page = markup.page()
         page.p('Currently uploaded files', class_="file-storage")
         page.ul(_class='file-list')
         for value in values:
             page.li()
             page.a(value,
                    href=url_for('static', filename='files/%s' % value),
                    target='_blank')
             page.li.close()
         page.ul.close()
         result += page()
    return wtf.widgets.core.HTMLString(result)
Ejemplo n.º 10
0
 def __call__(self, field, **kwargs):
     result = super(CustomFileInput, self).__call__(field, **kwargs)
     values = field.data
     if values and isinstance(values, list):
         page = markup.page()
         page.p('Currently uploaded files', class_="file-storage")
         page.ul(_class='file-list')
         for value in values:
             page.li()
             page.a(value,
                    href=url_for('static', filename='files/%s' % value),
                    target='_blank')
             page.li.close()
         page.ul.close()
         result += page()
     return wtf.widgets.core.HTMLString(result)
Ejemplo n.º 11
0
def main():

    # do Loading

    db = create_engine('sqlite:///data/' + DBFILE, echo=False)
    Session = sessionmaker(bind=db)
    session = Session()
    prot_fams_objs = session.query(Prot_Fams).all()
    UNP_rec_obj = session.query(Proteins).all()
    histrec = session.query(History).all()

    UNP_to_seqrecord = pickle.load(
        open("data/" + DBFILEINIT.replace('.db', '_') + "UNP_seqrecords.dat",
             "rb"))

    print """#############################################
#        Let's do the analysis              #
#############################################
"""
    gen_info = """********************General*******************
###There are %d unique seq strucutres 
""" % (len(UNP_rec_obj))

    p = re.compile('Full=(.+);', re.IGNORECASE)

    print '#####Summary table'
    summary_data = [[
        'Histone Family', 'Protein name', 'Organisms', 'UniProt IDs'
    ]]
    for k in prot_fams_objs:
        UNP_rec_objs = session.query(Proteins).filter(
            Proteins.family == k).order_by(Proteins.descr).all()
        summary_data.append(['######### Family: %s' % k.name])
        for i in UNP_rec_objs:
            m = p.search(i.descr)
            href = '<a href="http://www.uniprot.org/uniprot/%s">%s</a>' % (
                i.unp_id, i.unp_id)
            if (SHORT_NAMES):
                prot_data = [k.name, m.group(1), i.organism, href]
            else:
                prot_data = [k.name, i.descr, i.organism, href]
            summary_data.append(prot_data)

    print gen_info, summary_data  #,oligo_distr,organism_distr,prot_distr

    htmlfile = open('data/' + DBFILE.replace('.db', '.html'), 'wt')

    title = "Seqs from %s" % DBFILE
    header = "Seqs from %s" % DBFILE
    header += '''<script type="text/javascript" src="https://dl.dropboxusercontent.com/u/201202/js/tooltip.js"></script>
    <script type="text/javascript" src="https://dl.dropboxusercontent.com/u/201202/js/ajax.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
    $( document ).tooltip();
    });
    </script>
    <style>
    label {
    display: inline-block;
    width: 5em;
    }
    </style>'''

    footer = ""
    styles = ('layout.css', 'alt.css', 'images.css')
    page = markup.page()
    page.init(css=styles, title=title, header=header, footer=footer)
    page.p("<h1> %s </h1>" % histrec[-1].dbdescr)
    page.p("<h1> Database analysis:</h1>")
    page.br()
    page.p('<h2>History of how the database was created </h2>')
    for h in histrec:
        page.p(
            str(h.time.strftime("%Y-%m-%d %H:%M")) + ' | ' + h.dbname + ' | ' +
            h.histrec)
    page.br()
    page.p('<h2>Now comes the analysis</h2>')
    page.p(gen_info.replace('\n', '<br>'))
    page.br()
    page.p('<h2>Summary table </h2>')
    htmlcode = HTML.table(summary_data)
    page.add(htmlcode)

    #    page.p("********************Oligomeric state distribution*******************")
    #    page.p("###Olig state : Num PDBIDs : PDBIDs ")
    #    for key in sorted(NUMPDBs_with_NUMCHAINS.iterkeys()):
    #        page.p('### %s : %d' % (key, NUMPDBs_with_NUMCHAINS[key])) # , ' : ', PDBs_with_NUMCHAINS[key]
    #        for i in PDBs_with_NUMCHAINS[key]:
    #            if(OUTPUT_LINKS_TO_FILES): page.a( i, class_='internal', href='http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=%s' % i, title=mmdb_descr[i]['PdbDescr'], onmouseover="showtrail(1,1,'http://www.rcsb.org/pdb/images/%s_asym_r_500.jpg');" % i, onmouseout="hidetrail();" )
    #            else: page.a( i, class_='internal', href='http://www.rcsb.org/pdb/explore.do?structureId=%s' % i, title=mmdb_descr[i]['PdbDescr'], onmouseover="showtrail(1,1,'http://www.rcsb.org/pdb/images/%s_asym_r_500.jpg');" % i, onmouseout="hidetrail();" )
    #    page.br( )
    #    page.p(organism_distr.replace('\n','<br>').replace(' ','&nbsp;'))
    #    page.br()
    #
    #    prot_distr='*****************Protein distribution**************************\n'
    #    prot_distr+='### UniProtID | Num PDBs in database having it | Descr\n'
    #    page.p(prot_distr.replace('\n','<br>'))
    #    for key in sorted(UNPs, key=UNPs.get, reverse=True):
    #        number_pdbs_with_unp=len(session.query(PDB_UNP).filter(PDB_UNP.unp_id==key).all())
    #        pdb_ids_for_unp=""
    #        for i in session.query(PDB_UNP).filter(PDB_UNP.unp_id==key).all(): pdb_ids_for_unp+=i.pdb_id+' '
    #        page.add('### &nbsp;&nbsp;&nbsp;&nbsp;')
    #        page.a('%8s' % key, href="http://www.uniprot.org/uniprot/%s" % key)
    #        page.add('&nbsp;&nbsp;')
    #        page.a('&nbsp;&nbsp; %4d&nbsp;&nbsp;' % number_pdbs_with_unp, href='#', title=pdb_ids_for_unp)
    #        page.add('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
    #        page.add('  %s' % UNP_to_record[key].description)
    #        page.br()
    #
    #

    htmlfile.write(page.__call__())
    htmlfile.close()
    session.close()
Ejemplo n.º 12
0
def main():

    # do Loading

    db = create_engine('sqlite:///data/' + DBFILE, echo=False)
    Session = sessionmaker(bind=db)
    session = Session()
    res = session.query(PDB_UNP).all()
    histrec = session.query(History).all()
    session.close()
    UNP_to_record = pickle.load(
        open("data/" + DBFILEINIT.replace('.db', '_') + "UNP_records.dat",
             "rb"))
    mmdb_descr = pickle.load(
        open("data/" + DBFILEINIT.replace('.db', '_') + "MMDB_descr.dat",
             "rb"))
    UNPs = collections.Counter()
    PDBs = collections.Counter()
    TAXIDs = collections.Counter()
    ORGNs = collections.Counter()
    CHAINs_in_PDB = collections.Counter()
    NUMPDBs_with_NUMCHAINS = collections.Counter()
    PDBs_with_NUMCHAINS = collections.defaultdict(list)
    print "Read %d lines in table" % len(res)
    for rec in res:
        UNPs[rec.unp_id] += 1
        PDBs[rec.pdb_id] += 1
        TAXIDs[UNP_to_record[rec.unp_id].taxonomy_id[0]] += 1
        ORGNs[UNP_to_record[rec.unp_id].organism] += 1
        CHAINs_in_PDB[rec.pdb_id] += rec.unp_num
    for pdb_id in CHAINs_in_PDB:
        NUMPDBs_with_NUMCHAINS[CHAINs_in_PDB[pdb_id]] += 1
        PDBs_with_NUMCHAINS[CHAINs_in_PDB[pdb_id]].append(pdb_id)

#      print rec.pdb_id, rec.unp_id, UNP_to_record[rec.unp_id].taxonomy_id[0]
#  print vars(UNP_to_record[rec.unp_id])
    print """#############################################
#        Let's do the analysis              #
#############################################
"""
    gen_info = """********************General*******************
###There are %d unique pdb strucutres 
###There are %d unique protein ids
###There are %d unique taxonomic organisms present 
###Total protein chains in set %d""" % (
        len(PDBs), len(UNPs), len(TAXIDs),
        sum([
            a * b for a, b in zip(NUMPDBs_with_NUMCHAINS.values(),
                                  map(int, NUMPDBs_with_NUMCHAINS.keys()))
        ]))

    oligo_distr = "********************Oligomeric state distribution*******************\n"
    oligo_distr += "###Olig state : Num PDBIDs : PDBIDs \n"
    for key in sorted(NUMPDBs_with_NUMCHAINS.iterkeys()):
        oligo_distr += '### %s : %d ' % (key, NUMPDBs_with_NUMCHAINS[key])
        for item in PDBs_with_NUMCHAINS[key]:
            oligo_distr += ' %s ' % item
        oligo_distr += '\n'
    organism_distr = '*****************Organismic distribution**************************\n'
    organism_distr += '### Num PDBs with at least one protein from organism | Organism name\n'
    for key in sorted(ORGNs, key=ORGNs.get, reverse=True):
        organism_distr += '### %8s     %s\n' % (ORGNs[key], key)

    prot_distr = '*****************Protein distribution**************************\n'
    prot_distr += '### UniProtID | Num PDBs in database having it | Descr\n'
    for key in sorted(UNPs, key=UNPs.get, reverse=True):
        number_pdbs_with_unp = len(
            session.query(PDB_UNP).filter(PDB_UNP.unp_id == key).all())
        prot_distr += '### %8s %4d     %s\n' % (key, number_pdbs_with_unp,
                                                UNP_to_record[key].description)

    print gen_info, oligo_distr, organism_distr, prot_distr

    htmlfile = open('data/' + DBFILE.replace('.db', '.html'), 'wt')

    title = "PDBids from %s" % DBFILE
    header = "PDBids from %s" % DBFILE
    header += '''<script type="text/javascript" src="https://dl.dropboxusercontent.com/u/201202/js/tooltip.js"></script>
    <script type="text/javascript" src="https://dl.dropboxusercontent.com/u/201202/js/ajax.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
    $( document ).tooltip();
    });
    </script>
    <style>
    label {
    display: inline-block;
    width: 5em;
    }
    </style>'''

    footer = ""
    styles = ('layout.css', 'alt.css', 'images.css')
    page = markup.page()
    page.init(css=styles, title=title, header=header, footer=footer)
    page.p("<h1> %s </h1>" % histrec[-1].dbdescr)
    page.p("<h1> Database analysis:</h1>")
    page.br()
    page.p('<h2>History of how the database was created </h2>')
    for h in histrec:
        page.p(
            str(h.time.strftime("%Y-%m-%d %H:%M")) + ' | ' + h.dbname + ' | ' +
            h.histrec)
    page.br()
    page.p('<h2>Now comes the analysis</h2>')
    page.p(gen_info.replace('\n', '<br>'))
    page.br()
    page.p(
        "********************Oligomeric state distribution*******************")
    page.p("###Olig state : Num PDBIDs : PDBIDs ")
    for key in sorted(NUMPDBs_with_NUMCHAINS.iterkeys()):
        page.p(
            '### %s : %d' %
            (key,
             NUMPDBs_with_NUMCHAINS[key]))  # , ' : ', PDBs_with_NUMCHAINS[key]
        for i in PDBs_with_NUMCHAINS[key]:
            if (OUTPUT_LINKS_TO_FILES):
                page.a(
                    i,
                    class_='internal',
                    href=
                    'http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=%s'
                    % i,
                    title=mmdb_descr[i]['PdbDescr'],
                    onmouseover=
                    "showtrail(1,1,'http://www.rcsb.org/pdb/images/%s_asym_r_500.jpg');"
                    % i,
                    onmouseout="hidetrail();")
            else:
                page.a(
                    i,
                    class_='internal',
                    href='http://www.rcsb.org/pdb/explore.do?structureId=%s' %
                    i,
                    title=mmdb_descr[i]['PdbDescr'],
                    onmouseover=
                    "showtrail(1,1,'http://www.rcsb.org/pdb/images/%s_asym_r_500.jpg');"
                    % i,
                    onmouseout="hidetrail();")
    page.br()
    page.p(organism_distr.replace('\n', '<br>').replace(' ', '&nbsp;'))
    page.br()

    prot_distr = '*****************Protein distribution**************************\n'
    prot_distr += '### UniProtID | Num PDBs in database having it | Descr\n'
    page.p(prot_distr.replace('\n', '<br>'))
    for key in sorted(UNPs, key=UNPs.get, reverse=True):
        number_pdbs_with_unp = len(
            session.query(PDB_UNP).filter(PDB_UNP.unp_id == key).all())
        pdb_ids_for_unp = ""
        for i in session.query(PDB_UNP).filter(PDB_UNP.unp_id == key).all():
            pdb_ids_for_unp += i.pdb_id + ' '
        page.add('### &nbsp;&nbsp;&nbsp;&nbsp;')
        page.a('%8s' % key, href="http://www.uniprot.org/uniprot/%s" % key)
        page.add('&nbsp;&nbsp;')
        page.a('&nbsp;&nbsp; %4d&nbsp;&nbsp;' % number_pdbs_with_unp,
               href='#',
               title=pdb_ids_for_unp)
        page.add('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
        page.add('  %s' % UNP_to_record[key].description)
        page.br()

    htmlfile.write(page.__call__())
    htmlfile.close()