-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from jairideout/convert-finalization
biom convert finalization
- Loading branch information
Showing
5 changed files
with
354 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ---------------------------------------------------------------------------- | ||
# Copyright (c) 2011-2015, The BIOM Format Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
# ---------------------------------------------------------------------------- | ||
|
||
import biom.util | ||
import biom.parse | ||
|
||
|
||
def write_biom_table(table, fmt, filepath): | ||
"""Write table in specified format to filepath""" | ||
|
||
if fmt not in ['hdf5', 'json', 'tsv']: | ||
raise ValueError("Unknown file format") | ||
|
||
if fmt == 'hdf5' and not biom.util.HAVE_H5PY: | ||
fmt = 'json' | ||
|
||
if fmt == 'json': | ||
with open(filepath, 'w') as f: | ||
f.write(table.to_json(biom.parse.generatedby())) | ||
elif fmt == 'tsv': | ||
with open(filepath, 'w') as f: | ||
f.write(table) | ||
f.write('\n') | ||
else: | ||
import h5py | ||
|
||
with h5py.File(filepath, 'w') as f: | ||
table.to_hdf5(f, biom.parse.generatedby()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.