Esempio n. 1
0
def get_version(prog, path=None, raise_error=True):
    assert prog in prog_to_version_cmd
    if path is None:
        path = prog

    if not is_in_path(path):
        if raise_error:
            raise Error('Error getting version of ' + path + ' - not found in path.')
        else:
            return 'Not_in_path', 'Not_in_path'

    path = shutil.which(path)

    if prog in ['sspace', 'gapfiller']:
        cmd = 'perl ' + os.path.realpath(shutil.which(path))
        regex = prog_to_version_cmd[prog][1]
    else:
        cmd, regex = prog_to_version_cmd[prog]
        cmd = path + ' ' + cmd

    cmd_output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    cmd_output = common.decode(cmd_output[0]).split('\n')[:-1] + common.decode(cmd_output[1]).split('\n')[:-1]
    for line in cmd_output:
        hits = regex.search(line)
        if hits:
            return hits.group(1), path
    return 'UNKNOWN ...\n I tried running this to get the version: "' + cmd + '"\n and the output didn\'t match this regular expression: "' + regex.pattern + '"', path
Esempio n. 2
0
    def _sam_to_fastq(self, s):
        name = s.qname
        if s.is_read1:
            name += '/1'
        elif s.is_read2:
            name += '/2'
        else:
            raise Error('Read ' + name + ' must be first or second of pair according to flag. Cannot continue')

        seq = pyfastaq.sequences.Fastq(name, common.decode(s.seq), common.decode(s.qual))
        if s.is_reverse:
            seq.revcomp()

        return seq
Esempio n. 3
0
def sam_to_fastq(sam):
    '''Given a pysam alignment, returns the sequence a Fastq object.
       Reverse complements as required and add suffix /1 or /2 as appropriate from the flag'''
    name = sam.qname
    if sam.is_read1:
        name += '/1'
    elif sam.is_read2:
        name += '/2'
    else:
        raise Error('Read ' + name + ' must be first or second of pair according to flag. Cannot continue')

    seq = pyfastaq.sequences.Fastq(name, common.decode(sam.seq), common.decode(sam.qual))
    if sam.is_reverse:
        seq.revcomp()

    return seq
Esempio n. 4
0
    def _get_version(prog, path):
        '''Given a program name and expected path, tries to determine its version.
           Returns tuple (bool, version). First element True iff found version ok.
           Second element is version string (if found), otherwise an error message'''
        assert prog in prog_to_version_cmd
        cmd, regex = prog_to_version_cmd[prog]
        cmd = path + ' ' + cmd
        cmd_output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        cmd_output = common.decode(cmd_output[0]).split('\n')[:-1] + common.decode(cmd_output[1]).split('\n')[:-1]

        for line in cmd_output:
            hits = regex.search(line)
            if hits:
                return True, hits.group(1)

        return False, 'I tried to get the version of ' + prog + ' with: "' + cmd + '" and the output didn\'t match this regular expression: "' + regex.pattern + '"'
Esempio n. 5
0
File: mapping.py Progetto: ys4/ariba
def sam_to_fastq(sam):
    '''Given a pysam alignment, returns the sequence a Fastq object.
       Reverse complements as required and add suffix /1 or /2 as appropriate from the flag'''
    name = sam.qname
    if sam.is_read1:
        name += '/1'
    elif sam.is_read2:
        name += '/2'
    else:
        raise Error(
            'Read ' + name +
            ' must be first or second of pair according to flag. Cannot continue'
        )

    seq = pyfastaq.sequences.Fastq(name, common.decode(sam.seq),
                                   common.decode(sam.qual))
    if sam.is_reverse:
        seq.revcomp()

    return seq
Esempio n. 6
0
    def _get_version(prog, path):
        '''Given a program name and expected path, tries to determine its version.
           Returns tuple (bool, version). First element True iff found version ok.
           Second element is version string (if found), otherwise an error message'''
        assert prog in prog_to_version_cmd
        cmd, regex = prog_to_version_cmd[prog]
        cmd = path + ' ' + cmd
        cmd_output = subprocess.Popen(cmd,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()
        cmd_output = common.decode(
            cmd_output[0]).split('\n')[:-1] + common.decode(
                cmd_output[1]).split('\n')[:-1]

        for line in cmd_output:
            hits = regex.search(line)
            if hits:
                return True, hits.group(1)

        return False, 'I tried to get the version of ' + prog + ' with: "' + cmd + '" and the output didn\'t match this regular expression: "' + regex.pattern + '"'