Пример #1
0
def form_restart_cluster():
    '''
    Restart a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Restart cluster')

    # get the cluster name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) == []:
        print('WARNING: There is not any running cluster.')
        OK = False
    else:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)

    # confirm the restarting of the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The cluster is going to be restarted.')

    # stop the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.restart_cluster.__name__)
        OK = xcluster.restart_cluster(cluster_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #2
0
def form_open_terminal():
    '''
    Open a terminal windows of a cluster node.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cloud control - Open a terminal')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=True, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the terminal opening
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The terminal is going to be opened using StarCluster.')

    # open de terminal
    if OK:
        xcluster.open_terminal(cluster_name, node_name)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #3
0
def form_create_keypairs():
    '''
    Create the key pairs of a region.
    '''

    # initialize the control variable
    OK = True

    # print the header and get the cluster name
    clib.clear_screen()
    clib.print_headers_with_environment('Security - Create key pairs')

    # get current region name
    region_name = xconfiguration.get_current_region_name()

    # confirm the creation of the key pairs
    print(xlib.get_separator())
    OK = clib.confirm_action('The key pairs of the region {0} are going to be created.'.format(region_name))

    # create key pairs
    if OK:
        print(xlib.get_separator())
        print('The key pairs of the region {0} are been created ...'.format(region_name))
        (OK, error_list) = xec2.create_keypairs(region_name)
        if OK:
            print('The key pairs and their corresponding local files have been created.')
        else:
            for error in error_list:
                print(error)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #4
0
def form_manage_toa_database(process_type):
    '''
    Manage the TOA database.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    if process_type == xlib.get_toa_type_recreate():
        clib.print_headers_with_environment(
            f'{xlib.get_toa_name()} - Recreate database')
    elif process_type == xlib.get_toa_type_rebuild():
        clib.print_headers_with_environment(
            f'{xlib.get_toa_name()} - Rebuild database')

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(
            f'The {xlib.get_toa_name()} database is going to be {process_type}.'
        )

    # run the process
    if OK:
        devstdout = xlib.DevStdOut(xtoa.manage_toa_database.__name__)
        OK = xtoa.manage_toa_database(process_type, devstdout, function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #5
0
def form_remove_volume():
    '''
    Remove a volume in the current zone.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Remove volume')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the volume name
    print(xlib.get_separator())
    volume_name = cinputs.input_volume_name(zone_name, template_name='', help=True, help_type='created')

    # confirm the removal of the volume
    print(xlib.get_separator())
    OK = clib.confirm_action('The volume is going to be removed.')

    # remove the volume
    if OK:
        devstdout = xlib.DevStdOut(xvolume.remove_volume.__name__)
        OK = xvolume.remove_volume(volume_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #6
0
def form_update_connection_data():
    '''
    Update the user id, access key id,  secret access key and contact e-mail address
    in the NGScloud config file corresponding to the environment.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Update connection data')

    # get basic AWS data and contact e-mail address from NGScloud config file
    (user_id, access_key_id, secret_access_key) = xconfiguration.get_basic_aws_data()
    email = xconfiguration.get_contact_data()

    # input the new AWS data and the contact e-mail address
    print(xlib.get_separator())
    user_id = cinputs.input_user_id(user_id)
    access_key_id = cinputs.input_access_key_id(access_key_id)
    secret_access_key = cinputs.input_secret_access_key(secret_access_key)
    email = cinputs.input_email(email)

    # verify the AWS access key identification and the AWS secret access key   
    print(xlib.get_separator())
    print('Verifying the AWS access key identification and the AWS secret access key')
    OK = xec2.verify_aws_credentials(access_key_id, secret_access_key)
    if OK:
        print('The credentials are OK.')
    else:
        print('ERROR: The credentials are wrong. Please review your access key identification and secret access key in the AWS web.')

    # get the NGScloud config file
    if OK:
        ngscloud_config_file = xconfiguration.get_ngscloud_config_file()
    
    # confirm the connection data update in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The file {0} is going to be update with the new connection data.'.format(ngscloud_config_file))

    # save the options dictionary in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        print('The file {0} is being update with the new connection data ...'.format(ngscloud_config_file))
        (OK, error_list) = xconfiguration.update_connection_data(user_id, access_key_id, secret_access_key)
        if OK:
            (OK, error_list) = xconfiguration.update_contact_data(email)
        if OK:
            print('The config file has been update.')
        else:
            for error in error_list:
                print(error)
            raise xlib.ProgramException('C001')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #7
0
def form_delink_volume_from_template():
    '''
    Delink a volume from a cluster template
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Delink volume in a cluster template')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the template name and the volume name
    print(xlib.get_separator())
    template_name = cinputs.input_template_name(volume_creator_included=False, help=True, is_all_possible=True)
    volume_name = cinputs.input_volume_name(zone_name, template_name, help=True, help_type='linked')
 
    # verify there is some volume linked to the cluster template
    if volume_name == '':
        print(xlib.get_separator())
        print('*** WARNING: There is not any volume linked to the cluster template.')
        OK = False
 
    # confirm the exclusion of the volume
    if OK:
        print(xlib.get_separator())
        if template_name == 'all':
            OK = clib.confirm_action('The volume {0} is going to be delinked from every template.'.format(volume_name))
        else:
            OK = clib.confirm_action('The volume {0} is going to be delinked from the template {0}.'.format(volume_name, template_name))

    # delink a volume in a cluster template
    if OK:
        print(xlib.get_separator())
        print('The volume {0} is being delinked from the cluster template {1}.'.format(volume_name, template_name))
        devstdout = xlib.DevStdOut(xconfiguration.delink_volume_from_template.__name__)
        (OK, error_list) = xconfiguration.delink_volume_from_template(template_name, volume_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #8
0
def form_terminate_cluster(force):
    '''
    Terminate a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    if not force:
        clib.print_headers_with_environment('Cluster operation - Terminate cluster')
    else:
        clib.print_headers_with_environment('Cluster operation - Force termination of a cluster')

    # get the cluster name that must be terminated
    print(xlib.get_separator())
    if not force:
        if xec2.get_running_cluster_list(volume_creator_included=False) == []:
            print('WARNING: There is not any running cluster.')
            OK = False
        else:
            cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
    else:
        cluster_name = cinputs.input_template_name(volume_creator_included=False, help=False, is_all_possible=False)

    # confirm the termination of the cluster
    if OK:
        print(xlib.get_separator())
        if not force:
            OK = clib.confirm_action('The cluster is going to be terminated.')
        else:
            OK = clib.confirm_action('The cluster is going to be forced to terminate.')

    # terminate the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.terminate_cluster.__name__)
        OK = xcluster.terminate_cluster(cluster_name, force, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #9
0
def form_run_pipeline_process(pipeline_type):
    '''
    Run a pipeline process with the parameters in the corresponding config file.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()

    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()

    elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
        name = xlib.get_toa_process_merge_annotations_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Run process')

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(f'The {name} process is going to be run.')

    # run the process
    if OK:

        if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
            devstdout = xlib.DevStdOut(xtoa.run_pipeline_process.__name__)
            OK = xtoa.run_pipeline_process(pipeline_type,
                                           devstdout,
                                           function=None)

        elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
            devstdout = xlib.DevStdOut(xtoa.run_pipeline_process.__name__)
            OK = xtoa.run_pipeline_process(pipeline_type,
                                           devstdout,
                                           function=None)

        elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
            devstdout = xlib.DevStdOut(
                xtoa.run_annotation_merger_process.__name__)
            OK = xtoa.run_annotation_merger_process(devstdout, function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #10
0
def form_kill_batch_job():
    '''
    Kill a batch job in the cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Kill batch job')

    # get the cluster name, experiment identification, read dataset identification and the file pattern
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) == []:
        print('WARNING: There is not any running cluster.')
        OK = False
    else:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)

    # create the SSH client connection
    if OK:
        (OK, error_list, ssh_client) = xssh.create_ssh_client_connection(cluster_name, 'master')
        for error in error_list:
            print(error)

    # get the batch job identificaction
    if OK:
        batch_job_id = cinputs.input_batch_job_id(ssh_client, help=True)
        if batch_job_id == '':
            print('WARNING: There is not any batch job.')
            OK = False

    # confirm the kill of the batch job
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The batch job {0} is going to be killed.'.format(batch_job_id))

    # kill the batch job
    if OK:
        devstdout = xlib.DevStdOut(xcluster.kill_batch_job.__name__)
        xcluster.kill_batch_job(cluster_name, batch_job_id, devstdout, function=None)

    # close the SSH client connection
    if OK:
        xssh.close_ssh_client_connection(ssh_client)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #11
0
def form_restart_pipeline_process(pipeline_type):
    '''
    Restart a pipeline process from the last step ended OK.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Run process')

    # get the pipeline dataset identification
    app_list = [pipeline_type]
    pipeline_dataset_id = cinputs.input_result_dataset_id(
        xlib.get_toa_result_pipeline_dir(), app_list)
    if pipeline_dataset_id == '':
        print(f'WARNING: There are not any {pipeline_type} result datasets.')
        OK = False

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(f'The {name} process is going to be run.')

    # run the process
    if OK:

        devstdout = xlib.DevStdOut(xtoa.restart_pipeline_process.__name__)
        OK = xtoa.restart_pipeline_process(pipeline_type,
                                           pipeline_dataset_id,
                                           devstdout,
                                           function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #12
0
def form_mount_volume():
    '''
    Mount a volume in a node.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Mount volume in a node')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=True, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # get the volume name, AWS device file and directory path
    if OK:
        volume_name = cinputs.input_volume_name(zone_name, template_name='', help=True, help_type='created')
        aws_device_file = cinputs.input_device_file(node_name, volume_name)
        mounting_path = cinputs.input_mounting_path(node_name, aws_device_file)

    # confirm the mounting of the volume
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The volume is going to be mounted.')

    # mount the volume in the node
    if OK:
        devstdout = xlib.DevStdOut(xvolume.mount_volume.__name__)
        xvolume.mount_volume(cluster_name, node_name, volume_name, aws_device_file, mounting_path, devstdout, function=None, is_menu_call=True)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #13
0
def form_review_volume_links():
    '''
    Review linked volumes of cluster templates in order to remove linked volumes
    that do not currently exist.
    '''

    # initialize the control variable and the error list
    OK = True
    error_list = []

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Review volumes linked to cluster templates')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the NGScloud confign file
    ngscloud_config_file = xconfiguration.get_ngscloud_config_file()

    # verify if there are any volumes linked
    if xconfiguration.get_volumes_dict() == {}:
        print(xlib.get_separator())
        print('WARNING: There is not any volume linked.')
        OK = False
 
    # confirm the review of volumes links
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The file {0} is going to be reviewed in order to remove volumes linked which are not currently created in the zone {1}.'.format(ngscloud_config_file, zone_name))

    # review volumen link
    if OK:
        devstdout = xlib.DevStdOut(xconfiguration.review_volume_links.__name__)
        (OK, error_list) = xconfiguration.review_volume_links(zone_name, devstdout, function=None)

    # show continuation message or exit of application
    print(xlib.get_separator())
    if not OK and error_list != []:
        raise xlib.ProgramException('C001')
    else:
        input('Press [Intro] to continue ...')
Пример #14
0
def form_create_volume():
    '''
    Create a volume in the current zone.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Create volume')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # show sites related to EBS volumes
    print(xlib.get_separator())
    print('You can consult the characteristics of the EBS volumes in:')
    print('    https://aws.amazon.com/ebs/details/')
    print('and the EBS pricing is detailed in:')
    print('    https://aws.amazon.com/ebs/pricing/')

    # get the cluster name, node name, volume name, volume type and volume size
    print(xlib.get_separator())
    volume_name = cinputs.input_volume_name(zone_name, template_name='', help=False, help_type='created')
    volume_type = cinputs.input_volume_type()
    volume_size = cinputs.input_volume_size(volume_type)
    terminate_indicator = cinputs.input_terminate_indicator()

    # confirm the creation of the volume
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The volume is going to be created.')

    # create the volume
    if OK:
        devstdout = xlib.DevStdOut(xvolume.create_volume.__name__)
        OK = xvolume.create_volume(volume_name, volume_type, volume_size, terminate_indicator, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #15
0
def form_create_cluster():
    '''
    Create a cluster from a template name.
    '''

    # initialize the control variable
    OK = True

    # initialize the state variables
    master_state_code = ''
    master_state_name = ''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Create cluster')

    # show sites related to EBS volumes
    print(xlib.get_separator())
    print('You can consult the characteristics of the EC2 intance types in:')
    print('    https://aws.amazon.com/ec2/instance-types/')
    print('and the EC2 pricing is detailed in:')
    print('    https://aws.amazon.com/ec2/pricing/')
    print()

    # get the template name and set the cluster name
    print(xlib.get_separator())
    template_name = cinputs.input_template_name(volume_creator_included=False, help=True, is_all_possible=False)
    cluster_name = template_name

    # confirm the creation of the cluster
    print(xlib.get_separator())
    OK = clib.confirm_action('The cluster is going to be created.')

    # create the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.create_cluster.__name__)
        (OK, master_state_code, master_state_name) = xcluster.create_cluster(template_name, cluster_name, devstdout, function=None, is_menu_call=True)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #16
0
def form_update_region_zone():
    '''
    Update the current region and zone names in the NGScloud config file
    corresponding to the envoronment.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Update region and zone')

    # input new current region and zone
    print(xlib.get_separator())
    region_name = cinputs.input_region_name(region_name, help=True)
    zone_name = cinputs.input_zone_name(region_name, zone_name, help=True)
  
    # get the NGScloud config file
    ngscloud_config_file = xconfiguration.get_ngscloud_config_file()
  
    # confirm the region and zone update in the NGScloud config file
    print(xlib.get_separator())
    OK = clib.confirm_action('The file {0} is going to be update with the new region and zone.'.format(ngscloud_config_file))

    # save the options dictionary in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        print('The file {0} is being update with the new region and zone ...'.format(ngscloud_config_file))
        (OK, error_list) = xconfiguration.update_region_zone_data(region_name, zone_name)
        if OK:
            print('The config file has been update.')
        else:
            for error in error_list:
                print(error)
            raise xlib.ProgramException('C001')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #17
0
def form_add_node():
    '''
    Add a node in a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Node operation - Add node in a cluster')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        if len(xec2.get_cluster_node_list(cluster_name)) >= xec2.get_max_node_number():
            print('WARNING: The maximum number ({0}) of instances is already running.'.format(xec2.get_max_node_number()))
            OK = False
        else:
            node_name = cinputs.input_node_name(cluster_name, new=True, is_master_valid=False, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the addition of the node in the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The node is going to be added.')

    # add node in cluster
    if OK:
        devstdout = xlib.DevStdOut(xnode.add_node.__name__)
        xnode.add_node(cluster_name, node_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #18
0
def form_remove_node():
    '''
    Remove a node in a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Node operation - Remove node in a cluster')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=False, help=True)
        if node_name == []:
            print('WARNING: There is not any running node besides the master.')
            OK = False
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the removal of the node in the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The node is going to be removed.')

    # remove node
    if OK:
        devstdout = xlib.DevStdOut(xnode.remove_node.__name__)
        xnode.remove_node(cluster_name, node_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #19
0
def form_terminate_volume_creator():
    '''
    Terminate de volume creator of the current zone.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Terminate volume creator')

    # confirm the termination of the volume creator
    print(xlib.get_separator())
    OK = clib.confirm_action('The volume creator is going to be terminated.')

    # terminate the volume creator
    if OK:
        devstdout = xlib.DevStdOut(xcluster.terminate_cluster.__name__)
        xcluster.terminate_cluster(xlib.get_volume_creator_name(), True, devstdout, function=None, is_menu_call=False)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #20
0
def form_recreate_data_file(data_file):
    '''
    Recreate a data file.
    '''

    # get the head
    if data_file == xtoa.get_dataset_file():
        head = f'{xlib.get_toa_name()} - Recreate the file of genomic dataset'
    elif data_file == xtoa.get_species_file():
        head = f'{xlib.get_toa_name()} - Recreate the file of species'

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(head)

    # confirm the creation of the data file
    print(xlib.get_separator())
    OK = clib.confirm_action(
        f'The file {data_file} is going to be recreated. The previous files will be lost.'
    )

    # recreate the config file
    if OK:
        if data_file == xtoa.get_dataset_file():
            (OK, error_list) = xtoa.create_dataset_file()
        elif data_file == xtoa.get_species_file():
            (OK, error_list) = xtoa.create_species_file()
        if OK:
            print('The file is recreated.')
        else:
            for error in error_list:
                print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #21
0
def form_manage_genomic_database(process_type, genomic_database):
    '''
    Manage processes of genomic database.
    '''

    # initialize the control variable
    OK = True

    # set the genomica database name
    if genomic_database == xlib.get_toa_data_basic_data_code():
        name = xlib.get_toa_data_basic_data_name()
    elif genomic_database == xlib.get_toa_data_gymno_01_code():
        name = xlib.get_toa_data_gymno_01_name()
    elif genomic_database == xlib.get_toa_data_dicots_04_code():
        name = xlib.get_toa_data_dicots_04_name()
    elif genomic_database == xlib.get_toa_data_monocots_04_code():
        name = xlib.get_toa_data_monocots_04_name()
    elif genomic_database == xlib.get_toa_data_refseq_plant_code():
        name = xlib.get_toa_data_refseq_plant_name()
    elif genomic_database == xlib.get_toa_data_taxonomy_code():
        name = xlib.get_toa_data_taxonomy_name()
    elif genomic_database == xlib.get_toa_data_nt_code():
        name = xlib.get_toa_data_nt_name()
    elif genomic_database == xlib.get_toa_data_viridiplantae_nucleotide_gi_code(
    ):
        name = xlib.get_toa_data_viridiplantae_nucleotide_gi_name()
    elif genomic_database == xlib.get_toa_data_nr_code():
        name = xlib.get_toa_data_nr_name()
    elif genomic_database == xlib.get_toa_data_viridiplantae_protein_gi_code():
        name = xlib.get_toa_data_viridiplantae_protein_gi_name()
    elif genomic_database == xlib.get_toa_data_gene_code():
        name = xlib.get_toa_data_gene_name()
    elif genomic_database == xlib.get_toa_data_interpro_code():
        name = xlib.get_toa_data_interpro_name()
    elif genomic_database == xlib.get_toa_data_go_code():
        name = xlib.get_toa_data_go_name()

    # print the header
    clib.clear_screen()
    if process_type == xlib.get_toa_type_build_blastplus_db():
        clib.print_headers_with_environment(f'Build {name} for BLAST+')
    elif process_type == xlib.get_toa_type_build_diamond_db():
        clib.print_headers_with_environment(f'Build {name} for DIAMOND')
    elif process_type == xlib.get_toa_type_build_gilist():
        clib.print_headers_with_environment(f'Build {name}')
    elif process_type == xlib.get_toa_type_build_proteome():
        clib.print_headers_with_environment(f'Build {name} proteome')
    elif process_type == xlib.get_toa_type_download_data():
        clib.print_headers_with_environment(
            f'Download {name} functional annotations')
    elif process_type == xlib.get_toa_type_load_data():
        clib.print_headers_with_environment(
            f'Load {name} data in {xlib.get_toa_name()} database')
    print(xlib.get_separator())

    # confirm the process run
    if OK:
        OK = clib.confirm_action(f'The {name} process is going to be run.')

    # run the process
    if OK:
        devstdout = xlib.DevStdOut(xtoa.manage_genomic_database.__name__)
        OK = xtoa.manage_genomic_database(process_type,
                                          genomic_database,
                                          devstdout,
                                          function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #22
0
def form_recreate_pipeline_config_file(pipeline_type):
    '''
    Recreate a pipeline config file.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()

    # set the config file
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        config_file = xtoa.get_nucleotide_pipeline_config_file()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        config_file = xtoa.get_aminoacid_pipeline_config_file()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Recreate config file')
    print(xlib.get_separator())

    # get the transcriptome directory
    transcriptome_dir = ''
    while transcriptome_dir == '':
        transcriptome_dir = input('Enter transcriptome directory: ')
        if not os.path.isdir(transcriptome_dir):
            print(f'***ERROR: The directory {transcriptome_dir} is not valid.')
            transcriptome_dir = ''

    # get the transcriptome file
    transcriptome_file = ''
    while transcriptome_file == '':
        transcriptome_file = input('Enter transcriptome file: ')
        print(f'transcriptome_file: {transcriptome_file}')
        if not os.path.isfile(f'{transcriptome_dir}/{transcriptome_file}'):
            print(f'***ERROR: The file {transcriptome_file} is not valid.')
            transcriptome_file = ''

    # get the database list
    if OK:

        # nucleotide pipelines
        if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
            database_list = cinputs.input_database_list(
                xtoa.get_nucleotide_annotation_database_code_list(), 'nt')

        # amino acid pipelines
        elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
            database_list = cinputs.input_database_list(
                xtoa.get_aminoacid_annotation_database_code_list(), 'nr')

    # recreate the pipeline config file
    if OK:

        # confirm the creation of the config file
        print(xlib.get_separator())
        OK = clib.confirm_action(
            f'The file {config_file} is going to be recreated. The previous files will be lost.'
        )

        # recreate the config file
        if OK:
            (OK, error_list) = xtoa.create_pipeline_config_file(
                pipeline_type, transcriptome_dir, transcriptome_file,
                database_list)
            if OK:
                print('The file is recreated.')
            else:
                for error in error_list:
                    print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #23
0
def form_recreate_annotation_merger_config_file():
    '''
    Recreate the annotation merger config file.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(
        f'{xlib.get_toa_process_merge_annotations_name()} - Recreate config file'
    )

    # get the identification of the first pipeline dataset
    app_list = [
        xlib.get_toa_process_pipeline_nucleotide_code(),
        xlib.get_toa_process_pipeline_aminoacid_code(),
        xlib.get_toa_process_merge_annotations_code()
    ]
    print('First pipeline ...')
    pipeline_dataset_id_1 = cinputs.input_result_dataset_id(
        xlib.get_toa_result_pipeline_dir(), app_list)
    if pipeline_dataset_id_1 == '':
        print('WARNING: There are not any pipeline datasets.')
        OK = False

    # get the identification of the second pipeline dataset
    app_list = [
        xlib.get_toa_process_pipeline_nucleotide_code(),
        xlib.get_toa_process_pipeline_aminoacid_code(),
        xlib.get_toa_process_merge_annotations_code()
    ]
    print('Second pipeline ...')
    pipeline_dataset_id_2 = cinputs.input_result_dataset_id(
        xlib.get_toa_result_pipeline_dir(), app_list)
    if pipeline_dataset_id_2 == '':
        print('WARNING: There are not any pipeline datasets.')
        OK = False
    elif pipeline_dataset_id_1 == pipeline_dataset_id_2:
        print('ERROR: The first pipeline dataset is equal to the second one.')
        OK = False

    # get the merger operation
    if OK:
        merger_operation = cinputs.input_code(
            text='Merger operation',
            code_list=xlib.get_annotation_merger_operation_code_list(),
            default_code=None).upper()

    # recreate the pipeline config file
    if OK:

        # confirm the creation of the config file
        print(xlib.get_separator())
        OK = clib.confirm_action(
            f'The file {xtoa.get_annotation_merger_config_file()} is going to be recreated. The previous files will be lost.'
        )

        # recreate the config file
        if OK:
            (OK, error_list) = xtoa.create_annotation_merger_config_file(
                pipeline_dataset_id_1, pipeline_dataset_id_2, merger_operation)
            if OK:
                print('The file is recreated.')
            else:
                for error in error_list:
                    print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #24
0
def form_create_toa_config_file():
    '''
    Create the TOA config file.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(
        f'{xlib.get_toa_name()} - Recreate config file')
    print(xlib.get_separator())

    # get the HOME directory
    home_dir = str(pathlib.Path.home())

    # set the TOA directory
    toa_dir = os.path.dirname(os.path.abspath(__file__))
    print(f'TOA directory: {toa_dir}')

    # set the Miniconda3 directory
    miniconda3_dir = cinputs.input_directory(
        directory_name='Miniconda3',
        default_directory=f'{home_dir}/{xlib.get_miniconda_dir()}',
        is_created=False)

    # set the database directory
    db_dir = cinputs.input_directory(
        directory_name='database',
        default_directory=f'{home_dir}/{xlib.get_toa_database_dir()}',
        is_created=False)

    # set the result directory
    result_dir = cinputs.input_directory(
        directory_name='result',
        default_directory=f'{home_dir}/{xlib.get_toa_result_dir()}',
        is_created=False)

    # create the TOA config file
    if OK:

        # confirm the creation of the config file
        print(xlib.get_separator())
        OK = clib.confirm_action(
            f'The file {xtoa.get_toa_config_file()} is going to be recreated. The previous files will be lost.'
        )

        # recreate the config file
        if OK:
            (OK,
             error_list) = xtoa.create_toa_config_file(toa_dir, miniconda3_dir,
                                                       db_dir, result_dir)
            if OK:
                print('The file is recreated.')
            else:
                for error in error_list:
                    print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #25
0
def form_install_bioinfo_app(app_code):
    '''
    Install the bioinfo application software in the cluster.
    '''

    # initialize the control variable
    OK = True

    # set the bioinfo application name
    if app_code == xlib.get_blastplus_code():
        app_name = xlib.get_blastplus_name()

    elif app_code == xlib.get_diamond_code():
        app_name = xlib.get_diamond_name()

    elif app_code == xlib.get_entrez_direct_code():
        app_name = xlib.get_entrez_direct_name()

    elif app_code == xlib.get_miniconda3_code():
        app_name = xlib.get_miniconda3_name()

    elif app_code == xlib.get_r_code():
        app_name = xlib.get_r_name()

    elif app_code == xlib.get_transdecoder_code():
        app_name = xlib.get_transdecoder_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{app_name} - Install software')

    # confirm the software installation
    print(xlib.get_separator())
    if app_code == xlib.get_miniconda3_code():
        OK = clib.confirm_action(
            f'{app_name} (Conda infrastructure) is going to be installed. All Conda packages previously installed will be lost and they have to be reinstalled.'
        )
    elif app_code == xlib.get_r_code():
        OK = clib.confirm_action(
            f'{app_name} and analysis packages are going to be installed. The previous version will be lost, if it exists.'
        )
    else:
        OK = clib.confirm_action(
            f'The {app_name} Conda package is going to be installed. The previous version will be lost, if it exists.'
        )

    # install the software
    if OK:

        # install the BLAST+ software
        if app_code == xlib.get_blastplus_code():
            # -- package_code_list = [(xlib.get_blastplus_conda_code(), 'last')]
            package_code_list = [(xlib.get_blastplus_conda_code(), '2.9.0')]
            devstdout = xlib.DevStdOut(
                xbioinfoapp.install_conda_package_list.__name__)
            OK = xbioinfoapp.install_conda_package_list(app_code,
                                                        app_name,
                                                        package_code_list,
                                                        devstdout,
                                                        function=None)

        # install the DIAMOND software
        elif app_code == xlib.get_diamond_code():
            # -- package_code_list = [(xlib.get_diamond_conda_code(), 'last')]
            package_code_list = [(xlib.get_diamond_conda_code(), '0.9.34')]
            devstdout = xlib.DevStdOut(
                xbioinfoapp.install_conda_package_list.__name__)
            OK = xbioinfoapp.install_conda_package_list(app_code,
                                                        app_name,
                                                        package_code_list,
                                                        devstdout,
                                                        function=None)

        # install the Entrez Direct software
        elif app_code == xlib.get_entrez_direct_code():
            package_code_list = [(xlib.get_entrez_direct_conda_code(), 'last')]
            devstdout = xlib.DevStdOut(
                xbioinfoapp.install_conda_package_list.__name__)
            OK = xbioinfoapp.install_conda_package_list(app_code,
                                                        app_name,
                                                        package_code_list,
                                                        devstdout,
                                                        function=None)

        # install the Miniconda3 software
        elif app_code == xlib.get_miniconda3_code():
            devstdout = xlib.DevStdOut(xbioinfoapp.install_miniconda3.__name__)
            OK = xbioinfoapp.install_miniconda3(devstdout, function=None)

        # install R and analysis packages
        elif app_code == xlib.get_r_code():
            devstdout = xlib.DevStdOut(xbioinfoapp.install_r.__name__)
            OK = xbioinfoapp.install_r(devstdout, function=None)

        # install the TransDecoder software
        elif app_code == xlib.get_transdecoder_code():
            package_code_list = [(xlib.get_transdecoder_conda_code(), 'last')]
            devstdout = xlib.DevStdOut(
                xbioinfoapp.install_conda_package_list.__name__)
            OK = xbioinfoapp.install_conda_package_list(app_code,
                                                        app_name,
                                                        package_code_list,
                                                        devstdout,
                                                        function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #26
0
def form_create_ngscloud_config_file(is_menu_call):
    '''
    Create the NGScloud config file corresponding to the environment.
    '''

    # initialize the control variable
    OK = True

    # print the header
    if is_menu_call:
        clib.clear_screen()
        clib.print_headers_with_environment('Configuration - Recreate TransciptomeCloud config file')

    # get current region and zone names
    region_name = xconfiguration.get_current_region_name()
    zone_name = xconfiguration.get_current_zone_name()

    # get basic AWS data and contact e-mail address from NGScloud config file
    (user_id, access_key_id, secret_access_key) = xconfiguration.get_basic_aws_data()
    email = xconfiguration.get_contact_data()

    # confirm or change the AWS data and contact e-mail address
    print(xlib.get_separator())
    user_id = cinputs.input_user_id(user_id)
    access_key_id = cinputs.input_access_key_id(access_key_id)
    secret_access_key = cinputs.input_secret_access_key(secret_access_key)
    email = cinputs.input_email(email)

    # verify the AWS access key identification and the AWS secret access key   
    print(xlib.get_separator())
    print('Verifying the AWS access key identification and the AWS secret access key')
    OK = xec2.verify_aws_credentials(access_key_id, secret_access_key)
    if OK:
        print('The credentials are OK.')
    else:
        print('ERROR: The credentials are wrong. Please review your access key identification and secret access key in the AWS web.')
        if not is_menu_call:
            raise xlib.ProgramException('EXIT')

    # confirm the creation of the NGScloud config file
    if OK:
        if is_menu_call:
            print(xlib.get_separator())
            OK = clib.confirm_action('The {0} config file is going to be created. The previous files will be lost.'.format(xlib.get_project_name()))

    # create the NGScloud config file corresponding to the environment
    if OK:
        print(xlib.get_separator())
        print('The file {0} is being created ...'.format(xconfiguration.get_ngscloud_config_file()))
        (OK, error_list) = xconfiguration.create_ngscloud_config_file(user_id, access_key_id, secret_access_key, email)
        if OK:
            print('The config file is created with default values.')
            print()
            print('You can modify the conection data and contact e-mail address in:')
            print('    "Cloud control" -> "Configuration" -> "Update connection data and contact e-mail"')
            print('The assigned region and zone are {0} and {1}, respectively. You can modify them in:'.format(xconfiguration.get_default_region_name(), xconfiguration.get_default_zone_name()))
            print('    "Cloud control" -> "Configuration" -> "Update region and zone data"')
        else:
            for error in error_list:
                print(error)
            raise xlib.ProgramException('C001')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')