website.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:MetaSRA-pipeline 作者: deweylab 项目源码 文件源码
def POST(self): 

        form = search_form()
        form.validates()

        error_message = ""

        usr_in = form['term_id'].value

        metasra_db = web.database(dbn='sqlite', db='static/metasra.sqlite')

        #term_ancestors_db = web.database(dbn='sqlite', db='static/term_ancestors.sqlite')        

        term_ids = get_searched_term_ids(usr_in)
        if len(term_ids) == 0:
            error_message = "The query did not match the name nor synonym of any ontology terms. Please use the search-suggestion feature to guide your search."


        request_results = []
        for term_id in term_ids:    
            in_sample_type = form["sample_type"].value
            if in_sample_type == "all":
                results = query_metasra.query_metasra_for_term(metasra_db, term_id)
            else:
                results = query_metasra.query_metasra_for_term(metasra_db, term_id, sample_type=in_sample_type)


            print "Preparing results..."
            for r in results:
                r_sample_acc = r["sample_accession"]
                r_study_acc = r["study_accession"]
                if r["study_title"]:
                    r_study_title = r["study_title"]
                else:
                    r_study_title = ""
                r_attrs_elem = r["sample_attributes_html"]
                r_terms_elem = r["sample_terms_html"]
                r_sample_name = r["sample_name"]
                r_sample_type = r["sample_type"]
                r_confidence = r["confidence"]

                request_results.append([
                    '<a class="sample_accession_link" target="_blank" href="https://www.ncbi.nlm.nih.gov/biosample/%s">%s</a>' % (r_sample_acc,r_sample_acc),
                    '<a class="sample_accession_link" target="_blank" href="https://www.ncbi.nlm.nih.gov/biosample/%s">%s</a>' % (r_sample_acc,r_sample_name),
                    '<a class="study_link" target="_blank" href="https://trace.ncbi.nlm.nih.gov/Traces/sra/?study=%s">%s</a>' % (r_study_acc, r_study_title),
                    '<div class="sample_type_table_entry">%s (%0.2f)</div>' % (r_sample_type, r_confidence),
                    r_terms_elem,
                    r_attrs_elem
                ])
            print "Finished preparing results."

        print "Returning %d results" % len(request_results)

        return json.dumps({"error_message":error_message, "search_results":request_results})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号