Exemple #1
0
    def setUp(self):
        fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, False)
        ref_fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, True)

        self.analysis = GenomeAnalysis(10, .9)
        self.coroutine_fn = lambda *arg: (self.CoroutineMock(),
                                          self.CoroutineMock())
        self.dups_contig = fasta
        self.reference_contig = ref_fasta.get_contig(
            'ContigWithFilePositionOffset')
        self.sample_groups = ((fasta, fasta), (fasta, ), (fasta, fasta))
Exemple #2
0
class SamplePositionsTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        vcf = StringIO(initial_value='')
        fasta = StringIO(initial_value='')
        self.analysis = GenomeAnalysis(10, 0.9)

    def tearDown(self):
        pass

    @unittest.skip('Not Implemented')
    def test_foo(self):
        self.analysis.sample_positions('test_contig', self.sample_groups)
Exemple #3
0
class SamplePositionsTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        vcf = StringIO(initial_value='')
        fasta = StringIO(initial_value='')
        self.analysis = GenomeAnalysis(10, 0.9)

    def tearDown(self):
        pass

    @unittest.skip('Not Implemented')
    def test_foo(self):
        self.analysis.sample_positions('test_contig', self.sample_groups)
Exemple #4
0
    def test_sample_analysis(self):
        with TemporaryDirectory() as tmpdir:
            matrix_dir = os.path.join(tmpdir, 'matrices')
            stats_dir = os.path.join(tmpdir, 'statistics')

            os.mkdir(matrix_dir)
            os.mkdir(stats_dir)

            genome_analysis = GenomeAnalysis(10, .9)
            reference_fasta = Fasta(testdata.REFERENCE_FASTA, 'reference', 'aligner', is_reference=True)
            reference_dups = Fasta(testdata.REFERENCE_DUPS, 'dups', 'aligner', is_reference=True)
            write_matrix.analyze_samples(matrix_dir, stats_dir, genome_analysis, reference_fasta, reference_dups, sample_groups, max_workers=1)
Exemple #5
0
    def setUp(self):
        fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, False)
        ref_fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, True)

        self.analysis = GenomeAnalysis(10, .9)
        self.coroutine_fn = lambda *arg: (self.CoroutineMock(), self.CoroutineMock())
        self.dups_contig = fasta
        self.reference_contig = ref_fasta.get_contig('ContigWithFilePositionOffset')
        self.sample_groups = (
            (
                fasta,
                fasta
            ), (
                fasta,
            ), (
                fasta,
                fasta
            )
        )
Exemple #6
0
class AnalyzeContigTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, False)
        ref_fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, True)

        self.analysis = GenomeAnalysis(10, .9)
        self.coroutine_fn = lambda *arg: (self.CoroutineMock(), self.CoroutineMock())
        self.dups_contig = fasta
        self.reference_contig = ref_fasta.get_contig('ContigWithFilePositionOffset')
        self.sample_groups = (
            (
                fasta,
                fasta
            ), (
                fasta,
            ), (
                fasta,
                fasta
            )
        )

    def tearDown(self):
        pass

    # def test_it_calls_the_coroutine_function_once(self):
    # coroutine_fn_call_count = 0
    #
    # def coroutine_fn():
    # return lambda *args: coroutine_fn_call_count += 1
    #
    # self.analysis.analyze_contig(coroutine_fn, sample_groups, dups_contig, reference_contig)

    class CoroutineMock:
        def send(self, arg):
            pass

    def test_it_collects_analysis_and_overall_contig_stats(self):
        expected_analysis_stats = [
            [
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}),
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0})
            ],
            [
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}), Counter(
                {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                 'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}), Counter(
                {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                 'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}), Counter(
                {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                 'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0})
            ], [
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}), Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}), Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0})
            ], [
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}),
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}),
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0}),
                Counter(
                    {'quality_breadth': 8, 'passed_proportion_filter': 8, 'called_reference': 8, 'was_called': 8,
                     'passed_coverage_filter': 8, 'called_snp': 0, 'called_degen': 0})
            ]
        ]
        expected_contig_stats = Counter(
            {'reference_clean': 8, 'all_passed_proportion': 8, 'quality_breadth': 8,
             'Contig': 'ContigWithFilePositionOffset', 'reference_length': 8, 'best_snps': 0,
             'all_passed_coverage': 8, 'reference_duplicated': 0, 'all_passed_consensus': 8, 'all_called': 8,
             'any_snps': 0}
        )
        observed_analysis_stats, observed_contig_stats = self.analysis.analyze_contig(self.coroutine_fn,
                                                                                      self.sample_groups,
                                                                                      self.dups_contig,
                                                                                      self.reference_contig)

        self.assertEqual(expected_analysis_stats, observed_analysis_stats)
        self.assertEqual(expected_contig_stats, observed_contig_stats)
Exemple #7
0
 def setUp(self):
     self.analysis = GenomeAnalysis(10, 0.9)
Exemple #8
0
class AnalyzePositionTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        self.analysis = GenomeAnalysis(10, 0.9)

    def tearDown(self):
        pass

    @unittest.skip('Not Implemented')
    def test_it_filters_position_by_coverage(self):
        """
        Change the coverage to check for a hardcoded value.
        """
        self.analysis.analyze_position((), (), ())

    @unittest.skip('Not Implemented')
    def test_it_filters_position_by_proportion(self):
        # Change the proportion to check for a hardcoded value.
        self.analysis.analyze_position((), (), ())

    def test_fasta_position(self):
        reference_position = Position(
            call='G',
            coverage='-',
            proportion='-'
        )

        dups_position = Position(
            call='0',
            coverage='-',
            proportion='-'
        )

        samples = (
            (
                Position(
                    call='G',
                    coverage='-',
                    proportion='-'
                ),
                Position(
                    call='G',
                    coverage='-',
                    proportion='-'
                )
            ),
        )

        expected = PositionInfo(
            is_all_called=True,
            is_reference_clean=True,
            is_reference_duplicated=False,
            is_all_passed_coverage=True,
            is_all_passed_proportion=True,
            is_all_passed_consensus=True,
            is_all_quality_breadth=True,
            is_best_snp=False,
            all_sample_stats=[
                [
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0}),
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0})
                ], [
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0}),
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0}),
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0}),
                    Counter({'called_reference': 1, 'passed_coverage_filter': 1, 'quality_breadth': 1, 'was_called': 1,
                             'passed_proportion_filter': 1, 'called_snp': 0, 'called_degen': 0})
                ]
            ],
            is_missing_matrix=False,
            called_reference=2,
            called_snp=0,
            passed_coverage_filter=2,
            passed_proportion_filter=2,
            num_A=0,
            num_C=0,
            num_G=2,
            num_T=0,
            num_N=0,
            call_str=['G', 'G', 'G'],
            masked_call_str=['G', 'G', 'G'],
            CallWasMade='YY',
            PassedDepthFilter='--',
            PassedProportionFilter='--',
            Pattern=['1', '1', '1']
        )

        self.assertEqual(expected, self.analysis.analyze_position(reference_position, dups_position, samples))
Exemple #9
0
 def setUp(self):
     vcf = StringIO(initial_value='')
     fasta = StringIO(initial_value='')
     self.analysis = GenomeAnalysis(10, 0.9)
Exemple #10
0
class AnalyzeContigTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, False)
        ref_fasta = Fasta(testdata.PARSE_FASTA, 'test_data', None, True)

        self.analysis = GenomeAnalysis(10, .9)
        self.coroutine_fn = lambda *arg: (self.CoroutineMock(),
                                          self.CoroutineMock())
        self.dups_contig = fasta
        self.reference_contig = ref_fasta.get_contig(
            'ContigWithFilePositionOffset')
        self.sample_groups = ((fasta, fasta), (fasta, ), (fasta, fasta))

    def tearDown(self):
        pass

    # def test_it_calls_the_coroutine_function_once(self):
    # coroutine_fn_call_count = 0
    #
    # def coroutine_fn():
    # return lambda *args: coroutine_fn_call_count += 1
    #
    # self.analysis.analyze_contig(coroutine_fn, sample_groups, dups_contig, reference_contig)

    class CoroutineMock:
        def send(self, arg):
            pass

    def test_it_collects_analysis_and_overall_contig_stats(self):
        expected_analysis_stats = [[
            Counter({
                'quality_breadth': 8,
                'passed_proportion_filter': 8,
                'called_reference': 8,
                'was_called': 8,
                'passed_coverage_filter': 8,
                'called_snp': 0,
                'called_degen': 0
            }),
            Counter({
                'quality_breadth': 8,
                'passed_proportion_filter': 8,
                'called_reference': 8,
                'was_called': 8,
                'passed_coverage_filter': 8,
                'called_snp': 0,
                'called_degen': 0
            })
        ],
                                   [
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       })
                                   ],
                                   [
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       })
                                   ],
                                   [
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       }),
                                       Counter({
                                           'quality_breadth': 8,
                                           'passed_proportion_filter': 8,
                                           'called_reference': 8,
                                           'was_called': 8,
                                           'passed_coverage_filter': 8,
                                           'called_snp': 0,
                                           'called_degen': 0
                                       })
                                   ]]
        expected_contig_stats = Counter({
            'reference_clean': 8,
            'all_passed_proportion': 8,
            'quality_breadth': 8,
            'Contig': 'ContigWithFilePositionOffset',
            'reference_length': 8,
            'best_snps': 0,
            'all_passed_coverage': 8,
            'reference_duplicated': 0,
            'all_passed_consensus': 8,
            'all_called': 8,
            'any_snps': 0
        })
        observed_analysis_stats, observed_contig_stats = self.analysis.analyze_contig(
            self.coroutine_fn, self.sample_groups, self.dups_contig,
            self.reference_contig)

        self.assertEqual(expected_analysis_stats, observed_analysis_stats)
        self.assertEqual(expected_contig_stats, observed_contig_stats)
Exemple #11
0
 def setUp(self):
     self.analysis = GenomeAnalysis(10, 0.9)
Exemple #12
0
class AnalyzePositionTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        pass

    def setUp(self):
        self.analysis = GenomeAnalysis(10, 0.9)

    def tearDown(self):
        pass

    @unittest.skip('Not Implemented')
    def test_it_filters_position_by_coverage(self):
        """
        Change the coverage to check for a hardcoded value.
        """
        self.analysis.analyze_position((), (), ())

    @unittest.skip('Not Implemented')
    def test_it_filters_position_by_proportion(self):
        # Change the proportion to check for a hardcoded value.
        self.analysis.analyze_position((), (), ())

    def test_fasta_position(self):
        reference_position = Position(call='G', coverage='-', proportion='-')

        dups_position = Position(call='0', coverage='-', proportion='-')

        samples = ((Position(call='G', coverage='-', proportion='-'),
                    Position(call='G', coverage='-', proportion='-')), )

        expected = PositionInfo(
            is_all_called=True,
            is_reference_clean=True,
            is_reference_duplicated=False,
            is_all_passed_coverage=True,
            is_all_passed_proportion=True,
            is_all_passed_consensus=True,
            is_all_quality_breadth=True,
            is_best_snp=False,
            all_sample_stats=[[
                Counter({
                    'called_reference': 1,
                    'passed_coverage_filter': 1,
                    'quality_breadth': 1,
                    'was_called': 1,
                    'passed_proportion_filter': 1,
                    'called_snp': 0,
                    'called_degen': 0
                }),
                Counter({
                    'called_reference': 1,
                    'passed_coverage_filter': 1,
                    'quality_breadth': 1,
                    'was_called': 1,
                    'passed_proportion_filter': 1,
                    'called_snp': 0,
                    'called_degen': 0
                })
            ],
                              [
                                  Counter({
                                      'called_reference': 1,
                                      'passed_coverage_filter': 1,
                                      'quality_breadth': 1,
                                      'was_called': 1,
                                      'passed_proportion_filter': 1,
                                      'called_snp': 0,
                                      'called_degen': 0
                                  }),
                                  Counter({
                                      'called_reference': 1,
                                      'passed_coverage_filter': 1,
                                      'quality_breadth': 1,
                                      'was_called': 1,
                                      'passed_proportion_filter': 1,
                                      'called_snp': 0,
                                      'called_degen': 0
                                  }),
                                  Counter({
                                      'called_reference': 1,
                                      'passed_coverage_filter': 1,
                                      'quality_breadth': 1,
                                      'was_called': 1,
                                      'passed_proportion_filter': 1,
                                      'called_snp': 0,
                                      'called_degen': 0
                                  }),
                                  Counter({
                                      'called_reference': 1,
                                      'passed_coverage_filter': 1,
                                      'quality_breadth': 1,
                                      'was_called': 1,
                                      'passed_proportion_filter': 1,
                                      'called_snp': 0,
                                      'called_degen': 0
                                  })
                              ]],
            is_missing_matrix=False,
            called_reference=2,
            called_snp=0,
            passed_coverage_filter=2,
            passed_proportion_filter=2,
            num_A=0,
            num_C=0,
            num_G=2,
            num_T=0,
            num_N=0,
            call_str=['G', 'G', 'G'],
            masked_call_str=['G', 'G', 'G'],
            CallWasMade='YY',
            PassedDepthFilter='--',
            PassedProportionFilter='--',
            Pattern=['1', '1', '1'])

        self.assertEqual(
            expected,
            self.analysis.analyze_position(reference_position, dups_position,
                                           samples))
Exemple #13
0
 def setUpClass(cls):
     cls.analysis = GenomeAnalysis(10, 0.9)
Exemple #14
0
 def setUp(self):
     vcf = StringIO(initial_value='')
     fasta = StringIO(initial_value='')
     self.analysis = GenomeAnalysis(10, 0.9)