Public Vars

Back

line-seq (clj)

(source)

function

(line-seq rdr)
Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.

Examples

PacktPublishing/Clojure-Programming-Cookbook

(require '[clojure.core.reducers :as r])
(use 'clojure.data.xml)
(use '[clojure.java.io :only [writer reader input-stream output-stream]])


(time
 (with-open [in (reader (input-stream "test_0.xml"))]
  (into []
    (r/filter
    (fn[x]
      (= "Friend1"
      (first (:content (parse
       (java.io.StringReader. x))))))
    (line-seq in)))))
PacktPublishing/Clojure-Programming-Cookbook
(use 'clojure.data.xml)
(use '[clojure.java.io :only [writer reader input-stream output-stream]])
(require '[clojure.core.async :as async])

(with-open [in (reader (input-stream "test_0.xml"))]
(doall
 (pmap
 #(async/>!! in-chan %)
  (line-seq in))))
GenomicsAotearoa/Kakapo
(ns figures.core
  (:require [quil.core :as q]
            [clojure.core.matrix :as mat]
            [clojure.core.matrix.stats :as stats]
            [quil.middleware :as m]))

(def chr-lengths
  (into 
   {}
    (with-open [rdr (clojure.java.io/reader "data/chr_lengths.txt")]
    (doall
     (for [line (line-seq rdr)]
       (clojure.string/split line #"\t"))))))

(with-open [rdr (clojure.java.io/reader "data/out.snpden")
            wrt (clojure.java.io/writer "snpden.hist")]
  (doseq [line (rest (line-seq rdr))]
    (let [[chr start count vkb] (clojure.string/split line #"\s+")]
      (.write
       wrt
       (clojure.string/join
        " "
        [chr
         start
         (+ (read-string start) bin-size)
         vkb
         "\n"])))))

(def founders 
  (into
   #{}
   (with-open [rdr (clojure.java.io/reader "data/founders.ped")]
     (doall
      (for [line (rest (line-seq rdr))]
        (let [[_ bird & _] (clojure.string/split line #"\s+")]
          bird))))))

(with-open [rdr (clojure.java.io/reader "data/bcftoolsroh_rgonly")
            wrt (clojure.java.io/writer "founders.roh")]
  (doseq [line (line-seq rdr)]
    (let [[_ who chr start end _ _ score] (clojure.string/split line #"\s+")]
      (when (founders who)
        (.write
         wrt
         (clojure.string/join
          " "
          [chr
           start
           end
           "\n"]))))))

  
(with-open [rdr (clojure.java.io/reader "data/bcftoolsroh_rgonly")]
  (doseq [line (line-seq rdr)]
    (let [[_ who chr start end _ _ score] (clojure.string/split line #"\s+")]
      (with-open [wrt (clojure.java.io/writer (str who ".roh")  :append true)]
        (.write
         wrt
         (clojure.string/join
          " "
          [chr
           start
           end
           "\n"]))))))