示例#1
0
    def test_change_to_private_multiple_ids(self):

        # adding the accession to yml file
        with open(GEO_ACCESSIONS_PATH, "a") as my_file:
            my_file.write("\n  - %s%s" % (self.geo_ids[0], os.linesep))
            my_file.write("\n  - %s%s" % (self.geo_ids[1], os.linesep))

        sql_stmt = """INSERT INTO experiments (accession, status, is_deleted)
                      VALUES ('%s', 'AE2 Export Complete', 0),
                             ('%s', 'AE2 Export Complete', 0);""" % tuple(
            self.ae_ids)
        execute_insert(sql_stmt, ae_autosubs_db)
        geo.retrieve_study_id_by_acc = mock.Mock(return_value=[{'ID': 12345}])
        geo.ConanPage = mock.Mock()
        geo.retrieve_plantain_connection = mock.Mock(
            return_value=(mock.Mock(), mock.Mock()))
        geo.change_to_private(self.email_body_multiple_series,
                              settings.CONAN_LOGIN_EMAIL)
        geo.wait_execution = mock.Mock()
        # self.assertTrue(geo.ConanPage.unload_experiment.called)
        self.assertTrue(geo.retrieve_plantain_connection.called)
        self.assertEqual(retrieve_experiment_status(self.ae_ids[0]),
                         'Checking failed')
        self.assertEqual(retrieve_experiment_status(self.ae_ids[1]),
                         'Checking failed')
        f = open(GEO_ACCESSIONS_PATH, 'r')
        txt = f.read()
        f.close()
        self.assertNotIn(self.geo_ids[0], txt)
        self.assertNotIn(self.geo_ids[1], txt)
示例#2
0
def wait_for_ae_export(accession):
    status = retrieve_experiment_status(accession)

    while status != 'AE2 Export Complete':
        print status
        time.sleep(30)
        status = retrieve_experiment_status(accession)
        if status in [
                'Export failed', 'Checking failed', 'Abandoned',
                '** CHECKER CRASH **', 'MAGE-TAB export failed',
                'Validation failed'
        ]:
            with LOCK:
                REPORT[accession] += 'Failure: Experiment Reset Failed'
                print colored.red('Failure: Experiment Reset Failed')
            return False
    return True
示例#3
0
def wait_for_ae_export(accession, exp_dir):
    status = retrieve_experiment_status(accession)
    while status != 'AE2 Export Complete':
        # print status
        time.sleep(30)
        status = retrieve_experiment_status(accession)
        if status in [
                'Export failed', 'Checking failed', 'Abandoned',
                '** CHECKER CRASH **', 'MAGE-TAB export failed',
                'Validation failed'
        ]:
            checker_score = retrieve_checker_score(accession)
            if checker_score == 34:
                print 'Checker score 34. Exporting'
                os.subprocess.call('source %s; reset_experiment.pl -e %s\n' %
                                   (BASH_PATH, exp_dir),
                                   shell=True,
                                   env=dict(ENV=BASH_PATH))
                time.sleep(120)
                wait_for_ae_export(accession, exp_dir)
            else:
                print colored.red('Failure: Experiment Reset Failed')
                # exit(1)
    print colored.green('Export Complete')
示例#4
0
def change_to_private(email_body, email_address):
    ids = geo_email_parse(email_body)
    for geo_id, ae_id in ids.items():
        check_url = 'http://ves-hx-69.ebi.ac.uk:8983/solr/analytics/select?q=experimentAccession%3A' + ae_id + '&rows=0&wt=json&indent=true'
        # print check_url
        r = requests.get(check_url)
        # print colored.blue(r.content)
        if r.json()['response']['numFound'] > 0:
            ATLAS_EXPERIMENTS.append(ae_id)
        print 'geo id: ', geo_id, ' AE id: ', ae_id
        status = retrieve_experiment_status(ae_id)
        remove_geo_accession(geo_id)
        if status is None:
            print 'Not Imported'
            continue
        update_experiment_status(ae_id)

        if status not in ([
                'Checking failed', 'GEO import failed', 'Validation failed',
                None
        ]):
            exp = retrieve_study_id_by_acc(ae_id)
            if exp and len(exp) > 0:

                print colored.green('%s found and unloading starting' % ae_id)
                plantain, plantain_ssh = retrieve_plantain_connection()
                plantain.send(
                    'dos2unix /ebi/microarray/home/arrayexpress/ae2_production/data/EXPERIMENT/GEOD/%s*.txt\n'
                    % ae_id)
                wait_execution(plantain)

                # conan = ConanPage(url=settings.CONAN_URL)
                # conan.login(login_email=email_address)
                # conan.unload_experiment(ae_id)
                submit_conan_task(accession=ae_id,
                                  pipeline_name=CONAN_PIPELINES.unload)
                print '%s unload submitted to Conan' % ae_id
            else:
                print colored.blue(
                    '%s not in AE database. It might has been unloaded before.'
                    % ae_id)
        else:
            print colored.yellow('%s status is: %s. No need to unload' %
                                 (ae_id, status))
    if ATLAS_EXPERIMENTS:
        print 'sending email for ', ATLAS_EXPERIMENTS
        body = """Dear %s,
The following GEO experiments are turned into private as requested by GEO, and they are found in Atlas.
=======================================================================================================

%s

This email was sent automatically from the AE Automation Tool.
Thank You!
AE Automation Tool.""" % (settings.ATLAS_CONTACT['name'],
                          '\n'.join(ATLAS_EXPERIMENTS))
        send_email(from_email=settings.AUTOMATION_EMAIL,
                   to_emails=[settings.ATLAS_CONTACT['email']],
                   subject='GEO to Private Notification',
                   body=body)

        print colored.green('EMAIL SENT')