Skip to content

Commit

Permalink
Fixed errors
Browse files Browse the repository at this point in the history
Fixed parts of the code that needed to be changed to work with bytes. There are no more errors in testing.
  • Loading branch information
ptth222 committed Mar 8, 2024
1 parent 3d2f060 commit 0f7b791
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
24 changes: 12 additions & 12 deletions isatools/isatab/dump/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')

Expand Down Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion isatools/isatab/load/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:])


Expand Down
3 changes: 1 addition & 2 deletions isatools/magetab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f7b791

Please sign in to comment.