当前位置: 首页>>代码示例>>Python>>正文


Python Profile.tissue方法代码示例

本文整理汇总了Python中models.Profile.tissue方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.tissue方法的具体用法?Python Profile.tissue怎么用?Python Profile.tissue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Profile的用法示例。


在下文中一共展示了Profile.tissue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_profile

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import tissue [as 别名]
def add_profile(request):
    form = ProfileForm(request.POST or None, request.FILES or None)

    if request.POST:
        if not "file" in request.POST:
            file = request.FILES['file']
            data = file.read().split('\n')
        elif request.POST["data_text"]:
            data = request.POST["data_text"].replace('\r', '').split('\n')
        else:
            redirect('/expressions/profile/add/')

        # Create profiles:
        profiles = []
        replicates = [] # Container for bulk creation.

        # Header:
        columns = data[0].split('\t')
        for index, dataset in enumerate(columns[1:]):
            tissue, diet, name = columns[index+1].split('_')
            #print tissue, diet, name
            profile = Profile(
                name=name,
                species=Species.objects.get(pk=request.POST['species']),
                diet=Regimen.objects.get(shortcut__exact=diet)
            )
            profile.save()
            tissues = Tissue.objects.filter(notes__icontains=tissue)
            profile.tissue = tissues
            profiles.append(profile)
            #print index, tissue, diet, name

        # Actually Data Parsing:
        limit = 10
        counter = 0
        overall_count = 0
        lines = data[1:]
        line_number = len(lines)
        c = Counter(lines)
        print(line_number)
        for line in lines:
            #print(line)
            counter += 1
            c.count()
            #if counter % 2: print counter
#            if (100. * overall_count / line_number) < 40:
#                overall_count += counter
#                continue
            columns = line.split('\t')
            if not line: continue
            #print("Iterate over columns and save the replicates:")
            probe_id = columns[0]
            for index, column in enumerate(columns[1:]):
                #print index, column
                intensity = columns[index+1]
                replicate = Replicate(probe_id=probe_id, intensity=intensity,
                                      profile=profiles[index])
                #replicate.save()
                replicates.append(replicate)


            if counter >= limit:
                current = 100. * overall_count / line_number
                #print(current)
                #if current > 47 and not current > 48:
                    #print " ".join(replicate.intensity for replicate in replicates)
                    #
                #else:
                try: Replicate.objects.bulk_create(replicates)
                except Exception as e:
                    print(e)
                    messages.add_message(request, messages.ERROR, ugettext("1. Try: "+str(e)))
                    try:
                        [replicate.save() for replicate in replicates]
                    except Exception as es:
                        print(e)
                        messages.add_message(request, messages.ERROR, ugettext("2. Try: "+str(e)))
                replicates = []
                overall_count += counter
                counter = 0
                #print(current)
        if replicates:
            #Replicate.objects.bulk_create(replicates)
            replicates = []
            overall_count += counter

        # Adding replicates:
#        for profile in profiles:
#            replicates = Replicate.objects.filter(profile_id=profile.pk)
#            for replicate in replicates:
#                profile.replicates.add(replicate)
            #profiles[index].replicates.add(replicate)

        msg = "Successfully integrated profiles."
        print(msg)
        messages.add_message(request, messages.SUCCESS, ugettext(msg))

        # Cleaning up:
        request.POST['file'] = ''
        data = ''
#.........这里部分代码省略.........
开发者ID:denigma,项目名称:denigma,代码行数:103,代码来源:views.py


注:本文中的models.Profile.tissue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。