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

Why is specifying the extension required when reading files? #152

Closed
ghuls opened this issue Jun 20, 2024 · 2 comments · Fixed by #153
Closed

Why is specifying the extension required when reading files? #152

ghuls opened this issue Jun 20, 2024 · 2 comments · Fixed by #153

Comments

@ghuls
Copy link
Contributor

ghuls commented Jun 20, 2024

Why is specifying the extension required when reading files?

When the wrong one is specified, an empty dataframe is returned.

In [41]: fasta = session.read_fasta_file("Ns.fa", options=bb.FASTAReadOptions()).to_polars()

In [42]: fasta
Out[42]: 
shape: (0, 3)
┌─────┬─────────────┬──────────┐
│ iddescriptionsequence │
│ ---------      │
│ strstrstr      │
╞═════╪═════════════╪══════════╡
└─────┴─────────────┴──────────┘

In [43]: fasta = session.read_fasta_file("Ns.fa", options=bb.FASTAReadOptions(file_extension="fa").to_polars()

In [44]: fasta
Out[44]: 
shape: (1, 3)
┌──────┬─────────────┬─────────────────────────────────┐
│ iddescriptionsequence                        │
│ ---------                             │
│ strstrstr                             │
╞══════╪═════════════╪═════════════════════════════════╡
│ chr1nullNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN… │
└──────┴─────────────┴─────────────────────────────────┘

In [47]: fasta = session.read_fasta_file("/home/luna.kuleuven.be/u0079808/Downloads/Ns.fa", options=bb.FASTAReadOptions(file_extension="fasta",)).to_polars()

In [48]: fasta
Out[48]: 
shape: (0, 3)
┌─────┬─────────────┬──────────┐
│ iddescriptionsequence │
│ ---------      │
│ strstrstr      │
╞═════╪═════════════╪══════════╡
└─────┴─────────────┴──────────┘

It would be nice if the extension and compression would be automatically be detected by checking the extension(s) if not explicitly set.

Also at the moment: fasta_sequence_data_type option can't be set as FastaSequenceDataType is not exposed.

@tshauck
Copy link
Member

tshauck commented Jun 20, 2024

Thanks for bringing this up... it's setup to potentially treat many files as one table (e.g. a directory of FASTAs), which is why if you're not using .fasta it needs to be specified. But you're right that can/should be improved to automatically detect in the single file case.

I'll look into it this afternoon and try to resolve at least for FASTA files (along w/ compression).

@tshauck
Copy link
Member

tshauck commented Jun 21, 2024

This should work now[1] for FASTA and FASTQ, except for the last one example in that if the user explicitly passes an option for which extension to use biobear will respect that. I've made #154 to continue to make file path options inferable ordered in rough priority. If there's a particular one you're interested in, happy to do that first. Thanks again for raising this!

[1]: on main, will release shortly

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

Successfully merging a pull request may close this issue.

2 participants