def delete_manifest(org=None): """Deletes a manifest""" if org is None: raise InvalidInputError('org should be provided to execute this task') cmd = ('provider delete_manifest --name "{0}" ' '--org {1}'.format(PROVIDER_NAME, org)) run_command(cmd)
def get_activation_key(name, org): """Gets an activation key""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'activation_key info --name {0} --org {1}'.format(name, org) run_command(cmd)
def main(): parser = argparse.ArgumentParser(description="This script takes in a nucleotide file and filters it by both length and if it is annotated as a resistance gene or not.") parser.add_argument('-fasta', dest="nucl_fp", help="Path to nucleotide or protein fasta file") parser.add_argument('-min_len', dest="min_len", help="Minimum length gene to retain") parser.add_argument('-annotations', dest="annotation_fp", help="Path to annotations file (only necessary if filtering by resfams) - this is the *.final.txt annotation file") parser.add_argument('--res_filter', dest="res_filter", help="Flag to determine if keeping only resistance genes or all genes.", action='store_true', default=False) parser.add_argument('-ids', dest="ids", help="gene ids to keep") parser.add_argument('-o', dest="output_fp", help="Path to filtered fasta output directory") args = parser.parse_args() if args.min_len: min_len = args.min_len else: min_len = 0 if not os.path.exists(args.output_fp): h.run_command("mkdir " + args.output_fp) filtered_file = args.output_fp.rstrip('/') + "/filtered.fasta" other_file = args.output_fp.rstrip('/') + "/other.fasta" # Determine genes that have resfams annotation if args.res_filter: resfam_genes = find_res_genes(args.annotation_fp) # Filter fasta file and output SeqIO.write(filter_records(args.nucl_fp, min_len, resfams=resfam_genes)[0], filtered_file, "fasta") SeqIO.write(filter_records(args.nucl_fp, min_len, resfams=resfam_genes)[1], other_file, "fasta") elif args.ids: SeqIO.write(filter_records(args.nucl_fp, min_len, ids=[line.rstrip() for line in open(args.ids)])[0], filtered_file, "fasta") SeqIO.write(filter_records(args.nucl_fp, min_len, ids=[line.rstrip() for line in open(args.ids)])[1], other_file, "fasta") else: SeqIO.write(filter_records(args.nucl_fp, min_len)[0], filtered_file, "fasta") SeqIO.write(filter_records(args.nucl_fp, min_len)[1], other_file, "fasta")
def get_user(username): """Gets an user""" if username is None: raise InvalidInputError('username should be provided to ' 'execute this task') cmd = 'user info --username {0}'.format(username) run_command(cmd)
def get_permission(user_role): """Gets a permission""" if user_role is None: raise InvalidInputError('user_rold should be provided to ' 'execute this task') cmd = 'permission list --user_role {0}'.format(user_role) run_command(cmd)
def get_role(name): """Gets a role""" if name is None: raise InvalidInputError('role name should be provided to ' 'execute this task') cmd = 'user_role info --name {0}'.format(name) run_command(cmd)
def get_distributor(name, org): """Gets a distributor""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'distributor info --name {0} --org {1}'.format(name, org) run_command(cmd)
def quantitize_image(filename, extension, colors): try: run_command( f'magick {filename}.{extension} -kmeans {colors} {filename}_temp.png' ) except: print('Something went wrong while quantitizing your image')
def _run(facts): log.pDebug("Running Apache plugin") if 'httpd' in facts.processes: run_command(['httpd', '-S']) else: log.pDebug("Apache not in running processes list")
def get_system_group(name, org): """Gets a system group""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'system_group info --name {0} --org {1}'.format(name, org) run_command(cmd)
def calculate_global_identity_blastp_fasta(args): # import proteins as fasta protein_dict = SeqIO.to_dict(SeqIO.parse(args.protein_fp, "fasta")) proteindb_dict = SeqIO.to_dict(SeqIO.parse(args.protdb_fp, "fasta")) final = open(args.output_fp + "/final_protein_identity.txt", 'w') for result in open(args.output_fp + "/blastp_results.txt", 'r'): id_number1 = result.split()[0] print(id_number1) id_number2 = result.split()[1] print(id_number2) SeqIO.write(protein_dict[id_number1], args.output_fp + "/temp_fasta1.fa", "fasta") SeqIO.write(proteindb_dict[id_number2], args.output_fp + "/temp_fasta2.fa", "fasta") needle = "needle -outfile=" + args.output_fp + "/temp_identity.txt -asequence " + args.output_fp + "/temp_fasta1.fa -bsequence " + args.output_fp + "/temp_fasta2.fa -gapope\ n=10 -gapextend=0.5" h.run_command(needle) identity = "NA" for line in open(args.output_fp + "/temp_identity.txt", 'r'): if line.startswith("# Identity:"): identity = line.split("(")[1].rstrip("\n").rstrip(")").rstrip("%") final.write(id_number1 + "\t" + retrieve_annotations(id_number1, args.anno_tab) + "\t"+ id_number2 + "\t" + identity + "\n") h.run_command("rm " + args.output_fp + "/temp_*")
def update_org(name, new_description=None): """Updates an org.""" if name is None: raise InvalidInputError('org name should be provided' 'to execute this task') run_command('org update --name={0} --description={1}'.format( name, new_description)) return name
def create_system(name=None, org=None): """Creates a system""" if name is None: name = gen_string("alphanumeric", 10) if org is None: org = create_org() run_command('system register --name {0} --org {1}'.format(name, org)) return name
def create_distributor(name=None, org=None): """Creates a distributor""" if name is None: name = gen_string("alphanumeric", 10) if org is None: org = create_org() run_command('distributor create --name {0} --org {1}'.format(name, org)) return name
def copy_sample_graphs(head_node, goffish_relative_path): graph_folder_path = head_node.path.source + goffish_relative_path + '/sample/gofs-graphs' sample_path = head_node.path.sample h_add = head_node.address h_user = head_node.username helper.run_command(h_add, h_user,'cp -r ' + graph_folder_path + ' ' + sample_path) return
def get_system(name, org): """Gets a system""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'system info --name {0} --org {1}'.format(name, org) # Open bug run_command(cmd, warn_only=True)
def delete_permission(name, user_role): """Creates a permission""" if name is None or user_role is None: raise InvalidInputError('name and user_role should be provided to ' 'execute this task') cmd = ('permission delete --name {0} ' '--user_role {1}').format(name, user_role) run_command(cmd)
def create_role(name=None, description=None): """Creates an user role""" if name is None: name = gen_string("alphanumeric", 10) if description is None: description = gen_string("alphanumeric", 10) run_command('user_role create --name {0} --description {1}'.format( name, description)) return name
def copy_compiled_source(head_node, temp_path): #copies from temp to head node source os.system("tar -czvf ./source.tar.gz -C " + temp_path + " .") h_add = head_node.address h_user = head_node.username helper.copy_file_to_remote(h_add, h_user,"source.tar.gz", head_node.path.source) tar_command = "tar -C " + head_node.path.source + " -xzvf " + head_node.path.source + "/source.tar.gz" helper.run_command(h_add, h_user, tar_command) helper.run_command(h_add, h_user, "rm " + head_node.path.source + "/source.tar.gz") os.system("rm ./source.tar.gz") print "Source Copied To HeadNode" return
def update_role(name, new_name=None, new_description=None): """Updates an user role""" if name is None: raise InvalidInputError('role name should be provided to ' 'execute this task') cmd = 'user_role update --name {0} '.format(name) if new_name is not None: cmd = cmd + ' --new_name {0} '.format(new_name) if new_description is not None: cmd = cmd + ' --description {0} '.format(new_description) run_command(cmd) if new_name is not None: return new_name
def update_distributor(name, org, new_name=None, new_description=None): """Updates a distributor""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'distributor update --name {0} --org {1} '.format(name, org) if new_name is not None: cmd = cmd + '--new_name {0} '.format(new_name) if new_description is not None: cmd = cmd + '--description {0}'.format(new_description) run_command(cmd) if new_name is not None: return new_name
def update_system(name=None, org=None, new_name=None, new_description=None): """Updates a system""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'system update --name {0} --org {1} '.format(name, org) if new_name is not None: cmd = cmd + '--new_name {0} '.format(new_name) if new_description is not None: cmd = cmd + '--description {0}'.format(new_description) run_command(cmd, warn_only=True) if new_name is not None: return new_name
def create_activation_key(name=None, org=None, description=None, limit=None): """Creates an activation key.""" if name is None: name = gen_string("alphanumeric", 10) if org is None: org = create_org() if description is None: description = gen_string("alphanumeric", 10) if limit is None: limit = gen_integer(min_value=1, max_value=3) run_command('activation_key create --name {0} --org {1} --description {2}' ' --limit {3}'.format(name, org, description, limit)) return name
def cluster_fasta(output_fp, args): for fasta in os.listdir(output_fp): basename = os.path.splitext(os.path.basename(fasta))[0] if args.protein_fp: cluster_fp = output_fp + '/' + basename + '_unique.faa' command = 'cd-hit -i ' + output_fp + '/' + fasta + ' -o ' + cluster_fp + ' -c ' + args.percent_id + ' -aS 1.0 -g 1 -d 0' elif args.nucleotide_fp: cluster_fp = output_fp + '/' + basename + '_unique.fna' command = 'cd-hit-est -i ' + output_fp + '/' + fasta + ' -o ' + cluster_fp + ' -c ' + args.percent_id + ' -aS 1.0 -g 1 -d 0 -r 1' h.run_command(command) if args.within_lib and args.within_abx: if args.nucleotide_fp: command = 'cat ' + output_fp + '/*_unique.fna > ' + output_fp + '/unique_within_lib-abx_' + args.percent_id + '.fna' else: command = 'cat ' + output_fp + '/*_unique.faa > ' + output_fp + '/unique_within_lib-abx_'+ args.percent_id + '.faa' h.run_command(command) elif args.within_lib: if args.nucleotide_fp: command = 'cat ' + output_fp + '/*_unique.fna > ' + output_fp + '/unique_within_lib_' + args.percent_id + '.fna' else: command = 'cat ' + output_fp + '/*_unique.faa > ' + output_fp + '/unique_within_lib_'+ args.percent_id + '.faa' h.run_command(command) elif args.within_abx: if args.nucleotide_fp: command = 'cat ' + output_fp + '/*_unique.fna > ' + output_fp + '/unique_within_abx_'+ args.percent_id + '.fna' else: command = 'cat ' + output_fp + '/*_unique.faa > ' + output_fp + '/unique_within_abx_'+ args.percent_id + '.faa' h.run_command(command)
def calculate_global_identity_blastp_ncbi(args): # set NCBI information Entrez.email = "*****@*****.**" # import proteins as fasta protein_dict = SeqIO.to_dict(SeqIO.parse(args.protein_fp, "fasta")) final = open(args.output_fp + "/final_protein_identity.txt", 'w') for result in open(args.output_fp + "/blastp_results.txt", 'r'): id_number1 = result.split()[0] id_number2 = result.split()[1].split('|')[3] try: SeqIO.write(protein_dict[id_number1], args.output_fp + "/temp_fasta1.fa", "fasta") except: print("(1) Didn't work for + " + id_number1, file=sys.stderr) try: handle = Entrez.efetch(db='protein', id=id_number2, rettype="text", retmode="fasta") output = open(args.output_fp + "/temp_fasta2.fa", 'w') output.write(handle.read()) output.close() except: print("(1) Didn't work for " + id_number2, file=sys.stderr) needle = "needle -outfile=" + args.output_fp + "/temp_identity.txt -asequence " + args.output_fp + "/temp_fasta1.fa -bsequence " + args.output_fp + "/temp_fasta2.fa -gapopen=10 -gapextend=0.5" h.run_command(needle) identity = "NA" for line in open(args.output_fp + "/temp_identity.txt", 'r'): if line.startswith("# Identity:"): identity = line.split("(")[1].rstrip("\n").rstrip(")").rstrip("%") try: handle = Entrez.efetch(db='protein', id=result.split()[1].split('|')[3], rettype="text", retmode="gb") record = SeqIO.read(handle, "genbank") if "source" in record.annotations and "taxonomy" in record.annotations: final.write(id_number1 + "\t" + retrieve_annotations(id_number1, args.anno_tab) + "\t" + id_number2 + "\t" + identity + "\t" + record.description + "\t" + record.annotations["source"] + "\t" + ";".join(record.annotations["taxonomy"]) + "\n") elif "source" in record.annotations: final.write(id_number1 + "\t" + retrieve_annotations(id_number1, args.anno_tab) + "\t"+ id_number2 + "\t" + identity + "\t" + record.description + "\t" + record.annotations["source"] + "\n") else: final.write(id_number1 + "\t" + retrieve_annotations(id_number1, args.anno_tab) + "\t"+ id_number2 + "\t" + identity + "\t" + record.description + "\t" + "\n") except: final.write(id_number1 + "\t" + retrieve_annotations(id_number1, args.anno_tab) + "\t"+ id_number2 + "\t" + identity + "\n") print("(2) Didn't work for " + id_number1 + " " + id_number2, file=sys.stderr) h.run_command("rm " + args.output_fp + "/temp_*")
def generate_histogram(filename): try: return run_command( f'magick convert {filename} -format %c -depth 8 histogram:info:-', get_output=True) except: print('Something went wrong while generating the histogram')
def fill_gofs_bin(head_node, machine_list, goffish_relative_path): headnode_source_path = head_node.path.source gofs_zip_path = headnode_source_path + goffish_relative_path +'gofs/code/modules/gofs-distribution/target/gofs-bin.zip' helper.copy_file_from_remote(head_node.address, head_node.username, gofs_zip_path, 'gofs-bin.zip') for m in machine_list: remote_path = m.path.bin + '/gofs-bin' helper.copy_file_to_remote(m.address, m.username, 'gofs-bin.zip', remote_path) helper.run_command(m.address, m.username, "unzip " + remote_path + '/gofs-bin.zip' + " -d " + remote_path) helper.run_command(m.address, m.username, "rm "+ remote_path + '/gofs-bin.zip') helper.run_command(m.address, m.username, "cp -r " + remote_path +'/gofs/* '+remote_path +'/') helper.run_command(m.address, m.username, "chmod 777 "+ remote_path + '/*') helper.run_command(m.address, m.username, "rm -r "+ remote_path + '/gofs') return
def update_activation_key(name, org, new_name=None, new_description=None, new_limit=None): """Updates an activation key.""" if name is None or org is None: raise InvalidInputError('Activation key name and org name should be ' 'provided to execute this task') cmd = 'activation_key update --name {0} --org {1} '.format(name, org) if new_name is not None: cmd = cmd + '--new_name={0} '.format(new_name) if new_name is not None: cmd = cmd + '--description={0} '.format(new_description) if new_name is not None: cmd = cmd + '--limit={0}'.format(new_limit) run_command(cmd) if new_name is not None: return new_name
def update_system_group(name=None, org=None, new_name=None, new_description=None, new_max_systems=None): """Updates a system group""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'system_group update --name {0} --org {1} '.format(name, org) if new_name is not None: cmd = cmd + '--new_name {0} '.format(new_name) if new_description is not None: cmd = cmd + '--description {0} '.format(new_description) if new_max_systems is not None: cmd = cmd + '--max_systems {0}'.format(new_max_systems) run_command(cmd) if new_name is not None: return new_name
def create_user(username=None, password=None, email=None, default_organization=None, default_locale=None): """Creates an user""" if username is None: username = gen_string("alphanumeric", 10) if password is None: password = gen_string("alphanumeric", 10) if email is None: email = gen_email("alphanumeric", 10) cmd = 'user create --username {0} --password {1} --email {2}'.format( username, password, email) if default_organization is not None: cmd = cmd + ' --default_organization {0}'.format(default_organization) if default_locale is not None: cmd = cmd + ' --default_locale {0}'.format(default_locale) run_command(cmd) return username
def copy_samples_apps(head_node, goffish_relative_path, temp_path): sample_path = temp_path + goffish_relative_path[:-1] + '/gopher/samples' print sample_path jar_list = get_all_jars_in_folder(os.path.expanduser(sample_path)) print jar_list source_jar_list = map(lambda x: x.replace(os.path.expanduser(temp_path), head_node.path.source), jar_list) print source_jar_list h_add = head_node.address h_sam_path = head_node.path.sample h_user = head_node.username for s in source_jar_list: helper.run_command(h_add, h_user, "cp " + s + " " + h_sam_path + '/gopher-apps') return
def kill(head_node, machine_list): #kill $(ps aux | grep -v [N]ameNode | grep '[l]ocalhost' | awk '{print $2}') #we will execute the kill command last on headnode is_headnode_in_machinelist = False for m in machine_list: kill_command = m.path.bin +"/gopher-bin/gopher-server/bin/kill-gopher.sh" helper.run_command(m.address, m.username, kill_command) if m.address == head_node.address: is_headnode_in_machinelist = True if not is_headnode_in_machinelist: kill_command = head_node.path.bin +"/gopher-bin/gopher-server/bin/kill-gopher.sh" helper.run_command(head_node.address, head_node.username, kill_command)
def import_manifest(org=None, filepath=None, deleted=True): """Imports a manifest If delete is set to False, the manifest will not be deleted and the user has to handle the deletion manually or by calling delete_manifest """ if org is None: org = create_org() if filepath is None: filepath = MANIFEST_URL cmd = ('provider import_manifest create --name "{0}" --org {1} ' '--file "{2}"').format(PROVIDER_NAME, org, filepath) run_command(cmd) if deleted is True: print ('* After manifest import, manifest will be deleted so as ' 'to reuse it *') delete_manifest(org)
def import_manifest(org=None, filepath=None, deleted=True): """Imports a manifest If delete is set to False, the manifest will not be deleted and the user has to handle the deletion manually or by calling delete_manifest """ if org is None: org = create_org() if filepath is None: filepath = MANIFEST_URL cmd = ('provider import_manifest create --name "{0}" --org {1} ' '--file "{2}"').format(PROVIDER_NAME, org, filepath) run_command(cmd) if deleted is True: print('* After manifest import, manifest will be deleted so as ' 'to reuse it *') delete_manifest(org)
def update_user(username, new_password=None, new_email=None, new_default_organization=None, new_default_locale=None): """Updates an user""" if username is None: raise InvalidInputError('username should be provided to ' 'execute this task') cmd = 'user update --username {0} '.format(username) if new_password is not None: cmd = cmd + ' --password {0} '.format(new_password) if new_email is not None: cmd = cmd + ' --email {0} '.format(new_email) if new_default_organization is not None: cmd = cmd + (' --default_organization' ' {0} '.format(new_default_organization)) if new_default_locale is not None: cmd = cmd + ' --default_locale {0}'.format(new_default_locale) run_command(cmd) return username
def update_system_group(name=None, org=None, new_name=None, new_description=None, new_max_systems=None): """Updates a system group""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') cmd = 'system_group update --name {0} --org {1} '.format(name, org) if new_name is not None: cmd = cmd + '--new_name {0} '.format(new_name) if new_description is not None: cmd = cmd + '--description {0}'.format(new_description) if new_max_systems is not None: cmd = cmd + '--max_systems {0}'.format(new_max_systems) run_command(cmd) if new_name is not None: return new_name
def create_permission(name=None, user_role=None, description=None, scope=None, verbs=None): """Creates a permission""" if name is None: name = gen_string("alphanumeric", 10) if user_role is None: user_role = create_role() if description is None: description = gen_string("alphanumeric", 10) if scope is None: scope = 'activation_keys' if verbs is None: verbs = 'read_all' cmd = ('permission create --name {0} --user_role {1} ' '--description {2} --scope {3} ' '--verbs {4}').format(name, user_role, description, scope, verbs) run_command(cmd) return name
def _run(facts): log.pInfo( "Ran the example module. This uses the \"processes\" datasource.") log.pInfo( "Example of getting data from sources - number of running processes: %s" % len(facts.processes)) log.pError("Example of an error message") log.pWarning("Example of a warning message") log.pDebug("Example of a debug message") # Example of running a shell command o = run_command(["uname", "-r"]) log.pInfo("Example command output - kernel version is: %s" % o[0])
def delete_org(name): """Deletes an org.""" if name is None: raise InvalidInputError('name should be provided to execute this task') run_command('org delete --name={0}'.format(name))
def delete_system_group(name, org): """Deletes a system group""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') run_command('system_group delete --name {0} --org {1}'.format(name, org))
def delete_distributor(name, org): """Deletes a distributor""" if name is None or org is None: raise InvalidInputError('name and org should be provided to ' 'execute this task') run_command('distributor delete --name {0} --org {1}'.format(name, org))