Ejemplo n.º 1
0
    def __call__(self, *args, **kwargs):
        '''execute a samtools command
        '''
        retval, stderr, stdout = csamtools._samtools_dispatch(
            self.dispatch, args)
        if retval:
            raise SamtoolsError('csamtools returned with error %i: %s' %
                                (retval, "\n".join(stderr)))
        self.stderr = stderr
        # samtools commands do not propagate the return code correctly.
        # I have thus added this patch to throw if there is output on stderr.
        # Note that there is sometimes output on stderr that is not an error,
        # for example: [sam_header_read2] 2 sequences loaded.
        # Ignore messages like these
        stderr = [ x for x in stderr \
                       if not (x.startswith( "[sam_header_read2]" ) or \
                                   x.startswith("[bam_index_load]") or \
                                   x.startswith("[bam_sort_core]") or \
                                   x.startswith("[samopen] SAM header is present") )
                   ]
        if stderr: raise SamtoolsError("\n".join(stderr))

        # call parser for stdout:
        if not kwargs.get("raw") and stdout and self.parsers:
            for options, parser in self.parsers:
                for option in options:
                    if option not in args: break
                else:
                    return parser(stdout)

        return stdout
Ejemplo n.º 2
0
    def __call__(self, *args, **kwargs):
        '''execute a samtools command
        '''
        retval, stderr, stdout = csamtools._samtools_dispatch(
            self.dispatch, args)
        if retval:
            raise SamtoolsError(
                'csamtools returned with error %i: %s' %
                (retval, "\n".join(stderr)))
        self.stderr = stderr
        # samtools commands do not propagate the return code correctly.
        # I have thus added this patch to throw if there is output on stderr.
        # Note that there is sometimes output on stderr that is not an error,
        # for example: [sam_header_read2] 2 sequences loaded.
        # Ignore messages like these
        stderr = [x for x in stderr
                  if not (x.startswith("[sam_header_read2]") or
                          x.startswith("[bam_index_load]") or
                          x.startswith("[bam_sort_core]") or
                          x.startswith("[samopen] SAM header is present"))
        ]
        if stderr:
            raise SamtoolsError("\n".join(stderr))

        # call parser for stdout:
        if not kwargs.get("raw") and stdout and self.parsers:
            for options, parser in self.parsers:
                for option in options:
                    if option not in args:
                        break
                else:
                    return parser(stdout)

        return stdout
Ejemplo n.º 3
0
    def __call__(self, *args, **kwargs):
        '''execute a samtools command.

        Keyword arguments:
        catch_stdout -- redirect stdout from the samtools command and return as variable (default True)
        raw -- ignore any parsers associated with this samtools command.
        '''
        retval, stderr, stdout = csamtools._samtools_dispatch(
            self.dispatch, args, catch_stdout=kwargs.get("catch_stdout", True))

        if retval:
            raise SamtoolsError(
                'csamtools returned with error %i: %s' %
                (retval, "\n".join(stderr)))

        self.stderr = stderr

        # Uncommented for samtools 1.2
        # # samtools commands do not propagate the return code correctly.
        # # I have thus added this patch to throw if there is output on stderr.
        # # Note that there is sometimes output on stderr that is not an error,
        # # for example: [sam_header_read2] 2 sequences loaded.
        # # Ignore messages like these
        # stderr = [x for x in stderr
        #           if not (x.startswith("[sam_header_read2]") or
        #                   x.startswith("[bam_index_load]") or
        #                   x.startswith("[bam_sort_core]") or
        #                   x.startswith("[samopen] SAM header is present"))]

        # if stderr:
        #     raise SamtoolsError("\n".join(stderr))

        # call parser for stdout:
        if not kwargs.get("raw") and stdout and self.parsers:
            for options, parser in self.parsers:
                for option in options:
                    if option not in args:
                        break
                else:
                    return parser(stdout)

        return stdout
Ejemplo n.º 4
0
    def __call__(self, *args, **kwargs):
        '''execute a samtools command.

        Keyword arguments:
        catch_stdout -- redirect stdout from the samtools command and return as variable (default True)
        raw -- ignore any parsers associated with this samtools command.
        '''
        retval, stderr, stdout = csamtools._samtools_dispatch(
            self.dispatch, args, catch_stdout=kwargs.get("catch_stdout", True))

        if retval:
            raise SamtoolsError('csamtools returned with error %i: %s' %
                                (retval, "\n".join(stderr)))

        self.stderr = stderr

        # Uncommented for samtools 1.2
        # # samtools commands do not propagate the return code correctly.
        # # I have thus added this patch to throw if there is output on stderr.
        # # Note that there is sometimes output on stderr that is not an error,
        # # for example: [sam_header_read2] 2 sequences loaded.
        # # Ignore messages like these
        # stderr = [x for x in stderr
        #           if not (x.startswith("[sam_header_read2]") or
        #                   x.startswith("[bam_index_load]") or
        #                   x.startswith("[bam_sort_core]") or
        #                   x.startswith("[samopen] SAM header is present"))]

        # if stderr:
        #     raise SamtoolsError("\n".join(stderr))

        # call parser for stdout:
        if not kwargs.get("raw") and stdout and self.parsers:
            for options, parser in self.parsers:
                for option in options:
                    if option not in args:
                        break
                else:
                    return parser(stdout)

        return stdout
Ejemplo n.º 5
0
 def usage(self):
     '''return the samtools usage information for this command'''
     retval, stderr, stdout = csamtools._samtools_dispatch(self.dispatch)
     return "".join(stderr)
Ejemplo n.º 6
0
 def usage(self):
     '''return the samtools usage information for this command'''
     retval, stderr, stdout = csamtools._samtools_dispatch(
         self.dispatch)
     return "".join(stderr)