Exemplo n.º 1
0
from django.db import models, transaction
from django.db.models import Max
from django.utils import timezone

from celery.decorators import task

from apps.authentication.models import User
from apps.genome.models import Genome, Genotype
from apps.gwascatalog.models import GwasCatalogPhenotype, GwasCatalogSnp
from apps.snp.models import get_freqs
from lib.riskreport.commons import *
from lib.utils.population import POPULATION_MAP
from lib.utils.pg import list2pg_array
from utils import clogging
log = clogging.getColorLogger(__name__)


class RiskReport(models.Model):
    """
     ------------
    |            |
    |   Genome   |
    |            |
     ------------
          1
          |
          n
     ------------       ---------------------       ---------------
    |            |     |                     |     |               |
    | RiskReport |1 - n| PhenotypeRiskReport |1 - n| SnpRiskReport |
Exemplo n.º 2
0
from django.contrib.auth.decorators import login_required
from django.shortcuts import render

from apps.authentication.models import User
from apps.genome.models import Genome
from apps.gwascatalog.models import GwasCatalogSnp
from utils.clogging import getColorLogger
log = getColorLogger(__name__)


@login_required
def index(request):
    while True:
        # Your Genome Files
        user = User.objects.filter(id=request.user.id)
        owner_genomes = Genome.objects.filter(owner=user)
        reader_genomes = Genome.objects.filter(readers__in=user)
        my_genomes = list(owner_genomes) + list(reader_genomes)

        # Recently Added Studies
        recent_studies = GwasCatalogSnp.objects.distinct('pubmed_id', 'date_published').order_by('-date_published')[0:3]

        break

    return render(request, 'dashboard.html',
                  dict(my_genomes=my_genomes,
                       recent_studies=recent_studies))
Exemplo n.º 3
0
Arquivo: r.py Projeto: knmkr/pergenie
import sys, os
import subprocess
from pymongo import MongoClient
from django.conf import settings
from lib.api.genomes import Genomes
genomes = Genomes()
from utils import clogging
log = clogging.getColorLogger(__name__)

def projection(scale, info):
    _1000genomes = os.path.join(settings.BASE_DIR, 'lib', 'r', '1000genomes.{0}.subsnps.csv'.format(scale))

    with open(_1000genomes, 'r') as f:
        pca_snps = f.next().rstrip().split(',')[:-1]

    with MongoClient(host=settings.MONGO_URI) as connection:
        db = connection['pergenie']
        variants = genomes.get_variants(info['user_id'], info['name'])

        user_snps_list = variants.find({'rs': {'$in': [int(s[2:-2]) for s in pca_snps]}})
        user_snps = dict((data['rs'], data) for data in user_snps_list)
        user_bits = list()
        for snp in pca_snps:
            rec = user_snps.get(int(snp[2:-2]))  # "rs100GT" => 100
            if rec:
                # count alt alleles
                ref = snp[-2:-1]
                alt = snp[-1]
                ref_count = rec['genotype'].count(ref)
                alt_count = rec['genotype'].count(alt)
                if ref_count + alt_count != 2:
Exemplo n.º 4
0
# -*- coding: utf-8 -*-

import sys
import os
import time
import datetime

from django.conf import settings
from django.utils.translation import ugettext as _
from django.utils.translation import activate as translation_activate

from utils.clogging import getColorLogger
log = getColorLogger(__name__)


# class SimpleTest(LoginUserTestCase):
#     def test_login_required(self):
#         response = self.client.get('/riskreport/')
#         self.assertEqual(response.status_code, 302)

#         # TODO: check all studies?
#         response = self.client.get('/riskreport/もやもや病%28ウィリス動脈輪閉塞症%29/A%20genome-wide%20association%20study%20identifies%20RNF213%20as%20the%20first%20Moyamoya%20disease%20gene./')
#         self.assertEqual(response.status_code, 302)

#         response = self.client.get('/riskreport/もやもや病%28ウィリス動脈輪閉塞症%29/A%20genome-wide%20association%20study%20identifies%20RNF213%20as%20the%20first%20Moyamoya%20disease%20gene./?file_name=' + self.file_cleaned_name)
#         self.assertEqual(response.status_code, 302)

    # def test_index_success(self):
    #     self.client.login(username=self.test_user_id, password=self.test_user_password)
    #     self._import_data()