def download_sequence_result(dest_file, group_dir, result, accession, subtree, update_accs, expanded): ts = time.time() temp_file_path = os.path.join(group_dir, str(ts) + 'temp.txt') download_report(utils.SEQUENCE, result, accession, temp_file_path, subtree) header = True with open(temp_file_path) as f: for line in f: if header: header = False continue data_accession = line.strip() write_record = False if result == utils.SEQUENCE_UPDATE_RESULT: update_accs.append(data_accession) write_record = True elif result == utils.SEQUENCE_RELEASE_RESULT: if data_accession not in update_accs: write_record = True if write_record: sequenceGet.write_record(dest_file, data_accession, output_format) dest_file.flush() os.remove(temp_file_path) return update_accs
def download_sequence_set(accession_list, mol_type, assembly_dir, output_format, expanded, quiet): failed_accessions = [] count = 0 sequence_cnt = len(accession_list) divisor = utils.get_divisor(sequence_cnt) if sequence_cnt > 0: if not quiet: print 'fetching {0} sequences: {1}'.format(sequence_cnt, mol_type) target_file_path = os.path.join(assembly_dir, utils.get_filename(mol_type, output_format)) target_file = open(target_file_path, 'w') for accession in accession_list: success = sequenceGet.write_record(target_file, accession, output_format, expanded) if not success: failed_accessions.append(accession) else: count += 1 if count % divisor == 0 and not quiet: print 'downloaded {0} of {1} sequences'.format(count, sequence_cnt) if not quiet: print 'downloaded {0} of {1} sequences'.format(count, sequence_cnt) target_file.close() elif not quiet: print 'no sequences: ' + mol_type if len(failed_accessions) > 0: print 'Failed to fetch following {0}, format {1}'.format(mol_type, output_format) print ','.join(failed_accessions)