Skip to content

Commit

Permalink
Merge pull request #30 from chrovis/feature/improve-fasta-indexer
Browse files Browse the repository at this point in the history
Improve performance of FASTA indexing
  • Loading branch information
alumi authored Mar 3, 2017
2 parents 636fc67 + a393127 commit be6037e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/cljam/fasta_index/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[clojure.tools.logging :as logging]
[me.raynes.fs :as fs]
[cljam.fasta-index.writer :as writer]
[cljam.fasta-index.reader :as reader]))
[cljam.fasta-index.reader :as reader]
[cljam.util :as util]))

;;;; Writing

Expand All @@ -16,10 +17,11 @@

(defn create-index
"Creates a FASTA index file from the sequences."
[rdr f]
(with-open [w ^cljam.fasta_index.writer.FAIWriter (writer f)]
[in-fa out-fai]
(with-open [r (io/reader (util/compressor-input-stream in-fa))
w ^cljam.fasta_index.writer.FAIWriter (writer out-fai)]
(try
(writer/write-index! rdr w)
(writer/write-index! r w)
(catch Exception e (do
(fs/delete (.f w))
(logging/error "Failed to create FASTA index")
Expand Down
9 changes: 3 additions & 6 deletions src/cljam/fasta_index/writer.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns cljam.fasta-index.writer
"Writing features for a FASTA index file."
(:require [clojure.string :as cstr]
[cljam.util :refer [graph?]]
[cljam.util.fasta :refer [header-line? parse-header-line]])
(:import [java.io BufferedWriter RandomAccessFile]))
(:import [java.io BufferedWriter]))

;;;; FAIWriter

Expand All @@ -15,11 +14,9 @@
;;;; Writing

(defn make-indices
[rdr]
(let [r ^RandomAccessFile (.reader rdr)
indices (atom [])
[^java.io.BufferedReader r]
(let [indices (atom [])
current-index (atom nil)]
(.seek r 0)
(loop [l (.readLine r)
pos 0]
(when-not (nil? l)
Expand Down
6 changes: 2 additions & 4 deletions src/cljam/fasta_indexer.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(ns cljam.fasta-indexer
"Alpha - subject to change.
Indexer of FASTA."
(:require [cljam.fasta :as fasta]
[cljam.fasta-index.core :as fai-core]))
(:require [cljam.fasta-index.core :as fai-core]))

(defn create-index
"Create a FASTA index file from the FASTA file."
[in-fa out-fai]
(with-open [r (fasta/reader in-fa)]
(fai-core/create-index r out-fai)))
(fai-core/create-index in-fa out-fai))

0 comments on commit be6037e

Please sign in to comment.