Ejemplo n.º 1
0
    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])])
Ejemplo n.º 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))
Ejemplo n.º 3
0
    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])])
Ejemplo n.º 4
0
    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])])
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 7
0
 def test_expression(string, expected):
     expression = expressions.parse(string)
     updated = expressions.update_clause_values(expression, add_one)
     assert_equal(compose(updated), expected)
Ejemplo n.º 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)
Ejemplo n.º 9
0
 def test_expression(expression, expected):
     ast = expressions.parse(expression)
     is_clause = ast.accept(ClauseTester())
     assert_equal(is_clause, expected)
Ejemplo n.º 10
0
 def test_expression(string):
     expression = expressions.parse(string)
     pretty_printed = expressions.pretty_print(expression)
     assert_equal(compose(expression), pretty_printed)
Ejemplo n.º 11
0
 def test_expression(string):
     expression = expressions.parse(string)
     identity = expressions.deep_copy(expression)
     assert_equal(compose(expression), compose(identity))
Ejemplo n.º 12
0
 def test_expression(string):
     with assert_raises(SyntaxError):
         expressions.parse(string)
Ejemplo n.º 13
0
 def test_expression(string, composed):
     assert_equal(compose(expressions.parse(string)), composed)