示例#1
0
    def test_creates_fresh_reads_file(self, path_reads_file, require_aligned,
                                      remove_reads_file):
        """ Reads file pysam object is created by register_files(). """

        # Note that remove_reads_file is here to clear the module-scoped map.

        # Explicitly set by_chromosome=False to prevent it from
        # controlling the requirement regarding aligned reads.
        processor = IdentityProcessor(path_reads_file=path_reads_file,
                                      action="test",
                                      allow_unaligned=not require_aligned,
                                      by_chromosome=False)

        # The pysam readsfile shouldn't exist before register_files().
        with pytest.raises(CommandOrderException):
            processor.readsfile

        # Now do the registration, creating the pysam readsfile instance.
        processor.register_files()
        readsfile = processor.readsfile

        # Check out the new readsfile.
        assert isinstance(readsfile, AlignmentFile)
        num_reads = sum(1 for _ in readsfile)
        assert NUM_READS_BY_FILE[path_reads_file] == num_reads
示例#2
0
    def test_adds_pysam_kwargs(self, require_aligned, pysam_kwargs,
                               remove_reads_file):
        """ Unaligned input BAM needs check_sq=False to be created. """

        # Note that remove_reads_file is here to clear the module-scoped map.

        # Explicitly set by_chromosome=False to prevent it from
        # controlling the requirement regarding aligned reads.
        processor = IdentityProcessor(path_reads_file=PATH_UNALIGNED_FILE,
                                      action="test",
                                      allow_unaligned=not require_aligned,
                                      by_chromosome=False)

        if require_aligned:
            exp_error = MissingHeaderException if pysam_kwargs else ValueError
            with pytest.raises(exp_error):
                processor.register_files(**pysam_kwargs)
        else:
            # No exception --> pass (file registration is just for effect.)
            processor.register_files(**pysam_kwargs)