Skip to content

Instantly share code, notes, and snippets.

@soh-i
Last active September 23, 2020 12:59
Show Gist options
  • Save soh-i/87f005a425a0d04c4cf308ac52048be3 to your computer and use it in GitHub Desktop.
Save soh-i/87f005a425a0d04c4cf308ac52048be3 to your computer and use it in GitHub Desktop.
Fast Local Alignment in Julia
module main
using BioSequences
using BioAlignments
using BenchmarkTools
struct AlignmentResults
align::BioAlignments.PairwiseAlignmentResult
name::String
end
function generate_fasta_db(fasta_path::String)::Dict{String, BioSequences.BioSequence}
db = Dict{String, BioSequences.BioSequence}()
reader = BioSequences.FASTA.Reader(open(fasta_path, "r"))
for record in reader
sequence = BioSequences.FASTA.sequence(record)
id::String = BioSequences.FASTA.identifier(record)
db[id] = sequence
end
close(reader)
return db
end
const PS1 = BioSequences.dna"TAACTTACGGAGTCGCTCTACG"
function sw_alignments()
fasta = "sampled_50000.fasta"
fasta_db = generate_fasta_db(fasta)
problem = BioAlignments.LocalAlignment() #smith-waterman local alignment
scoremodel = BioAlignments.AffineGapScoreModel(match=5, mismatch=-4, gap_open=-4, gap_extend=-1)
global i = 1
for (name, seq) in fasta_db
align = pairalign(problem, seq, PS1, scoremodel)
i += 1
end
@show("Processed $i alignments in total")
end
for i in 1:10
@time main.sw_alignments()
end
end
@soh-i
Copy link
Author

soh-i commented Sep 23, 2020

julia> include("sw_alignment.jl")
WARNING: replacing module main.
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.071445 seconds (942.09 k allocations: 381.156 MiB, 6.12% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.330422 seconds (942.09 k allocations: 381.156 MiB, 22.41% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.086053 seconds (942.09 k allocations: 381.156 MiB, 5.71% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.080862 seconds (942.09 k allocations: 381.156 MiB, 6.04% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.064474 seconds (942.09 k allocations: 381.156 MiB, 5.38% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.326917 seconds (942.09 k allocations: 381.156 MiB, 22.05% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.098568 seconds (942.09 k allocations: 381.156 MiB, 6.33% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.068314 seconds (942.09 k allocations: 381.156 MiB, 5.94% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.078697 seconds (942.09 k allocations: 381.156 MiB, 5.26% gc time)
"Processed $(i) alignments in total" = "Processed 55275 alignments in total"
  1.637824 seconds (942.09 k allocations: 381.156 MiB, 29.16% gc time)
Main.main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment