-
-
Save rubiesonthesky/94b72f539d9ea1dfd547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
debug("Sequence cleaner started") | |
Shoes.setup do | |
gem 'bio' | |
end | |
require 'bio' | |
Shoes.app :width => 1000, :margin => 20 do | |
# initializing global variables | |
@sequenceCount = 0 | |
@scfvCount = 0 | |
@count = 0 | |
@gene = 0 | |
@gene2 = 0 | |
flow do # title | |
title "Sequence cleaner", :stroke => orange | |
image "DNA.png", :width => 100, :right => 10, :top => 10 | |
end | |
flow do # open, save | |
button "New project" do | |
debug("New project button") | |
if @sequence.text != "" | |
if confirm("Are you sure you want to start over?") | |
@sequenceCount = 0 | |
@statics.text = "" | |
@message.text = "Start selecting sequences" | |
@count = 0 | |
@sequence.text = "" | |
@gene = 0 | |
@gene2 = 0 | |
end | |
else | |
@message.text = "Start selecting sequence folder" | |
end | |
end | |
button "Open sequence folder" do | |
debug("Open sequence folder button") | |
readFolder = ask_open_file | |
combinedText = "" | |
f = "" | |
seqHash = Hash.new{name, dna, scfv} | |
Dir.glob(readFolder) do |file| | |
combinedText = combinedText + File.read(file) | |
seq = File.read(file) | |
@sequenceCount =+ 1 | |
f = Bio::FastaFormat.new(seq) | |
#s = Bio::Sequence::NA.new(f.naseq) | |
seqHash.name = {f.definition, f.seq} | |
end | |
@statics.text = @statics.text + "Sequences: " + @sequenceCount.to_s | |
@message.text = "Sequences loaded." | |
end | |
button "Save as text file" do | |
file = ask_save_file | |
File.open(file+".txt", "w+") do |f| | |
f.write @sequence.text | |
end | |
@message.text = "Sequences saved" | |
end | |
end | |
flow do # sequence manipulation | |
button "Clean up" do | |
if @count == 0 | |
dirtyText = @sequence.text | |
dirtyText2 = dirtyText.gsub(/-/, "") | |
dirtyText3 = dirtyText2.gsub(/\s/, "") | |
cleanText = dirtyText3.gsub(/>/, "\n") | |
@sequence.text = cleanText | |
@message.text = "Sequences cleaned" | |
@count = 1 | |
else | |
@message.text = "Already cleaned!" | |
end | |
end | |
button "How many ScFvs?" do # ei toimi | |
@message.text = "Counting ScFvs..." | |
#howMany = @sequence.count('/(ATTGTGCTG)(\w*?)(CCGTGAGCTCG)/') | |
howManyStart = @sequence.text.count('/ATTGTGCTG') | |
howManyEnd = @sequence.text.count('/CCGTGAGCTCG/') | |
debug(howManyStart) | |
debug(howManyEnd) | |
@scfvCount = @sequence.text.count('/(ATTGTGCTG)(\w*?)(CCGTGAGCTCG)/') | |
debug(@scfvCount) | |
@message.text = "ScFv's counted" | |
end | |
button "Find genes" do | |
if @gene == 0 | |
raw = @sequence.text | |
#genes = raw.gsub(/ATTGTGCTG(.*?)CCGTGAGCTCG/, "") | |
genes = raw.gsub(/.ab1.*?ATTGTGCTG/, " ATTGTGCTG") | |
@sequence.text = genes | |
@message.text = "Genes found part I" | |
@gene = 1 | |
else | |
@message.text = "Already done" | |
end | |
end | |
button "Find genes2" do | |
if @gene2 == 0 | |
raw2 = @sequence.text | |
genes2 = raw2.gsub(/CCGTGAGCTCG.*?$/, "CCGTGAGCTCG") | |
@sequence.text = genes2 | |
@message.text ="Genes found part II" | |
@gene2 = 1 | |
else | |
@message.text = "Already done!" | |
end | |
end | |
button "Translate" do | |
trans = Bio::Sequence::NA.new(@sequence.text) | |
@sequence.text = trans.translate | |
end | |
end | |
stack do # show messages | |
@message = para :stroke => red | |
@message.text = "Start selecting sequences" | |
@statics = para | |
@statics.text = "" | |
end | |
stack do #statistics | |
para "Sequence count: " + @sequenceCount.to_s + "ScFvs count: " + @scfvCount.to_s | |
end | |
stack :width => 100 do # sequences | |
@bio = para | |
@translate = para | |
@sequence = para | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment