示例#1
0
文件: test_tasks.py 项目: varda/varda
    def test_annotate_variants(self):
        """
        Annotate a file with observation frequencies.

        We first import a subset of the observations with coverage.
        """
        with self.fixture.data(AnnotationData, CoverageData, DataSourceData, VariationData) as data:
            coverage = Coverage.query.get(
                data.CoverageData.exome_subset_coverage.id)
            result = tasks.import_coverage.delay(coverage.id)
            assert coverage.task_done

            variation = Variation.query.get(
                data.VariationData.exome_subset_variation.id)
            result = tasks.import_variation.delay(variation.id)
            assert variation.task_done

            variation.sample.active = True

            annotation = Annotation.query.get(data.AnnotationData.exome_annotation.id)
            query = Query('GLOBAL', expressions.parse('*'))
            db.session.add(query)
            annotation.queries = [query]

            db.session.commit()

            data_source = DataSource.query.get(
                data.DataSourceData.exome_variation.id)
            annotated_file = StringIO.StringIO()

            with data_source.data() as data:
                checksum, records = utils.digest(data)

            with data_source.data() as data:
                tasks.annotate_variants(data, annotated_file,
                                        original_filetype=data_source.filetype,
                                        annotated_filetype='vcf',
                                        original_records=records,
                                        queries=[query])

            lines = annotated_file.getvalue().split('\n')
            reader = vcf.Reader(lines)

            assert_equal([(record.INFO['GLOBAL_VN'], record.INFO['GLOBAL_VF']) for record in reader],
                         [([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1, 1], [1.0, 0.0]),
                          ([0], [0.0]),
                          ([1], [0.0]),
                          ([1], [1.0]),
                          ([1], [1.0])])
示例#2
0
 def test_expression(string):
     expression = expressions.parse(string)
     switched = expression.accept(Switcher())
     assert_equal(compose(expression)
                    .replace('and', '%OLDAND%')
                    .replace('or', 'and')
                    .replace('%OLDAND%', 'or'),
                  compose(switched))
示例#3
0
文件: test_tasks.py 项目: varda/varda
    def test_write_annotation(self):
        """
        Annotate a variants file.

        We first import a subset of the observations with coverage.
        """
        with self.fixture.data(AnnotationData, CoverageData, VariationData) as data:
            coverage = Coverage.query.get(
                data.CoverageData.exome_subset_coverage.id)
            result = tasks.import_coverage.delay(coverage.id)
            assert coverage.task_done

            variation = Variation.query.get(
                data.VariationData.exome_subset_variation.id)
            result = tasks.import_variation.delay(variation.id)
            assert variation.task_done

            variation.sample.active = True

            annotation = Annotation.query.get(data.AnnotationData.exome_annotation.id)

            query = Query('GLOBAL', expressions.parse('*'))
            db.session.add(query)
            annotation.queries = [query]

            db.session.commit()

            result = tasks.write_annotation.delay(annotation.id)
            assert_equal(result.state, 'SUCCESS')
            assert annotation.task_done

            with annotation.annotated_data_source.data() as data:
                reader = vcf.Reader(data)
                assert_equal([(record.INFO['GLOBAL_VN'], record.INFO['GLOBAL_VF']) for record in reader],
                             [([1], [1.0]),
                              ([1], [1.0]),
                              ([1], [1.0]),
                              ([0], [0.0]),
                              ([0], [0.0]),
                              ([0], [0.0]),
                              ([1], [1.0]),
                              ([1], [1.0]),
                              ([1], [1.0]),
                              ([1], [1.0]),
                              ([1], [1.0]),
                              ([1, 1], [1.0, 0.0]),
                              ([0], [0.0]),
                              ([1], [0.0]),
                              ([1], [1.0]),
                              ([1], [1.0])])
示例#4
0
文件: test_tasks.py 项目: varda/varda
    def test_annotate_variants_multi_one_sample_one_sample(self):
        """
        Annotate a file with observation frequencies against multiple samples
        querying one and querying one.

        We first import two subsets of the observations with coverage.
        """
        with self.fixture.data(AnnotationData, CoverageData, DataSourceData, VariationData) as data:
            coverage = Coverage.query.get(
                data.CoverageData.exome_subset_coverage.id)
            result = tasks.import_coverage.delay(coverage.id)
            assert coverage.task_done

            variation = Variation.query.get(
                data.VariationData.exome_subset_variation.id)
            result = tasks.import_variation.delay(variation.id)
            assert variation.task_done

            sample_a = variation.sample

            coverage = Coverage.query.get(
                data.CoverageData.exome_subsubset_coverage.id)
            result = tasks.import_coverage.delay(coverage.id)
            assert coverage.task_done

            variation = Variation.query.get(
                data.VariationData.exome_subsubset_variation.id)
            result = tasks.import_variation.delay(variation.id)
            assert variation.task_done

            sample_b = variation.sample

            sample_a.active = True
            sample_b.active = True

            annotation = Annotation.query.get(data.AnnotationData.exome_annotation.id)

            query_a = Query('QA', expressions.parse('sample:%i' %
                                                    data.SampleData.exome_subset_sample.id))
            db.session.add(query_a)

            query_b = Query('QB', expressions.parse('sample:%i' %
                                                    data.SampleData.exome_subsubset_sample.id))
            db.session.add(query_b)
            annotation.queries = [query_a, query_b]

            db.session.commit()

            data_source = DataSource.query.get(
                data.DataSourceData.exome_variation.id)
            annotated_file = StringIO.StringIO()

            with data_source.data() as data:
                checksum, records = utils.digest(data)

            with data_source.data() as data:
                tasks.annotate_variants(data, annotated_file,
                                        original_filetype=data_source.filetype,
                                        annotated_filetype='vcf',
                                        original_records=records,
                                        queries=[query_a, query_b])

            lines = annotated_file.getvalue().split('\n')
            reader = vcf.Reader(lines)

            assert_equal([(record.INFO['QA_VN'], record.INFO['QA_VF']) for record in reader],
                         [([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1], [1.0]),
                          ([1, 1], [1.0, 0.0]),
                          ([0], [0.0]),
                          ([1], [0.0]),
                          ([1], [1.0]),
                          ([1], [1.0])])

            reader = vcf.Reader(lines)

            assert_equal([(record.INFO['QB_VN'], record.INFO['QB_VF']) for record in reader],
                         [([1], [1.0]),
                          ([1], [0.0]),
                          ([1], [1.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([0], [0.0]),
                          ([1], [1.0]),
                          ([0], [0.0]),
                          ([1], [1.0]),
                          ([1], [0.0]),
                          ([1], [1.0]),
                          ([1, 1], [1.0, 0.0]),
                          ([0], [0.0]),
                          ([1], [0.0]),
                          ([1], [0.0]),
                          ([1], [0.0])])
示例#5
0
 def test_expressions(string_left, string_right):
     left = expressions.parse(string_left)
     right = expressions.parse(string_right)
     expression = expressions.make_conjunction(left, right)
     assert_equal(compose(expression),
                  '(%s) and %s' % (string_left, string_right))
示例#6
0
 def test_expression(string, expected):
     expression = expressions.parse(string)
     only_short_values = expressions.test_clauses(expression, short_value)
     assert_equal(only_short_values, expected)
示例#7
0
 def test_expression(string, expected):
     expression = expressions.parse(string)
     updated = expressions.update_clause_values(expression, add_one)
     assert_equal(compose(updated), expected)
示例#8
0
 def test_expression(string, expected):
     expression = expressions.parse(string)
     filter_criterion = expressions.build_query_criterion(expression, build_clause)
     clause = filter_criterion.compile(dialect=postgresql.dialect(),
                                       compile_kwargs={'literal_binds': True})
     assert_equal(clause.string.replace('\n', ''), expected)
示例#9
0
 def test_expression(expression, expected):
     ast = expressions.parse(expression)
     is_clause = ast.accept(ClauseTester())
     assert_equal(is_clause, expected)
示例#10
0
 def test_expression(string):
     expression = expressions.parse(string)
     pretty_printed = expressions.pretty_print(expression)
     assert_equal(compose(expression), pretty_printed)
示例#11
0
 def test_expression(string):
     expression = expressions.parse(string)
     identity = expressions.deep_copy(expression)
     assert_equal(compose(expression), compose(identity))
示例#12
0
 def test_expression(string):
     with assert_raises(SyntaxError):
         expressions.parse(string)
示例#13
0
 def test_expression(string, composed):
     assert_equal(compose(expressions.parse(string)), composed)