Example #1
0
def componentList(request,organism,**kargs):
    import util.dataEncapsulater as deer
    if not (kargs):
        componentTypeList=["promoter","promoter_function_module","terminator","terminator_function_module","replication_origin","replication_origin_function_module","selection_marker","selection_marker_function_module"]
        from models import NavLink
        import collections
        resultDataDict=collections.OrderedDict()
        for componentType in componentTypeList:
            resultDataDict[componentType]=NavLink(organism,componentType).get_absolute_url()
        resultDataJson=deer.encapsulateJson(resultDataDict)
    else:
        componentType=kargs["componentType"]
        fieldNameData,fieldNameCount=selectData("information_schema.columns",["COLUMN_NAME"],{"table_name":componentType})
        if(fieldNameCount>0):
           resultTitle=[inner_1[0] for inner_1 in fieldNameData][1:]
           resultData,resultCount=selectData(componentType,resultTitle,{"organism":organism})
           resultDataDict=deer.encapsulateDict(resultTitle,resultData)
           resultDataJson=deer.encapsulateJson(resultDataDict)
        #backup
        #resultTypeDic={}
           #backup
           #resultTypeDic[resultType]={"resultTitle":resultTitle,
           #                           "resultCount":resultCount,
           #                           "resultData":resultData,
           #                           "resultDataDict":resultDataDict,}
    return HttpResponse(resultDataJson)
Example #2
0
def assemble(request,queryName="component5Design"):
    inputHtmlPath,resultHtmlPath=htmlPage(queryName)
    from forms import formDict# 引入我们创建的表单类
    if request.method != 'POST':# 当正常访问时
        if queryName=="component5Design":
            organismList=["E.coli","S.cerevisiae","C.glutamicum",]
            navL1LinkList=[]
            from models import NavLink
            for organism in organismList:
                navL1LinkList.append(NavLink(organism,""))
        #backup
        #form = formDict[queryName]()
    else:# 当提交表单时
        form=formDict[queryName](request.POST,request.FILES)
        if form.is_valid():# 如果提交的数据合法
            formData=form.cleaned_data
            
            if queryName=="designModule":
                assembleComponentList=request.POST.get("assembleComponentList")
                len_ha=request.POST.get("len_ha")
                len_ha=int(len_ha) if len_ha else 20
                
                import util.dataEncapsulater as deer
                #design primer
                from func.designPrimer import primerList
                assembleComponentListDict=deer.decapsulateJson(assembleComponentList)
                primerDataListDict=primerList(assembleComponentListDict,len_ha)
                primerDataList=deer.encapsulateJson(primerDataListDict)
                #join assembleComponent
#                 from func.joinComponent import joinSequence
#                 wholeSequence=joinSequence(assembleComponentListDict)
                request.session["assembleComponentList"]=assembleComponentList
                request.session["len_ha"]=len_ha
                request.session["primerDataList"]=primerDataList
                
            if queryName=="sendAssemble":
                #store user_submit
                #prepare db
                import util.dbOperator as dbor
                dbConn,dbCursor=dbor.prepareDb()
                #store
                sqlString="insert into user_submit (assembleComponentList,len_ha,submit_time) values (\'"+request.session["assembleComponentList"]+"\',"+str(request.session["len_ha"])+",now())"
                #backup 存的是单引号且字典内部顺序非原始 sqlString="insert into test (assembleComponentList,submit_time) values (\""+str(assembleComponentListDict)+"\",now())"
                isContinue=dbor.sqlDo(sqlString,dbCursor,dbConn)
                if(not isContinue):
                    logger.warning(sqlString)
                #close
                dbConn.close()
                #email assemble list
                wetlab_email='*****@*****.**'
                subject="Assemble component"
                content="Assemble Component\n"
                content+="Assemble Component List: \n"+request.session["assembleComponentList"]+"\n"
                content+="Primer Data List: \n"+request.session["primerDataList"]+"\n"
                content+="Length of homologous arm: \n"+str(request.session["len_ha"])+"\n"
                msg=EmailMultiAlternatives(subject,content,from_email,[wetlab_email,])
                msg.send()
                
                httpString="<div><h3>Design biocomponent</h3></div>\
                            <div><p>Task has been sent to laboratory</p>\
                                <p>Please contact to <a href\""+wetlab_email+"\">"+wetlab_email+"</a> for wet-lab technical support and "+"<a href\"[email protected]\">Yi Yang</a>"+" for computing-lab technical support</p></div>"
                
                
                #backup
                #symbolList=symbol.split(",")
            #calculate success, direct to the result page
            return render(request,resultHtmlPath,locals())
    #form = formDict[queryName]()
    return render(request,inputHtmlPath,locals())