Skip to content

Instantly share code, notes, and snippets.

@audy
Last active February 7, 2023 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save audy/5390180 to your computer and use it in GitHub Desktop.
Save audy/5390180 to your computer and use it in GitHub Desktop.
Demultiplex Ion Torrent Reads

Demultiplex IonTorrent

(c) 2013 Austin G. Davis-Richardson, LICENSE: MITv3

Requirements

  • Ruby 1.9.3 or better (check with ruby --version)
  • DNA (sudo gem install dna)

Instructions

./demultiplex_iontorrent.rb reads.fastq

Creates a directory on the desktop called split_by_barcode.

1 CTAAGGTAA
2 TAAGGAGAA
3 AAGAGGATT
4 TACCAAGAT
5 CAGAAGGAA
6 CTGCAAGTT
7 TTCGTGATT
8 TTCCGATAA
9 TGAGCGGAA
10 CTGACCGAA
11 TCCTCGAAT
12 TAGGTGGTT
13 TCTAACGGA
14 TTGGAGTGT
15 TCTAGAGGT
16 TCTGGATGA
#!/usr/bin/env ruby
require 'dna'
# Usage
# 1 - install dna by typing suda gem install dna
# 2 - you need a file called barcodes.csv
# that contains the barcode,sample_id on each line
# 3 - ruby split.rb reads.fastq
# this will output files in split_by_barcode/
MIN_READ_LEN = 300
BARCODES = 'barcodes.csv'
OUT_DIR = File.expand_path('~/Desktop/split_by_barcode/')
`mkdir -p #{OUT_DIR}`
barcodes = Hash.new
File.open BARCODES do |handle|
handle.each do |line|
line = line.strip.split(',')
id, barcode = line
barcodes[barcode] = File.open(File.join(OUT_DIR, "sample_#{id}.fastq"), 'w')
end
end
File.open ARGV[0] do |handle|
records = Dna.new(handle)
records.each do |record|
bc = record.sequence[0..8]
handle = barcodes[bc]
next if handle.nil?
unless record.sequence.size < MIN_READ_LEN
# remove barcode from sequence
record.sequence = record.sequence[7..-1]
record.quality = record.quality[7..-1]
handle.puts record
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment