Пример #1
0
def browse(request):
    version, stats = get_version_stats()
    username = get_username(request)

    queryset = Vouchers.objects.order_by("-modified")[:10]

    vouchers_with_images = []
    # Lookups that span relationships
    #  https://docs.djangoproject.com/en/1.8/topics/db/queries/#lookups-that-span-relationships
    for i in Vouchers.objects.filter(flickrimages__voucher_id__isnull=False):
        vouchers_with_images.append(i.code)

    for i in Vouchers.objects.filter(localimages__voucher_id__isnull=False):
        vouchers_with_images.append(i.code)

    return render(
        request,
        "public_interface/browse.html",
        {
            "username": username,
            "results": queryset,
            "vouchers_with_images": set(vouchers_with_images),
            "version": version,
            "stats": stats,
        },
    )
Пример #2
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)

    voucher_count = get_voucher_count()

    queryset = Genes.objects.all().values()
    result = []
    for i in queryset:
        gene_code = i['gene_code']
        try:
            i['voucher_count'] = voucher_count[gene_code]
        except KeyError:
            continue
        result.append(i)
    result = sorted(result, key=lambda k: k['gene_code'].lower())

    return render(request, 'view_genes/index.html',
                  {
                      'username': username,
                      'result': result,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #3
0
def show_sequence(request, voucher_code, gene_code):
    version, stats = get_version_stats()
    username = get_username(request)

    try:
        queryset = Vouchers.objects.get(code__iexact=voucher_code)
    except Vouchers.DoesNotExist:
        raise Http404

    seqs_queryset = Sequences.objects.get(code=voucher_code, gene_code=gene_code)
    images_queryset = FlickrImages.objects.filter(voucher=voucher_code)
    primers_queryset = Primers.objects.filter(for_sequence=seqs_queryset)

    return render(
        request,
        "public_interface/show_sequence.html",
        {
            "username": username,
            "voucher": queryset,
            "sequence": seqs_queryset,
            "images": images_queryset,
            "primers": primers_queryset,
            "version": version,
            "stats": stats,
        },
    )
Пример #4
0
def gene(request, gene_code):
    version, stats = get_version_stats()
    username = get_username(request)

    queryset = Genes.objects.filter(gene_code=gene_code)
    if not queryset:
        item = ''
    else:
        item = queryset[0]

        if ';' in item.intron:
            introns = item.intron.split(';')
            j = 1
            out = ''
            for i in introns:
                out += '<b>Intron ' + str(j) + ':</b> ' + i + ' > '
                j += 1
            item.intron = out.rstrip(' > ')

    return render(request, 'view_genes/gene.html',
                  {
                      'username': username,
                      'item': item,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #5
0
def results(request):
    version, stats = get_version_stats()
    username = get_username(request)

    if request.method == "POST":
        form = BLASTNewForm(request.POST)

        if form.is_valid():
            cleaned_data = form.cleaned_data

            blast = BLASTNew("new", cleaned_data["name"], cleaned_data["sequence"], cleaned_data["gene_codes"])
            blast.save_seqs_to_file()

            if not blast.is_blast_db_up_to_date():
                blast.create_blast_db()

            blast.save_query_to_file()
            blast.do_blast()
            result = blast.parse_blast_output()
            if not result:
                result = None
            blast.delete_query_output_files()
            return render(
                request,
                "blast_new/results.html",
                {"username": username, "result": result, "version": version, "stats": stats},
            )
        else:
            return render(
                request,
                "blast_new/index.html",
                {"username": username, "form": form, "version": version, "stats": stats},
            )

    return HttpResponseRedirect("/blast_new/")
Пример #6
0
def show_voucher(request, voucher_code):
    version, stats = get_version_stats()
    username = get_username(request)

    try:
        voucher_queryset = Vouchers.objects.get(code__iexact=voucher_code)
    except Vouchers.DoesNotExist:
        raise Http404

    flickr_images_queryset = FlickrImages.objects.filter(voucher=voucher_code)
    local_images_queryset = LocalImages.objects.filter(voucher=voucher_code)
    images_queryset = list(chain(flickr_images_queryset, local_images_queryset))

    seqs_queryset = Sequences.objects.filter(code=voucher_code).values('code', 'gene_code',
                                                                       'number_ambiguous_bp',
                                                                       'accession', 'lab_person')

    return render(request, 'public_interface/show_voucher.html',
                  {
                      'username': username,
                      'voucher': voucher_queryset,
                      'images': images_queryset,
                      'sequences': seqs_queryset,
                      'google_maps_api_key': settings.GOOGLE_MAPS_API_KEY,
                      'version': version,
                      'stats': stats,
                  })
Пример #7
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)

    genes = Genes.objects.all().order_by('gene_code')
    vouchers = OverviewTable.objects.all()

    paginator = Paginator(vouchers, 100)

    page = request.GET.get('page')
    try:
        vouchers_for_page = paginator.page(page)
    except PageNotAnInteger:
        vouchers_for_page = paginator.page(1)
    except EmptyPage:
        vouchers_for_page = paginator.page(paginator.num_pages)

    return render(request,
                  'overview_table/index.html',
                  {
                      'username': username,
                      'version': version,
                      'stats': stats,
                      'data': vouchers_for_page,
                      'genes': genes,
                      'page_range': paginator.page_range,
                  },
                  )
Пример #8
0
def show_voucher(request, voucher_code):
    version, stats = get_version_stats()
    username = get_username(request)

    try:
        voucher_queryset = Vouchers.objects.get(code__iexact=voucher_code)
    except Vouchers.DoesNotExist:
        raise Http404

    flickr_images_queryset = FlickrImages.objects.filter(voucher=voucher_code)
    local_images_queryset = LocalImages.objects.filter(voucher=voucher_code)
    images_queryset = list(chain(flickr_images_queryset, local_images_queryset))

    seqs_queryset = Sequences.objects.filter(code=voucher_code).values(
        "code", "gene_code", "number_ambiguous_bp", "accession", "lab_person", "total_number_bp"
    )
    sorted_seqs_queryset = sorted(seqs_queryset, key=lambda x: x["gene_code"].lower())

    return render(
        request,
        "public_interface/show_voucher.html",
        {
            "username": username,
            "voucher": voucher_queryset,
            "images": images_queryset,
            "sequences": sorted_seqs_queryset,
            "google_maps_api_key": settings.GOOGLE_MAPS_API_KEY,
            "version": version,
            "stats": stats,
        },
    )
Пример #9
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)

    form = BLASTNewForm()
    return render(
        request, "blast_new/index.html", {"username": username, "form": form, "version": version, "stats": stats}
    )
Пример #10
0
def index(request):
    version, stats = get_version_stats()
    return render(request, 'gbif/index.html',
                  {
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #11
0
 def extra_context(self):
     version, stats = get_version_stats()
     return {
         'simple_query': self.simple_query,
         'url_encoded_query': self.url_encoded_query,
         'result_count': len(self.searchqueryset),
         'version': version,
         'stats': stats,
     }
Пример #12
0
def index(request):
    version, stats = get_version_stats()

    return render(request,
                  'public_interface/index.html',
                  {
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #13
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)
    return render(request, 'gbif/index.html',
                  {
                      'username': username,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #14
0
def results(request):
    version, stats = get_version_stats()

    if request.method == 'POST':
        form = GenBankFastaForm(request.POST)

        if form.is_valid():
            cleaned_data = form.cleaned_data
            cleaned_data['file_format'] = 'GenbankFASTA'
            cleaned_data['number_genes'] = ''
            cleaned_data['aminoacids'] = True
            cleaned_data['positions'] = 'ALL'
            cleaned_data['partition_by_positions'] = 'ONE'
            cleaned_data['taxon_names'] = ['CODE', 'GENUS', 'SPECIES']
            cleaned_data['outgroup'] = ''

            dataset_creator = CreateDataset(cleaned_data)
            dataset, aa_dataset = dataset_creator.dataset_str
            dataset = dataset[0:1500] + '\n...\n\n\n' + '#######\nComplete dataset file available for download.\n#######'
            aa_dataset = aa_dataset[0:1500] + '\n...\n\n\n' + '#######\nComplete dataset file available for download.\n#######'
            errors = dataset_creator.errors
            warnings = dataset_creator.warnings

            dataset_file_abs = dataset_creator.dataset_file
            aa_dataset_file_abs = dataset_creator.aa_dataset_file
            if dataset_file_abs is not None:
                dataset_file = re.search('([a-zA-Z]+_[a-z0-9]+\.txt)', dataset_file_abs).groups()[0]
                aa_dataset_file = re.search('([a-zA-Z]+_aa_[a-z0-9]+\.txt)', aa_dataset_file_abs).groups()[0]
            else:
                dataset_file = False
                aa_dataset_file = False

            return render(request, 'genbank_fasta/results.html',
                          {
                              'items_with_accession': '',
                              'dataset': dataset,
                              'fasta_file': dataset_file,
                              'protein': aa_dataset,
                              'errors': errors,
                              'protein_file': aa_dataset_file,
                              'warnings': warnings,
                              'version': version,
                              'stats': stats,
                          },
                          )
        else:
            return render(request, 'genbank_fasta/index.html',
                          {
                              'form': form,
                              'version': version,
                              'stats': stats,
                          },
                          )

    return HttpResponseRedirect('/genbank_fasta/')
Пример #15
0
def index(request):
    version, stats = get_version_stats()

    form = BLASTNewForm()
    return render(request, 'blast_new/index.html',
                  {
                      'form': form,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #16
0
def index(request):
    version, stats = get_version_stats()
    form = GeneTableForm()

    return render(request, 'gene_table/index.html',
                  {
                      'version': version,
                      'stats': stats,
                      'form': form,
                  },
                  )
Пример #17
0
def index(request):
    version, stats = get_version_stats()

    form = GenBankFastaForm()
    return render(request,
                  'genbank_fasta/index.html',
                  {
                      'form': form,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #18
0
 def extra_context(self):
     version, stats = get_version_stats()
     username = get_username(self.request)
     return {
         'username': username,
         'voucher_code_list': self.voucher_code_list,
         'simple_query': self.simple_query,
         'url_encoded_query': self.url_encoded_query,
         'result_count': len(self.searchqueryset),
         'version': version,
         'stats': stats,
     }
Пример #19
0
def search_advanced(request):
    """Uses the haystack index `advanced_search` to find values based on a
    combination of queries for one or more fields.
    Works in a similar way to **genus:Mopho AND species:helenor**

    :param request: HTTP request from the url dispatcher.
    :return: response to html template.
    """
    version, stats = get_version_stats()
    username = get_username(request)

    if request.method == 'GET' and bool(request.GET) is not False:
        form = AdvancedSearchForm(request.GET)

        if form.is_valid():
            sqs = form.search()
            search_view = VoSeqSearchView(
                url_encoded_query=request.GET.urlencode(),
                template='public_interface/search_results.html',
                searchqueryset=sqs,
                form_class=AdvancedSearchForm
            )

            if sqs is not None:
                search_view.__call__(request)
                search_view.query = sqs.query
                return search_view.create_response()
            else:
                return render(request, 'public_interface/search_results.html',
                              {
                                  'username': username,
                                  'form': form,
                                  'version': version,
                                  'stats': stats,
                              })
        else:
            return render(request, 'public_interface/search.html',
                          {
                              'username': username,
                              'form': form,
                              'version': version,
                              'stats': stats,
                          })
    else:
        form = AdvancedSearchForm()
        return render(request, 'public_interface/search.html',
                      {
                          'username': username,
                          'form': form,
                          'version': version,
                          'stats': stats,
                      })
Пример #20
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)
    form = VoucherTableForm()

    return render(request, 'voucher_table/index.html',
                  {
                      'username': username,
                      'version': version,
                      'stats': stats,
                      'form': form,
                  },
                  )
Пример #21
0
def index(request, voucher_code, gene_code):
    version, stats = get_version_stats()

    blast = BLASTNcbi(voucher_code, gene_code)
    blast.save_query_to_file()

    blast.do_blast()
    result = blast.parse_blast_output()
    blast.delete_query_output_files()
    return render(request, 'blast_local/index.html',
                  {
                      'result': result,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #22
0
def results(request):
    version, stats = get_version_stats()
    if request.method == 'POST':
        form = GeneTableForm(request.POST)
        if form.is_valid():
            table = GeneTable(form.cleaned_data)
            response = create_excel_file(table.stats)
            return response

    return render(request, 'gene_table/index.html',
                  {
                      'version': version,
                      'stats': stats,
                      'form': GeneTableForm(),
                  },
                  )
Пример #23
0
def results(request):
    version, stats = get_version_stats()
    username = get_username(request)

    if request.method == 'POST':
        form = CreateDatasetForm(request.POST)

        if form.is_valid():
            dataset_format = form.cleaned_data['file_format']
            dataset_creator = CreateDataset(form.cleaned_data)
            dataset = dataset_creator.dataset_str[0:1500] + '\n...\n\n\n' + '#######\nComplete dataset file available for download.\n#######'
            errors = dataset_creator.errors
            warnings = set(dataset_creator.warnings)

            dataset_file_abs = dataset_creator.dataset_file
            if dataset_file_abs is not None:
                dataset_file = re.search('([A-Z]+_[a-z0-9]+\.txt)', dataset_file_abs).groups()[0]
            else:
                dataset_file = False

            return render(request, 'create_dataset/results.html',
                          {
                              'username': username,
                              'dataset_file': dataset_file,
                              'charset_block': dataset_creator.charset_block,
                              'dataset': dataset,
                              'dataset_format': dataset_format,
                              'errors': errors,
                              'warnings': warnings,
                              'version': version,
                              'stats': stats,
                          },
                          )
        else:
            print("invalid form")
            return render(request, 'create_dataset/index.html',
                          {
                              'username': username,
                              'form': form,
                              'version': version,
                              'stats': stats,
                          },
                          )
    else:
        return HttpResponseRedirect('/create_dataset/')
Пример #24
0
def results(request):
    version, stats = get_version_stats()
    username = get_username(request)

    if request.method == 'POST':
        form = BLASTNewForm(request.POST)

        if form.is_valid():
            cleaned_data = form.cleaned_data

            blast = BLASTNew(blast_type='new', name=cleaned_data['name'],
                             sequence=cleaned_data['sequence'],
                             gene_codes=cleaned_data['gene_codes'])
            blast.save_seqs_to_file()

            if not blast.is_blast_db_up_to_date():
                blast.create_blast_db()

            blast.save_query_to_file()
            blast.do_blast()
            result = blast.parse_blast_output()
            if not result:
                result = None
            blast.delete_query_output_files()
            return render(request, 'blast_new/results.html',
                          {
                              'username': username,
                              'result': result,
                              'version': version,
                              'stats': stats,
                          },
                          )
        else:
            return render(request, 'blast_new/index.html',
                          {
                              'username': username,
                              'form': form,
                              'version': version,
                              'stats': stats,
                          },
                          )

    return HttpResponseRedirect('/blast_new/')
Пример #25
0
def browse(request):
    version, stats = get_version_stats()

    queryset = Vouchers.objects.order_by('-timestamp')[:10]

    # TODO improve this ugly hack. Use select_related or prefetch_related
    vouchers_with_images = []
    for i in queryset:
        q = FlickrImages.objects.filter(voucher=i.code)
        if q.count() > 0:
            vouchers_with_images.append(i.code)

    return render(request, 'public_interface/browse.html',
                  {
                      'results': queryset,
                      'vouchers_with_images': vouchers_with_images,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #26
0
def index(request, voucher_code, gene_code):
    version, stats = get_version_stats()

    blast = BLASTFull('full', voucher_code, gene_code)
    blast.save_seqs_to_file()

    if blast.is_blast_db_up_to_date() is False:
        blast.create_blast_db()

    blast.save_query_to_file()
    blast.do_blast()
    result = blast.parse_blast_output()
    blast.delete_query_output_files()
    return render(request, 'blast_local/index.html',
                  {
                      'result': result,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #27
0
def show_sequence(request, voucher_code, gene_code):
    version, stats = get_version_stats()

    try:
        queryset = Vouchers.objects.get(code__iexact=voucher_code)
    except Vouchers.DoesNotExist:
        raise Http404

    seqs_queryset = Sequences.objects.get(code=voucher_code, gene_code=gene_code)
    images_queryset = FlickrImages.objects.filter(voucher=voucher_code)
    primers_queryset = Primers.objects.filter(for_sequence=seqs_queryset)

    return render(request, 'public_interface/show_sequence.html',
                  {
                      'voucher': queryset,
                      'sequence': seqs_queryset,
                      'images': images_queryset,
                      'primers': primers_queryset,
                      'version': version,
                      'stats': stats,
                  },)
Пример #28
0
def index(request, voucher_code, gene_code):
    version, stats = get_version_stats()
    username = get_username(request)

    blast = BLAST('local', voucher_code, gene_code)
    blast.save_seqs_to_file()

    if not blast.is_blast_db_up_to_date():
        blast.create_blast_db()

    blast.save_query_to_file()
    blast.do_blast()
    result = blast.parse_blast_output()
    blast.delete_query_output_files()
    return render(request, 'blast_local/index.html',
                  {
                      'username': username,
                      'result': result,
                      'version': version,
                      'stats': stats,
                  },
                  )
Пример #29
0
def index(request):
    version, stats = get_version_stats()
    username = get_username(request)

    return render(request, "public_interface/index.html", {"username": username, "version": version, "stats": stats})
Пример #30
0
def results(request):
    version, stats = get_version_stats()
    username = get_username(request)

    if request.method == 'POST':
        form = GenBankFastaForm(request.POST)

        if form.is_valid():
            cleaned_data = form.cleaned_data
            cleaned_data['file_format'] = 'GenBankFASTA'
            cleaned_data['number_genes'] = ''
            cleaned_data['translations'] = False
            cleaned_data['aminoacids'] = False
            cleaned_data['positions'] = 'ALL'
            cleaned_data['partition_by_positions'] = 'by gene'
            cleaned_data['taxon_names'] = ['CODE', 'GENUS', 'SPECIES']
            cleaned_data['outgroup'] = ''

            dataset_creator = CreateDataset(cleaned_data)
            dataset = dataset_creator.dataset_str
            dataset_short = dataset[0:1500] + '\n...\n\n\n' + '#######\nComplete dataset file available for download.\n#######'
            errors = dataset_creator.errors
            warnings = dataset_creator.warnings
            dataset_file_abs = dataset_creator.dataset_file
            if dataset_file_abs is not None:
                dataset_file = os.path.basename(dataset_file_abs)
            else:
                dataset_file = False

            cleaned_data['aminoacids'] = True
            dataset_creator = CreateDataset(cleaned_data)
            aa_dataset = dataset_creator.dataset_str
            aa_dataset_file_abs = dataset_creator.dataset_file
            if aa_dataset_file_abs is not None:
                aa_dataset_file = os.path.basename(aa_dataset_file_abs)
            else:
                aa_dataset_file = False

            return render(request, 'genbank_fasta/results.html',
                          {
                              'username': username,
                              'items_with_accession': '',
                              'dataset': dataset_short,
                              'fasta_file': dataset_file,
                              'protein': aa_dataset,
                              'errors': errors,
                              'protein_file': aa_dataset_file,
                              'warnings': warnings,
                              'version': version,
                              'stats': stats,
                          },
                          )
        else:
            return render(request, 'genbank_fasta/index.html',
                          {
                              'username': username,
                              'form': form,
                              'version': version,
                              'stats': stats,
                          },
                          )

    return HttpResponseRedirect('/genbank_fasta/')