コード例 #1
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_inconsistent_sequence_length_single(self):
        sequences = [('@s1/1 abc/1', 'GGGGGGG', '+', 'YYYYYYY'),
                     ('@s2/1 abc/1', 'CCCCC', '+', 'PPPPP'),
                     ('@s3/1 abc/1', 'AAA', '+', 'PPP'),
                     ('@s4/1 abc/1', 'T', '+', 'P')]
        bsi = BarcodeSequenceFastqIterator(self.barcodes, sequences)

        barcode_map = pd.Series(['AAAA', 'AACC'],
                                name='bc',
                                index=pd.Index(['sample1', 'sample2'],
                                               name='id'))
        barcode_map = qiime2.CategoricalMetadataColumn(barcode_map)

        demux_data = emp_single(bsi, barcode_map)
        lengths = [1, 3, 5, 7]
        for n in range(1, 6):
            with tempfile.TemporaryDirectory() as output_dir:
                lengths_ = lengths[0:5 - n] if n < 4 else [1]
                # TODO: Remove _PlotQualView wrapper
                summarize(output_dir,
                          _PlotQualView(demux_data, paired=False),
                          n=n)
                plot_fp = os.path.join(output_dir, 'data.jsonp')
                with open(plot_fp, 'r') as fh:
                    jsonp = fh.read()
                    json_ = jsonp.replace('app.init(', '[').replace(');', ']')
                    payload = json.loads(json_)[0]
                    self.assertEqual(payload["totalSeqCount"], 4)
                    self.assertIn(payload["minSeqLen"]["forward"], lengths_)
                    self.assertEqual(payload["minSeqLen"]["reverse"], None)
                    self.assertEqual(payload["n"], min(n, 4))
コード例 #2
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_sequence_length_uses_subsample_paired(self):
        random.seed(6)  # Will select s1 and s2 which aren't the shortest pairs

        forward = [('@s1/1 abc/1', 'GGG', '+', 'YYY'),
                   ('@s2/1 abc/1', 'CCCCC', '+', 'PPPPP'),
                   ('@s3/1 abc/1', 'A', '+', 'P'),
                   ('@s4/1 abc/1', 'TTTTTTT', '+', 'PPPPPPP')]
        reverse = [('@s1/1 abc/1', 'AAAAA', '+', 'YYYYY'),
                   ('@s2/1 abc/1', 'TTTTTTT', '+', 'PPPPPPP'),
                   ('@s3/1 abc/1', 'GGG', '+', 'PPP'),
                   ('@s4/1 abc/1', 'C', '+', 'P')]
        bpsi = BarcodePairedSequenceFastqIterator(self.barcodes, forward,
                                                  reverse)

        barcode_map = pd.Series(['AAAA', 'AACC'],
                                name='bc',
                                index=pd.Index(['sample1', 'sample2'],
                                               name='id'))
        barcode_map = qiime2.CategoricalMetadataColumn(barcode_map)

        demux_data = emp_paired(bpsi, barcode_map)
        with tempfile.TemporaryDirectory() as output_dir:
            summarize(output_dir, _PlotQualView(demux_data, paired=True), n=2)
            plot_fp = os.path.join(output_dir, 'data.jsonp')
            with open(plot_fp, 'r') as fh:
                jsonp = fh.read()
                json_ = jsonp.replace('app.init(', '[').replace(');', ']')
                payload = json.loads(json_)[0]
                self.assertEqual(payload["minSeqLen"]["forward"], 3)
                self.assertEqual(payload["minSeqLen"]["reverse"], 5)
コード例 #3
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_phred_score_out_of_range(self):
        barcodes = self.barcodes[:3]

        sequences = [('@s1/1 abc/1', 'GGG', '+', 'jjj'),
                     ('@s2/1 abc/1', 'CCC', '+', 'iii'),
                     ('@s3/1 abc/1', 'AAA', '+', 'hhh')]
        bsi = BarcodeSequenceFastqIterator(barcodes, sequences)

        barcode_map = pd.Series(['AAAA', 'AACC', 'TTAA'],
                                name='bc',
                                index=pd.Index(
                                    ['sample1', 'sample2', 'sample3'],
                                    name='id'))
        barcode_map = qiime2.CategoricalMetadataColumn(barcode_map)

        demux_data = emp_single(bsi, barcode_map)
        with tempfile.TemporaryDirectory() as output_dir:
            result = summarize(output_dir,
                               _PlotQualView(demux_data, paired=False),
                               n=50)
            self.assertTrue(result is None)
            plot_fp = os.path.join(output_dir, 'quality-plot.html')
            with open(plot_fp, 'r') as fh:
                html = fh.read()
                self.assertIn('<strong>Danger:</strong>', html)
コード例 #4
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_paired_end(self):
        barcodes = self.barcodes[:3]

        forward = self.sequences[:3]

        reverse = [('@s1/1 abc/1', 'CCC', '+', 'YYY'),
                   ('@s2/1 abc/1', 'GGG', '+', 'PPP'),
                   ('@s3/1 abc/1', 'TTT', '+', 'PPP')]

        bpsi = BarcodePairedSequenceFastqIterator(barcodes, forward, reverse)

        barcode_map = pd.Series(['AAAA', 'AACC', 'TTAA'],
                                name='bc',
                                index=pd.Index(
                                    ['sample1', 'sample2', 'sample3'],
                                    name='id'))
        barcode_map = qiime2.CategoricalMetadataColumn(barcode_map)

        demux_data = emp_paired(bpsi, barcode_map)
        with tempfile.TemporaryDirectory() as output_dir:
            result = summarize(output_dir,
                               _PlotQualView(demux_data, paired=True),
                               n=2)
            self.assertTrue(result is None)
            plot_fp = os.path.join(output_dir, 'quality-plot.html')
            with open(plot_fp, 'r') as fh:
                html = fh.read()
                self.assertIn('<h5 class="text-center">Forward Reads</h5>',
                              html)
                self.assertIn('<h5 class="text-center">Reverse Reads</h5>',
                              html)
コード例 #5
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_single_sample(self):
        bsi = BarcodeSequenceFastqIterator(self.barcodes[:1],
                                           self.sequences[:1])

        barcode_map = pd.Series(['AAAA'],
                                name='bc',
                                index=pd.Index(['sample1'], name='id'))
        barcode_map = qiime2.CategoricalMetadataColumn(barcode_map)

        demux_data = emp_single(bsi, barcode_map)
        # test that an index.html file is created and that it has size > 0
        with tempfile.TemporaryDirectory() as output_dir:
            # TODO: Remove _PlotQualView wrapper
            result = summarize(output_dir,
                               _PlotQualView(demux_data, paired=False),
                               n=1)
            self.assertTrue(result is None)
            index_fp = os.path.join(output_dir, 'overview.html')
            self.assertTrue(os.path.exists(index_fp))
            self.assertTrue(os.path.getsize(index_fp) > 0)
            csv_fp = os.path.join(output_dir, 'per-sample-fastq-counts.csv')
            self.assertTrue(os.path.exists(csv_fp))
            self.assertTrue(os.path.getsize(csv_fp) > 0)
            pdf_fp = os.path.join(output_dir, 'demultiplex-summary.pdf')
            self.assertFalse(os.path.exists(pdf_fp))
            png_fp = os.path.join(output_dir, 'demultiplex-summary.png')
            self.assertFalse(os.path.exists(png_fp))
            with open(index_fp, 'r') as fh:
                html = fh.read()
                self.assertIn('<td>Minimum:</td><td>1</td>', html)
                self.assertIn('<td>Maximum:</td><td>1</td>', html)
コード例 #6
0
    def test_subsample_higher_than_seqs_count(self):
        barcodes = self.barcodes[:1]

        sequences = self.sequences[:1]
        bsi = BarcodeSequenceFastqIterator(barcodes, sequences)

        barcode_map = pd.Series(['AAAA'], index=['sample1'])
        barcode_map = qiime2.MetadataCategory(barcode_map)

        demux_data = emp_single(bsi, barcode_map)
        with tempfile.TemporaryDirectory() as output_dir:
            result = summarize(output_dir, _PlotQualView(demux_data,
                                                         paired=False), n=50)
            self.assertTrue(result is None)
            plot_fp = os.path.join(output_dir, 'quality-plot.html')
            with open(plot_fp, 'r') as fh:
                html = fh.read()
                self.assertIn('<strong>Warning:</strong>', html)
コード例 #7
0
ファイル: test_demux.py プロジェクト: mahermassoud/q2-demux
    def test_single_sample_multiple_files(self):
        # Note, this case came up on the QIIME 2 Forum, due to a user running
        # `summarize` with demuxed sequences that all had the same Sample ID
        # in the internal MANIFEST file. With versions of seaborn greater than
        # 0.8.0 this is no longer a problem, but on prior versions, the user
        # would see the following error:
        # TypeError: len() of unsized object
        files = [
            'sample1_S0_L001_R1_001.fastq.gz',
            'sample2_S0_L001_R1_001.fastq.gz',
            'sample3_S0_L001_R1_001.fastq.gz', 'MANIFEST', 'metadata.yml'
        ]
        for f in files:
            shutil.copy(
                self.get_data_path('single_sample_multiple_files/%s' % f),
                self.temp_dir.name)

        demux_data = SingleLanePerSampleSingleEndFastqDirFmt(
            self.temp_dir.name, mode='r')
        with tempfile.TemporaryDirectory() as output_dir:
            # TODO: Remove _PlotQualView wrapper
            result = summarize(output_dir,
                               _PlotQualView(demux_data, paired=False),
                               n=1)
            self.assertTrue(result is None)
            index_fp = os.path.join(output_dir, 'overview.html')
            self.assertTrue(os.path.exists(index_fp))
            self.assertTrue(os.path.getsize(index_fp) > 0)
            csv_fp = os.path.join(output_dir, 'per-sample-fastq-counts.csv')
            self.assertTrue(os.path.exists(csv_fp))
            self.assertTrue(os.path.getsize(csv_fp) > 0)
            pdf_fp = os.path.join(output_dir, 'demultiplex-summary.pdf')
            self.assertTrue(os.path.exists(pdf_fp))
            png_fp = os.path.join(output_dir, 'demultiplex-summary.png')
            self.assertTrue(os.path.exists(png_fp))
            with open(index_fp, 'r') as fh:
                html = fh.read()
                self.assertIn('<td>Minimum:</td><td>1</td>', html)
                self.assertIn('<td>Maximum:</td><td>1</td>', html)