<commit_before>import re
import csv
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
from django.conf import settings
from .models import SNP


def index(request):
    rs_match = re.findall('\A(rs)?(\d+)\Z', request.GET.get('rs', ''))
    rs = int(rs_match[0][1]) if rs_match else ''
    records = {'rs': rs}

    if rs:
        chrom, pos = SNP.get_pos_by_rs(rs)
        # TODO: chrom, pos on b37, b38

        # TODO: gene

        # TODO: reference sequence

        # TODO: snp fasta sequence

        rs_current = SNP.get_current_rs(rs)

        allele_freq_source = '1000 Genomes Phase1, CHB+JPT+CHS'  # TODO
        allele_freq_source_id = 1  # TODO
        af = SNP.get_allele_freq(allele_freq_source_id, rs)
        allele_freqs = {allele_freq_source: dict(zip(af['allele'], af['freq']))}<commit_msg>wip: add validation on GET params<commit_after>import re
import csv
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
from django.conf import settings
from .models import SNP


def index(request):
    rs_regexp = re.compile('\A(rs)?(\d{1,9})\Z')  # max rs# is 483352819 (b141)
    rs_match = rs_regexp.findall(request.GET.get('rs', ''))
    rs = int(rs_match[0][1]) if rs_match else ''
    records = {'rs': rs}

    # TODO: handle not found records
    if rs:
        chrom, pos = SNP.get_pos_by_rs(rs)
        # TODO: chrom, pos on b37, b38

        # TODO: gene

        # TODO: reference sequence

        # TODO: snp fasta sequence

        rs_current = SNP.get_current_rs(rs)

        allele_freq_source = '1000 Genomes Phase1, CHB+JPT+CHS'  # TODO
        allele_freq_source_id = 1  # TODO
        af = SNP.get_allele_freq(allele_freq_source_id, rs)
        allele_freqs = {allele_freq_source: dict(zip(af['allele'], af['freq']))}
{'fraction_non_alphanumeric': 0.11868131868131868, 'fraction_numerical': 0.020879120879120878, 'mean_word_length': 3.1013513513513513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6868145', 'n_tokens_mistral': 664, 'n_tokens_neox': 618, 'n_words': 159}