Skip to content

Commit

Permalink
Merge pull request chop-dbhi#349 from cbmi/variant-sets
Browse files Browse the repository at this point in the history
Add support for result/variant sets
  • Loading branch information
bruth committed Aug 15, 2014
2 parents 638302d + 68da5bd commit 94f9e1f
Show file tree
Hide file tree
Showing 166 changed files with 5,059 additions and 2,992 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ install:
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install --use-mirrors cython && pip install --use-mirrors pysam argparse counter ordereddict importlib; fi"
- pip install flake8
- pip install httpretty
- npm install jshint

services:
- memcached
- redis-server

before_script:
- flake8
- jshint varify/static/js/src/
- psql -c 'create database varifydb;' -U postgres

script:
Expand Down
3 changes: 2 additions & 1 deletion test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'assessments',
'south_tests',
'geneset_form',
'resources'
'resources',
'samples'
]

management.call_command('test', *apps)
Empty file added tests/cases/samples/__init__.py
Empty file.
Empty file added tests/cases/samples/models.py
Empty file.
67 changes: 67 additions & 0 deletions tests/cases/samples/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import json
import os
from openpyxl import Workbook, cell
from restlib2.http import codes
from vdw.samples.models import Project
from guardian.shortcuts import assign
from ..base import AuthenticatedBaseTestCase


class VariantUploadResourceTestCase(AuthenticatedBaseTestCase):
fixtures = ['initial_variants.json']

def setUp(self):
super(VariantUploadResourceTestCase, self).setUp()

def test_post(self):
book = Workbook()
sheet1 = book.get_active_sheet()
sheet1.title = 'Variants List'
fields = ['Chromosome', 'Start', 'Reference', 'Allele 1', 'Allele 2',
'dbSNP']

# Create variants to cover all edge cases, including the case
# where there is a variation at the same genomic position.
# Also consider the case where the dbSNP id is incorrect.
variants = [['1', '20000', '.', 'AC', 'AC', ''],
['1', '20000', 'A', 'A', '.', ''],
['3', '20002', 'GAT', '.', '.', 'rs9160301'],
['1', '20003', '.', '.', 'TTTCTT', ''],
['3', '20004', 'A', 'C', 'C', 'rs916000'],
['1', '20007', 'GTCATTGGAACAGTC', '.',
'GTCATTGGAACAGTC', '']]

# Write our fields in first.
for i in range(0, 6):
sheet1.cell(row=0, column=i).set_value_explicit(
value=fields[i], data_type=cell.Cell.TYPE_STRING)

# Write the variants to the excel sheet.
row = 1
for v in variants:
for col in range(0, 6):
sheet1.cell(row=row, column=col).set_value_explicit(
value=v[col], data_type=cell.Cell.TYPE_STRING)
row += 1

book.save('variantList.xlsx')

with open('variantList.xlsx') as fp:
# Assign permissions for test user to access the project.
p = Project.objects.get(pk=1)
assign('samples.view_project', self.user, p)

response = self.client.post('/api/samples/9/variants/sets/',
{'name': 'variants',
'source': fp})
response_obj = json.loads(response.content)

# An array of matching variants are returned. Make sure
# that exactly 5 were found and 1 was added to the
# list of unmatched variants.
self.assertEqual(response.status_code, codes.created)
self.assertEqual(response_obj['num_total_records'], 6)
self.assertEqual(response_obj['count'], 5)
self.assertEqual(len(response_obj['invalid_records']), 1)

os.remove('variantList.xlsx')
Loading

0 comments on commit 94f9e1f

Please sign in to comment.