Esempio n. 1
0
def callFastqMultx(fastq_multx_call_args):

    fastq_multx_executable = confirmExecutable('fastq-multx')

    # Check if executable is installed
    if not fastq_multx_executable:
        raise IOError(
            'fastq-multx not found. Please confirm the executable is installed'
        )

    # fastq-multx subprocess call
    fastq_multx_call = subprocess.Popen(
        [fastq_multx_executable] + fastq_multx_call_args,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE,
        preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL))

    # Get stdout and stderr from subprocess
    fastq_multx_stdout, fastq_multx_stderr = fastq_multx_call.communicate()

    # Check if code is running in python 3
    if sys.version_info[0] == 3:

        # Convert bytes to string
        fastq_multx_stdout = fastq_multx_stdout.decode()
        fastq_multx_stderr = fastq_multx_stderr.decode()

    # Check the stderr for errors
    checkFastqMultxForErrors(fastq_multx_stderr)
Esempio n. 2
0
def callBlast(blast_call_args):

    # Find the blast executable
    blast_executable = confirmExecutable('blastn')

    # Check if executable is installed
    if not blast_executable:
        raise IOError(
            'blast not found. Please confirm the executable is installed')

    # blast subprocess call
    blast_call = subprocess.Popen([blast_executable] + blast_call_args,
                                  stderr=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

    # Get stdout and stderr from subprocess
    blast_stdout, blast_stderr = blast_call.communicate()

    # Check if code is running in python 3
    if sys.version_info[0] == 3:

        # Convert bytes to string
        blast_stdout = blast_stdout.decode()
        blast_stderr = blast_stderr.decode()

    # Check the stderr for errors
    checkBlastForErrors(blast_stderr)
Esempio n. 3
0
    def test_01_confirmExecutable(self):

        # Create list of executables
        executable_list = ['vsearch', 'fastq-multx', 'blastn']

        # Loop the executables
        for executable_str in executable_list:

            # Check that the non-standard executables were installed
            self.assertIsNotNone(
                confirmExecutable(executable_str),
                '%s not found. Please install' % executable_str)

        # Check that the function fails with a fake executable
        self.assertIsNone(
            confirmExecutable('retrieve_samples.py' + randomGenerator()))
Esempio n. 4
0
def callVsearch(vsearch_call_args):

    # Find the vsearch executable
    vsearch_executable = confirmExecutable('vsearch')

    # Check if executable is installed
    if not vsearch_executable:
        raise IOError(
            'vsearch not found. Please confirm the executable is installed')

    # vsearch subprocess call
    vsearch_call = subprocess.Popen([vsearch_executable] + vsearch_call_args,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)

    # Get stdout and stderr from subprocess
    vsearch_stdout, vsearch_stderr = vsearch_call.communicate()

    # Check if code is running in python 3
    if sys.version_info[0] == 3:

        # Convert bytes to string
        vsearch_stdout = vsearch_stdout.decode()
        vsearch_stderr = vsearch_stderr.decode()

    # Check for errors
    checkVsearchForErrors(vsearch_stderr)
Esempio n. 5
0
def gzipCompress(gzip_filename, return_filename=False, overwrite=True):

    # Find the gzip executable
    gzip_executable = confirmExecutable('gzip')

    # Check if executable is installed
    if not gzip_executable:
        raise IOError(
            'gzip not found. Please confirm the executable is installed')

    # Assign the overwrite argument
    overwrite_arg = []

    # Check if gzip shouldnt overwrite
    if overwrite:

        # Add the overwrite arg
        overwrite_arg.append('-f')

    # vsearch subprocess call
    gzip_call = subprocess.Popen([gzip_executable, gzip_filename] +
                                 overwrite_arg,
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)

    # Get stdout and stderr from subprocess
    gzip_stdout, gzip_stderr = gzip_call.communicate()

    # Check if code is running in python 3
    if sys.version_info[0] == 3:

        # Convert bytes to string
        gzip_stdout = gzip_stdout.decode()
        gzip_stderr = gzip_stderr.decode()

    # Update when starting logs
    #print(gzip_stdout)
    #print(gzip_stderr)

    # Check if the filename is to be returned
    if return_filename:
        return gzip_filename + '.gz'
Esempio n. 6
0
	def executeBackup (backup_executable_str, backup_call_args, backup_output):

		# Check if the executable is installed
		backup_executable = confirmExecutable(backup_executable_str)
		if not backup_executable:
			raise IOError(f'{backup_executable_str} not found. Please confirm the executable is installed')

		# Open the output file and make the subprocess call
		backup_output_file = open(backup_output, 'w')
		backup_call = subprocess.Popen([backup_executable] + backup_call_args, stderr = subprocess.PIPE, stdout = backup_output_file)

		# Get stdout and stderr from subprocess
		backup_stdout, backup_stderr = backup_call.communicate()
		if sys.version_info[0] == 3: backup_stderr = backup_stderr.decode()

		# Report any errors
		if backup_stderr: raise Exception(backup_stderr)

		# Close the file
		backup_output_file.close()
Esempio n. 7
0
def pipeBlast(blast_call_args, blast_output, header=None):

    # Find the blast executable
    blast_executable = confirmExecutable('blastn')

    # Check if executable is installed
    if not blast_executable:
        raise IOError(
            'blast not found. Please confirm the executable is installed')

    # Open the output file
    blast_output_file = open(blast_output, 'w')

    # Check if a header was specified
    if header:

        # Write the head to the output file
        blast_output_file.write(header + '\n')

        # Flush the file
        blast_output_file.flush()

    # blast subprocess call
    blast_call = subprocess.Popen([blast_executable] + blast_call_args,
                                  stderr=subprocess.PIPE,
                                  stdout=blast_output_file)

    # Get stdout and stderr from subprocess
    blast_stdout, blast_stderr = blast_call.communicate()

    # Check if code is running in python 3
    if sys.version_info[0] == 3:

        # Convert bytes to string
        blast_stderr = blast_stderr.decode()

    # Check the stderr for errors
    checkBlastForErrors(blast_stderr)

    # Close the file
    blast_output_file.close()
Esempio n. 8
0
    def __init__(self,
                 vcf_filename='',
                 bed_prefix='',
                 sample_model_dict={},
                 out_prefix='out',
                 out_dir='',
                 **kwargs):

        # Check if the plink2 executable was found
        self.plink2_path = confirmExecutable('plink2')
        if not self.plink2_path:
            raise IOError(
                'plink2 not found. Please confirm the executable is installed')
        self._plink2_call_args = []

        self.vcf_filename = vcf_filename
        self.bed_prefix = bed_prefix
        self.out_prefix = os.path.join(out_dir, out_prefix)
        self.out_dir = out_dir
        self.sample_model_dict = sample_model_dict
        self._files_to_remove = []

        # Check if the Binary-Ped files exists
        if self.bed_prefix and (os.path.isfile(f'{self.bed_prefix}.bed')
                                and os.path.isfile(f'{self.bed_prefix}.bim')
                                and os.path.isfile(f'{self.bed_prefix}.fam')):
            self.bed_exists = True
        else:
            self.bed_exists = False

        # Check if the VCF file exists
        if self.vcf_filename and os.path.isfile(self.vcf_filename):
            self.vcf_exists = True
        else:
            self.vcf_exists = False

        # Prepare the files, if needed
        self._prepFiles()