require 'aqueductron'The objective is to count the nucleotides (A,C,T,G) in a string.
We could construct the pipe ahead of time, with four branches.
require 'aqueductron'cn = Duct.new. expand(->(s) {s.each_char}). through(->(c) {c.upcase}). split( {
:A => Duct.new.keeping(->(actg) { actg == "A"}).count,
:T => Duct.new.keeping(->(actg) { actg == "T"}).count,
:C => Duct.new.keeping(->(actg) { actg == "C"}).count,
:G => Duct.new.keeping(->(actg) { actg == "A"}).count })Now we have a static pipe. To use it, we - send in one string
resultingCounts = cn.drip("ACCTAACG"). eofresultingCounts.value(:A)=> 3
resultingCounts.value(:C)=> 1
resultingCounts.value(:T)=> 3
resultingCounts.value(:G)what if we get some other letter? You're bound to see an N (for no data) in any real sequence string.
The more interesting implementation counts whatever the heck it gets.
puts "This part is more interesting"countChars = Duct.new. expand(->(s) {s.each_char}). partition(->(a) {a.upcase}, ->(a) { Duct.new.count })Now, we can pass in strings of whatever, and it'll count what it sees.
countChars.drip("AACTGTNNA").eof---
A => 3
---
---
C => 1
---
---
T => 2
---
---
G => 1
---
---
N => 2
---