diff --git a/isatools/isatab/dump/core.py b/isatools/isatab/dump/core.py index 12b94712..1ea8036e 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), 'w', encoding='utf-8') + fp = open(path.join(output_path, i_file_name), 'wb', encoding='utf-8') else: log.debug('output_path=', i_file_name) raise FileNotFoundError("Can't find " + output_path) diff --git a/isatools/isatab/dump/write.py b/isatools/isatab/dump/write.py index d7968ead..0fcf3397 100644 --- a/isatools/isatab/dump/write.py +++ b/isatools/isatab/dump/write.py @@ -221,7 +221,7 @@ def flatten(current_list): DF = DF.replace('', nan) DF = DF.dropna(axis=1, how='all') - with open(path.join(output_dir, study_obj.filename), 'w') as out_fp: + with open(path.join(output_dir, study_obj.filename), 'wb') as out_fp: DF.to_csv( path_or_buf=out_fp, index=False, sep='\t', encoding='utf-8') @@ -477,7 +477,7 @@ def pbar(x): DF = DF.dropna(axis=1, how='all') with open(path.join( - output_dir, assay_obj.filename), 'w') as out_fp: + output_dir, assay_obj.filename), 'wb') as out_fp: DF.to_csv(path_or_buf=out_fp, index=False, sep='\t', encoding='utf-8') diff --git a/isatools/isatab/load/core.py b/isatools/isatab/load/core.py index 715c294f..75a605be 100644 --- a/isatools/isatab/load/core.py +++ b/isatools/isatab/load/core.py @@ -387,7 +387,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, 'w', encoding='utf-8') as fp: + with open(target_file_path, 'wb', encoding='utf-8') 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 0f3d0d6f..cd2aa60f 100644 --- a/isatools/magetab.py +++ b/isatools/magetab.py @@ -362,7 +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])), "w", + else investigation.filename[2:-3])), "wb", encoding='utf-8') as idf_fp: idf_df.to_csv( path_or_buf=idf_fp, diff --git a/isatools/utils.py b/isatools/utils.py index 3fb21247..049c7bcb 100644 --- a/isatools/utils.py +++ b/isatools/utils.py @@ -733,7 +733,7 @@ def replace_factor_with_source_characteristic(self, factor_name): table_file_df.columns = self.clean_isatab_field_names( field_names_modified) - with open(self.path, 'w') as out_fp: + with open(self.path, 'wb') as out_fp: table_file_df.to_csv(path_or_buf=out_fp, index=False, sep='\t', encoding='utf-8') @@ -856,7 +856,7 @@ def replace_factor_with_protocol_parameter_value( with open(os.path.join( os.path.dirname(self.path), '{s_filename}.fix'.format( - s_filename=os.path.basename(self.path))), 'w') as out_fp: + s_filename=os.path.basename(self.path))), 'wb') as out_fp: table_file_df.to_csv(path_or_buf=out_fp, index=False, sep='\t', encoding='utf-8')