-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support encoding non-detached mate records
- Loading branch information
Showing
4 changed files
with
160 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns cljam.io.cram.encode.mate-records | ||
(:require [cljam.io.sam.util.flag :as util.flag]) | ||
(:import [java.util HashMap])) | ||
|
||
(defprotocol IMateResolver | ||
(resolve-mate! [this i record])) | ||
|
||
(defn make-mate-resolver | ||
"Creates a new mate resolver." | ||
[] | ||
(let [record-indices (HashMap.)] | ||
(reify IMateResolver | ||
(resolve-mate! [_ i {:keys [flag qname]}] | ||
(when (= (bit-and (long flag) | ||
(util.flag/encoded #{:multiple :secondary :supplementary})) | ||
(util.flag/encoded #{:multiple})) | ||
(if-let [mate-index (.get record-indices qname)] | ||
(do (.remove record-indices mate-index) | ||
mate-index) | ||
(.put record-indices qname i))))))) |
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,27 @@ | ||
(ns cljam.io.cram.encode.mate-records-test | ||
(:require [cljam.io.cram.encode.mate-records :as mate] | ||
[cljam.io.sam.util.flag :as flag] | ||
[clojure.test :refer [deftest is]])) | ||
|
||
(deftest make-mate-resolver-test | ||
(let [mate-resolver (mate/make-mate-resolver)] | ||
(is (nil? (mate/resolve-mate! mate-resolver 1 | ||
{:qname "q001" | ||
:flag (flag/encoded #{:properly-aligned :multiple | ||
:first :next-reversed})}))) | ||
(is (nil? (mate/resolve-mate! mate-resolver 2 | ||
{:qname "q002" | ||
:flag (flag/encoded #{:multiple :first :next-unmapped})}))) | ||
(is (nil? (mate/resolve-mate! mate-resolver 3 | ||
{:qname "q003" | ||
:flag (flag/encoded #{:multiple :first :supplementary})}))) | ||
(is (= 2 (mate/resolve-mate! mate-resolver 5 | ||
{:qname "q002" | ||
:flag (flag/encoded #{:multiple :last :unmapped})}))) | ||
(is (= 1 (mate/resolve-mate! mate-resolver 4 | ||
{:qname "q001" | ||
:flag (flag/encoded #{:properly-aligned :multiple | ||
:last :reversed})}))) | ||
(is (nil? (mate/resolve-mate! mate-resolver 6 | ||
{:qname "q003" | ||
:flag (flag/encoded #{:multiple :first :reversed})}))))) |
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