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

Add support for random reading of bgzipped FASTA files. #174

Merged
merged 6 commits into from
Aug 20, 2019

Conversation

alumi
Copy link
Member

@alumi alumi commented Aug 8, 2019

Summary

This PR adds support for random reading of bgzip-compressed FASTA files.
cljam.io.sequence/read-sequence now works on fa.gz files if fa.gz.fai and fa.gz.gzi exist.
.gzi is a file format for storing BGZF indices as a list of pairs (compressed offset, uncompressed offset).
Note that this implementation does not support indexing FASTA without .gzi file.

Tests

  • lein check
  • lein test :all
  • lein cloverage

@alumi alumi requested a review from a team August 8, 2019 04:17
@ghost ghost requested review from athos and yito88 and removed request for a team August 8, 2019 04:17
@codecov
Copy link

codecov bot commented Aug 8, 2019

Codecov Report

Merging #174 into master will decrease coverage by 0.03%.
The diff coverage is 86.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #174      +/-   ##
==========================================
- Coverage    86.9%   86.86%   -0.04%     
==========================================
  Files          73       74       +1     
  Lines        5683     5750      +67     
  Branches      482      492      +10     
==========================================
+ Hits         4939     4995      +56     
- Misses        262      263       +1     
- Partials      482      492      +10
Impacted Files Coverage Δ
src/cljam/io/fasta/core.clj 95.77% <100%> (+0.61%) ⬆️
src/cljam/io/util/bgzf.clj 77.77% <56.52%> (-8.59%) ⬇️
src/cljam/io/fasta/reader.clj 90.41% <90%> (-0.1%) ⬇️
src/cljam/io/util/bgzf/gzi.clj 93.33% <93.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d78b63c...29be531. Read the comment docs.

@alumi alumi assigned athos and yito88 Aug 9, 2019
Copy link
Contributor

@yito88 yito88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Member

@athos athos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the enhancement!
Functionally, the changes LGTM👍 Just added a trivial comment on a typo.

(bit-and diff 0xffff))))

(defn comp->uncomp
"Returns a uncompressed offset for a given virtual file offset"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Returns a uncompressed offset for a given virtual file offset"
"Returns an uncompressed offset for a given virtual file offset."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in c08fa83.

(:import [java.io RandomAccessFile InputStream]
[cljam.io.fasta-index.core :as fasta-index]
[cljam.io.util.bgzf.gzi :as gzi]
[cljam.io.util.bgzf :as bgzf])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cljam.io.util.bgzf is never used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks 🙏

@alumi alumi requested review from athos and r6eve August 20, 2019 01:06
@alumi alumi assigned r6eve and unassigned athos Aug 20, 2019
(let [off (unsigned-bit-shift-right compressed-offset 16)
[uncompressed] (->> gzi
rseq
(filter (fn [[u c]] (= (long c) off)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@r6eve r6eve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@r6eve r6eve merged commit 036fa84 into master Aug 20, 2019
@r6eve r6eve deleted the feature/bgzip-fasta-reader branch August 20, 2019 05:47
@alumi
Copy link
Member Author

alumi commented Aug 20, 2019

@r6eve @yito88 @athos Thank you for reviewing!

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

Successfully merging this pull request may close these issues.

4 participants