Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read HDF5 biom file #14

Open
chlige opened this issue May 25, 2023 · 1 comment
Open

Unable to read HDF5 biom file #14

chlige opened this issue May 25, 2023 · 1 comment

Comments

@chlige
Copy link

chlige commented May 25, 2023

I am trying to read in a BIOM v2 file (HDF5) using the read_biom function and receive the following error message. I would think the try statements in read_biom would work and properly open the file. Perhaps there is a change in R v4.3.0?

> genus_biom <- read_biom("metagenomics/genus_summary_clean/feature-table.biom")
Warning messages:
1: In strsplit(conditionMessage(e), "\n") :
  unable to translate 'lexical error: invalid char in json text.
                                       <89>HDF  �                      (right here) ------^
' to a wide string
2: In strsplit(conditionMessage(e), "\n") : input string 1 is invalid

I am able to open the file using the following command.

genus_biom <- biom(read_hdf5_biom("genus_summary_clean/feature-table.biom"))

Here are details for my installation of R and biomformat.

> installed.packages()["biomformat", "Version"]
[1] "1.28.0"
> version
               _                                
platform       x86_64-w64-mingw32               
arch           x86_64                           
os             mingw32                          
crt            ucrt                             
system         x86_64, mingw32                  
status                                          
major          4                                
minor          3.0                              
year           2023                             
month          04                               
day            21                               
svn rev        84292                            
language       R                                
version.string R version 4.3.0 (2023-04-21 ucrt)
nickname       Already Tomorrow                 

> read_biom
function (biom_file) 
{
    trash = try(silent = TRUE, expr = {
        x <- fromJSON(biom_file, simplifyDataFrame = FALSE, simplifyMatrix = FALSE)
    })
    if (inherits(trash, "try-error")) {
        trash = try(silent = TRUE, expr = {
            x <- read_hdf5_biom(biom_file)
        })
    }
    if (inherits(trash, "try-error")) {
        stop("Both attempts to read input file:\n", biom_file, 
            "\n", "either as JSON (BIOM-v1) or HDF5 (BIOM-v2).\n", 
            "Check file path, file name, file itself, then try again.")
    }
    return(biom(x))
}
<bytecode: 0x000001a1c3204da8>
<environment: namespace:biomformat>
>

Any help in this matter would be greatly appreciated.

Thanks!

  • George
@svillegasv
Copy link

I was experiencing the same problem. What seemed to work was to convert the .biom from hdf5 to json in the command line using:

biom convert -i input_hdf5_file.biom -o output_json_file.biom --to-json

Later, I was able to load the resulting biom file into R using the read_biom2phyloseq function from the microbiome package and add the metadata as an argument in the same function.

Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants