diff --git a/isatools/isatab/dump/core.py b/isatools/isatab/dump/core.py index 1ea8036e..9cb575a8 100644 --- a/isatools/isatab/dump/core.py +++ b/isatools/isatab/dump/core.py @@ -41,7 +41,7 @@ def dump(isa_obj, output_path, raise NameError('Investigation file must match pattern i_*.txt, got {}'.format(i_file_name)) if path.exists(output_path): - fp = open(path.join(output_path, i_file_name), 'wb', encoding='utf-8') + fp = open(path.join(output_path, i_file_name), 'wb') else: log.debug('output_path=', i_file_name) raise FileNotFoundError("Can't find " + output_path) @@ -55,7 +55,7 @@ def dump(isa_obj, output_path, # Write ONTOLOGY SOURCE REFERENCE section ontology_source_references_df = _build_ontology_reference_section(investigation.ontology_source_references) - fp.write('ONTOLOGY SOURCE REFERENCE\n') + fp.write(b'ONTOLOGY SOURCE REFERENCE\n') # Need to set index_label as top left cell ontology_source_references_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Term Source Name') @@ -80,7 +80,7 @@ def dump(isa_obj, output_path, inv_df_rows.append(comment.value) investigation_df.loc[0] = inv_df_rows investigation_df = investigation_df.set_index('Investigation Identifier').T - fp.write('INVESTIGATION\n') + fp.write(b'INVESTIGATION\n') investigation_df.to_csv( path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Investigation Identifier') @@ -90,14 +90,14 @@ def dump(isa_obj, output_path, prefix='Investigation', publications=investigation.publications ) - fp.write('INVESTIGATION PUBLICATIONS\n') + fp.write(b'INVESTIGATION PUBLICATIONS\n') investigation_publications_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Investigation PubMed ID') # Write INVESTIGATION CONTACTS section investigation_contacts_df = _build_contacts_section_df( contacts=investigation.contacts) - fp.write('INVESTIGATION CONTACTS\n') + fp.write(b'INVESTIGATION CONTACTS\n') investigation_contacts_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Investigation Person Last Name') @@ -127,40 +127,40 @@ def dump(isa_obj, output_path, study_df_row.append(comment.value) study_df.loc[0] = study_df_row study_df = study_df.set_index('Study Identifier').T - fp.write('STUDY\n') + fp.write(b'STUDY\n') study_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Identifier') study_design_descriptors_df = _build_design_descriptors_section(design_descriptors=study.design_descriptors) - fp.write('STUDY DESIGN DESCRIPTORS\n') + fp.write(b'STUDY DESIGN DESCRIPTORS\n') study_design_descriptors_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Design Type') # Write STUDY PUBLICATIONS section study_publications_df = _build_publications_section_df(prefix='Study', publications=study.publications) - fp.write('STUDY PUBLICATIONS\n') + fp.write(b'STUDY PUBLICATIONS\n') study_publications_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study PubMed ID') # Write STUDY FACTORS section study_factors_df = _build_factors_section_df(factors=study.factors) - fp.write('STUDY FACTORS\n') + fp.write(b'STUDY FACTORS\n') study_factors_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Factor Name') study_assays_df = _build_assays_section_df(assays=study.assays) - fp.write('STUDY ASSAYS\n') + fp.write(b'STUDY ASSAYS\n') study_assays_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Assay File Name') # Write STUDY PROTOCOLS section study_protocols_df = _build_protocols_section_df(protocols=study.protocols) - fp.write('STUDY PROTOCOLS\n') + fp.write(b'STUDY PROTOCOLS\n') study_protocols_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Protocol Name') # Write STUDY CONTACTS section study_contacts_df = _build_contacts_section_df( prefix='Study', contacts=study.contacts) - fp.write('STUDY CONTACTS\n') + fp.write(b'STUDY CONTACTS\n') study_contacts_df.to_csv(path_or_buf=fp, mode='a', sep='\t', encoding='utf-8', index_label='Study Person Last Name') diff --git a/isatools/isatab/load/core.py b/isatools/isatab/load/core.py index 28525d42..26400de1 100644 --- a/isatools/isatab/load/core.py +++ b/isatools/isatab/load/core.py @@ -390,7 +390,7 @@ def merge_study_with_assay_tables(study_file_path, assay_file_path, target_file_ log.info("Merging DataFrames...") merged_DF = merge(study_DF, assay_DF, on='Sample Name') log.info("Writing merged DataFrame to file %s", target_file_path) - with open(target_file_path, 'wb', encoding='utf-8') as fp: + with open(target_file_path, 'wb') as fp: merged_DF.to_csv(fp, sep='\t', index=False, header=study_DF.isatab_header + assay_DF.isatab_header[1:]) diff --git a/isatools/magetab.py b/isatools/magetab.py index cd2aa60f..3b0a1d86 100644 --- a/isatools/magetab.py +++ b/isatools/magetab.py @@ -362,8 +362,7 @@ def write_idf_file(inv_obj, output_path): idf_df = idf_df.replace('', np.nan) with open(os.path.join(output_path, "{}.idf.txt".format( investigation.identifier if investigation.identifier != "" - else investigation.filename[2:-3])), "wb", - encoding='utf-8') as idf_fp: + else investigation.filename[2:-3])), "wb") as idf_fp: idf_df.to_csv( path_or_buf=idf_fp, index=True,