aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xSelectiveWholeGenomeAmplificationGUI223
1 files changed, 223 insertions, 0 deletions
diff --git a/SelectiveWholeGenomeAmplificationGUI b/SelectiveWholeGenomeAmplificationGUI
new file mode 100755
index 0000000..40d3ffc
--- /dev/null
+++ b/SelectiveWholeGenomeAmplificationGUI
@@ -0,0 +1,223 @@
+#!/usr/bin/env python2.7
+import os.path
+
+def run_generic(cmd):
+ '''
+ get the length of a fasta file by piping it through several unix
+ programs.
+
+ 1) remove headers by grepping for any ">" at the start of a line
+ 2) delete all occurances of a new line, to join sequences together
+ 3) sum the number of characters.
+ '''
+ from subprocess import Popen
+ from subprocess import PIPE
+
+ fh = Popen(cmd, stdout=PIPE, shell=True, executable='/bin/bash')
+
+ return fh.stdout.readlines()
+
+foreground = ""
+background = ""
+
+yes_no = {'Y': True, 'y': True,'n': False, 'N': False, 'yes': True, 'no': False, '': '' }
+
+variables = {}
+
+questions = [
+ { 'q' : "what is your foreground fasta file?",
+ 'def': '',
+ 'tab': 'file',
+ 'v': 'foreground',
+ 't': 'file'},
+
+ { 'q' : "what is your background fasta file?",
+ 'def': '',
+ 'v': 'background',
+ 'tab': 'file',
+ 't': 'file'},
+
+ { 'q' : "Where would you like your output directory to be?",
+ 'def': 'current directory/foreground_background/',
+ 'v': 'output_directory',
+ 'tab': 'file',
+ 't': 'dir'},
+
+ {'q': "Where would you like to temporary files to be stored?",
+ 'def': '$output_directory/.tmp',
+ 'v': "temp_directory",
+ 'tab': 'file',
+ 't': 'dir'},
+
+ {'q': "Where would you like to count files to be stored?",
+ 'def': '$output_directory/.tmp',
+ 'v': "counts_directory",
+ 'tab': 'file',
+ 't': 'dir' },
+
+ { 'q': 'maximum mer size you would like to pick?',
+ 'def': '12',
+ 'v': 'max_mer_range',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'minimum mer size you would like to pick?',
+ 'def': '6',
+ 'v': 'min_mer_range',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'eliminate mers that appear on average less than this ?',
+ 'def': '50000',
+ 'v': 'min_foreground_binding_average',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'maximum size of mer combinations you want to search and select?',
+ 'def': '15',
+ 'v': 'max_select',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'maximum number of mers you want to use as possible primers?',
+ 'def': '35',
+ 'v': 'max_check',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ {'q': 'enter mers to ignore? (space seperated)',
+ 'def': "None",
+ 'v': 'ignore_mers',
+ 'tab': 'filter',
+ 't': 'str'},
+
+ {'q': 'enter files to ignore all mers from? (space seperated)',
+ 'def': "None",
+ 'v': 'ignore_all_mers_from_files',
+ 'tab': 'filter',
+ 't': 'file',
+ 'opt': 'multiple'},
+
+ { 'q': 'maximum distance between mers in the final selection?',
+ 'def': "5000",
+ 'v': 'max_mer_distance',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'minimum background ratio?',
+ 'def': "None",
+ 'v': 'min_bg_ratio',
+ 'tab': 'filter',
+ 't': 'int'},
+
+ { 'q': 'maximum melting temperature for mers?', 'def': '30c', 'v': 'max_melting_temp', 't': 'float', 'tab':'melting'},
+ { 'q': 'minimum melting temperature for mers?', 'def': '0c', 'v': 'min_melting_temp', 't': 'float' , 'tab':'melting'},
+ { 'q': 'DNA Concentration (nM)?', 'def': '5000nM', 'v': 'dna_con', 't':'float', 'tab':'melting' },
+ { 'q': 'Salt Concentration (mM) ?', 'def': '10mM', 'v': 'na_con', 't':'float', 'tab':'melting' },
+ { 'q': 'Magnesium Concentration (mM)?', 'def': '20mM', 'v': 'mg_con', 't':'float', 'tab':'melting'},
+ { 'q': 'dNTPs Concentration (mM) ?', 'def': '10mM', 'v': 'dntps_con', 't':'float', 'tab':'melting'},
+ { 'q': 'maximum number of consecutively binding mers in hetero and homodimers?', 'def': '4', 'v': 'max_consecutive_binding', 't':'int', 'tab':'filter' },
+ { 'q': 'what extra weight do you want for highgly binding primers? (0-1)', 'def': '0', 'v': 'fg_weight', 't':'float', 'tab':'scoring'},
+ { 'q': 'what extra weight do you want for sets with a higher number of primers? (0-1)', 'def': '0', 'v': 'primer_weight', 't':'float', 'tab':'scoring'},
+ { 'q': 'how many scored sets would you like in the top_scored_sets output file?', 'def':'10000', 'v': 'output_top_nb', 't':'int', 'tab':'scoring'},
+ { 'q': 'custom scoring function (see README.md for details) ', 'def':'', 'v': 'score_func', 't':'str', 'tab':'scoring'}
+]
+
+def bool_ask(ask_string, default):
+ ans = ""
+
+ ask_string = ask_string + " (Y/N/Default=" + str(default) + ")" + ": "
+
+ ans = raw_input(ask_string)
+ while ans not in yes_no.keys():
+ ans = raw_input(ask_string)
+ if ans is '':
+ ans = default
+
+ return yes_no[ans]
+
+def ask(question_dict):
+ question = question_dict['q']
+ default = question_dict['def']
+
+ ask_string = question + " (Default=" + str(default) + ")" + ": "
+
+ ans = raw_input(ask_string)
+ return ans
+
+def variables_to_string(variables):
+ ret = ""
+ for variable in variables:
+ if variables[variable] is not '':
+ ret = ret + variable + "=\"" + variables[variable] + "\" "
+
+ ret = ret + "foreground=\"" + foreground + "\" "
+ ret = ret + "background=\"" + background + "\" "
+ return ret
+
+def run(variables_as_a_string):
+
+ import subprocess
+ try:
+ subprocess.check_call(variables_as_a_string + " " + "SelectiveWholeGenomeAmplification " + foreground + " " + background, shell=True)
+ except:
+ pass
+
+def yad_ask_all_questions(questions):
+ import random
+
+ key = random.randint(0,100000)
+
+ cmd_d = {
+ 'file': "yad --form --plug=" + str(key) + " --tabnum=1 ",
+ 'filter': "yad --form --plug=" + str(key) + " --tabnum=2 ",
+ 'melting': "yad --form --plug=" + str(key) + " --tabnum=3 ",
+ 'scoring': "yad --form --plug=" + str(key) + " --tabnum=4 "
+ }
+ container = 'yad --notebook --key=' + str(key) + ' --tab="Files" --tab="filter" --tab="Melting Temperature" --tab="Scoring" --title="Selective Genome Amplification Options" '
+ shmcleanup = "ipcrm -M `printf 0x%0.8x "+ str(key) + "` 2> /dev/null"
+
+ for q in questions:
+ qstr = '--field="' + q['q'] + " (" + q['v'] + ')":LBL '
+
+ # if it's a directory
+ if q['t'] is 'dir':
+ qstr += "--field=" + q['v'] + ":DIR"
+
+ # if it's a file
+ elif q['t'] is 'file':
+ if 'opt' in q:
+ if q['opt'] is 'multiple':
+ qstr += "--field" + q['v'] + ":TXT"
+ else:
+ qstr += "--field=" + q['v'] + ":FL"
+
+ elif q['t'] is 'bool':
+ qstr += "--field" + q['v'] + ":CHK"
+
+ elif q['t'] is 'int':
+ qstr += "--field=" + q['v'] + ":NUM"
+
+ elif q['t'] is 'float':
+ qstr += "--field=" + q['v'] + ":NUM"
+ elif q['t'] is 'txt':
+ qstr += "--field=" + q['v'] + ":TXT"
+
+ elif q['t'] is 'str':
+ qstr += "--field=" + q['v'] + ""
+
+ cmd_d[q['tab']] += qstr + " "
+
+ cmd = "cat <( %s ) <( %s ) <( %s ) <( %s ) & %s; %s" % (cmd_d['file'], cmd_d['filter'], cmd_d['melting'], cmd_d['scoring'], container, shmcleanup)
+
+ print cmd
+ res = run_generic(cmd)
+ return res
+
+
+variable = yad_ask_all_questions(questions)
+print variable
+
+print variables_to_string(variables)
+run(variables_to_string(variables))
+raw_input("Press Enter to exit...")