Skip to content

Instantly share code, notes, and snippets.

View agdiaz's full-sized avatar
👋
Hello world!

Adrián Diaz agdiaz

👋
Hello world!
View GitHub Profile
@agdiaz
agdiaz / dna_text.rb
Created February 6, 2018 02:31
Converts a sequence of nucleotides (in char format) in an ASCII text
#!/usr/bin/env ruby
# Don't forget to do: chmod +x ./dna_text.rb
print 'INPUT sequence: '
sequence = gets.strip.scan(/\w/)
binary = sequence.map do |n|
case n
when 'A' then '00'
when 'C' then '01'
@agdiaz
agdiaz / text_dna.rb
Created February 6, 2018 02:30
Converts an ASCII text into a sequence of nucleotids
#!/usr/bin/env ruby
# Don't forget to do: chmod +x ./text_dna.rb
print 'INPUT text: '
text = gets.strip
binary = text.unpack('B*')
bits = binary[0].scan(/\w/)
sequence_bits = bits.each_slice(2).map do |a, b|
@agdiaz
agdiaz / bit_dna.c
Last active February 6, 2018 02:03
Reads a binary file and write a new one with the sequence as a string
// Compile: gcc -o bit2dna bit_dna.c
// Libraries
#include <stdio.h>
#include <string.h>
// Declare constants
#define A 0 // 00
#define C 1 // 01
#define G 2 // 10
#define T 3 // 11
@agdiaz
agdiaz / dna_bit.c
Last active February 6, 2018 14:34
Converts a DNA sequence in a binary file
// Compile: gcc -o dna2bit dna_bit.c
// Libraries
#include <stdio.h>
#include <string.h>
// Declare constants
#define A 0 // 00
#define C 1 // 01
#define G 2 // 10