示例#1
0
def download_sequence_group(accession, format, study_dir):
    print('Downloading sequences')
    update_accs = []
    dest_file = os.path.join(study_dir, utils.get_filename(accession + '_sequences', format))
    #sequence update
    temp_file = os.path.join(study_dir, 'temp.txt')
    download_report(utils.SEQUENCE, utils.SEQUENCE_UPDATE_RESULT, accession, temp_file)
    f = open(temp_file)
    header = True
    for line in f:
        if header:
            header = False
            continue
        data_accession = line.strip()
        update_accs.append(data_accession)
        sequenceGet.append_record(dest_file, data_accession, format)
    f.close()
    os.remove(temp_file)
    #sequence release
    temp_file = os.path.join(study_dir, 'temp.txt')
    download_report(utils.SEQUENCE, utils.SEQUENCE_RELEASE_RESULT, accession, temp_file)
    f = open(temp_file)
    header = True
    for line in f:
        if header:
            header = False
            continue
        data_accession = line.strip()
        if data_accession not in update_accs:
            sequenceGet.append_record(dest_file, data_accession, format)
    f.close()
    os.remove(temp_file)
示例#2
0
def download_sequence_set(accession_list, mol_type, assembly_dir, format,
                          quiet):
    failed_accessions = []
    if len(accession_list) > 0:
        if not quiet:
            print('fetching sequences: ' + mol_type)
        target_file = os.path.join(assembly_dir,
                                   utils.get_filename(mol_type, format))
        for accession in accession_list:
            success = sequenceGet.append_record(target_file, accession, format)
            if not success:
                failed_accessions.append(accession)
    elif not quiet:
        print('no sequences: ' + mol_type)
    if len(failed_accessions) > 0:
        print('Failed to fetch following ' + mol_type + ', format ' + format)
        print(failed_accessions.join(','))