-
Notifications
You must be signed in to change notification settings - Fork 0
/
revc.ls
35 lines (31 loc) · 865 Bytes
/
revc.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Problem
#
# In DNA strings, symbols A and T are complements of each other, as are C and G.
#
# The reverse complement of a DNA string s is the string sc formed by reversing the symbols of s, then taking the complement of each symbol (e.g., the reverse complement of GTCA is TGAC).
#
# Given: A DNA string s of length at most 1000 bp.
#
# Return: The reverse complement sc of s.
#
# Usage lsc revc.ls --file yourfile
argv = require \optimist .argv
fs = require \fs
{chars, join} = require \prelude-ls .Str
{map, reverse} = require \prelude-ls
file = argv.file or throw 'input file required'
reverse-complement = (dna) ->
complements =
A: 'T'
T: 'A'
C: 'G'
G: 'C'
dna
|> chars
|> reverse
|> map (complements.)
|> join ''
fs.read-file file, \utf-8, (err, data) !->
if err
throw err
console.log reverse-complement data