def test_create_blast_from_file(self): file_var = "NotExist" e_var = 1e-50 batch_size = 20 outfile_var = "foolname" setting = Setting() setting.add_all(blast_e_value=e_var, blast_wdir=self.Blast_dir, blast_infile=file_var, blast_outfile=outfile_var, blast_batch_size=batch_size, ) with self.assertRaises(IOError): RunBlast.create_blast_from_file(setting_class=setting) infile_var = self.Blast_dir + "bIn" setting.add("blast_infile", infile_var) blast = RunBlast.create_blast_from_file(setting) self.assertEqual(blast.results, dict()) self.record_index = SeqIO.index(infile_var, "fasta") for key in self.record_index: # print key self.assertEqual(str(self.record_index[key].seq), str(blast.record_index[key].seq)) self.assertEqual(str(self.record_index[key].id), str(blast.record_index[key].id)) self.assertEqual(blast.e_threshold, e_var) self.assertEqual(blast.batch_size, batch_size)
def __init__(self): self.settings = Setting.settings() self.handlers = Setting.handlers() self.handlers.append( (r"/(apple-touch-icon\.png)", web.StaticFileHandler, dict(path=self.settings['static_path'])), ) self.setup() print "MainApp initalize complete"
def test_Setting_set_param(self): setting = Setting() setting.add_all(infle="asdf", filename="zxcv", noI=2) expected = {"infle": "asdf", "filename": "zxcv", "noI": 2} self.assertEqual(setting.all_setting, expected) setting.add_all(infle="asdf", outfile2="12345", noI=6) expected = {"infle": "asdf", "filename": "zxcv", "noI": 6, "outfile2": "12345"} self.assertEqual(setting.all_setting, expected)
def test_missed_essential(self): # When not all essential parameters exist, should fail. infile = self.unittest_dir + "missedEssentials" with self.assertRaises(KeyError): setting = Setting.create_setting_from_file(infile) assembler = SoftwareAssembler(setting)
def test_min_setting(self): infile = self.unittest_dir + "testControlFileMin" setting = Setting.create_setting_from_file(infile) assembler = SoftwareAssembler(setting) expected = set(TestSoftwareAssembler.list_all_parameters) self.assertEqual(expected, set(assembler.get_all_par().viewkeys())) print assembler.get_all_par().values()
def test_some_optional(self): infile = self.unittest_dir + "testControlFileOp1" setting = Setting.create_setting_from_file(infile) assembler = SoftwareAssembler(setting) expected = set(TestSoftwareAssembler.list_all_parameters) self.assertEqual(expected, set(assembler.get_all_par().viewkeys())) self.assertEqual(run_genovo.DEFAULT_GENOVO_NO_ITER, assembler.get("genovo_num_iter")) self.assertEqual("1e-10", assembler.get("blast_e_value"))
def test_create_setting_from_file_MINE_only(self): # When not all essential parameters exist but no optional parameters exist, should pass. file = self.data_dir + "testControlFileMINE" setting = Setting.create_setting_from_file(file) expected = { "wdir" :"/someDir/subDir/workingDir", "mine_pdir":"/someDir/subDir/MINE", "mine_cv":"20", "mine_infile":"mineInfile", "csv_files":"out1.csv,out2.csv" } # self.assertEqual(setting.all_setting, expected) self.assertEqual(expected, setting.all_setting)
def test_Setting_get_glimmer(self): setting = Setting() setting.add_all(filename="Outfile") # setting.print_all() self.assertRaises(KeyError, setting.check_parameters_program, "glimmer") setting.add_all(genovo_outfile="infile", glimmer_outfile="glimOut", glimmer_pdir="glimp_dir", wdir=self.wdir) expected = {"glimmer_infile": "infile", "genovo_outfile": "infile", "filename": "Outfile", "glimmer_outfile": "glimOut", "glimmer_pdir": "glimp_dir", "wdir": self.wdir, "check_exist": True} self.assertEqual(expected, setting.check_parameters_program("glimmer")) setting.add_all(glimmer_infile="glInfile") expected["glimmer_infile"] = "glInfile"
def test_create_setting_from_file(self): # When not all essential parameters exist but no optional parameters exist, should pass. file = self.data_dir + "testControlFileOp1" setting = Setting.create_setting_from_file(file) expected = {"wdir" :"/someDir/subDir/workingDir", "master_tag": "genovoInfile", "genovo_infile": "genovoInfile", "genovo_pdir": "/someDir/subDir/genevo", "genovo_num_iter": "20", "glimmer_pdir":"/someDir/subDir/glimmer", "blast_e_value":"1e-10", } self.assertEqual(expected, setting.all_setting) # When not all essential parameters exist, should fail. file = self.data_dir + "missedEssentials" with self.assertRaises(KeyError): Setting.create_setting_from_file(file) # When all essential parameters exist and all optional parameters exist, should pass. file = self.data_dir + "allPass" try: setting = Setting.create_setting_from_file(file) except KeyError: self.fail("raise KeyError unexpectedly") # When not all essential parameters exist and some optional parameters exist, should pass. file = self.data_dir + "testControlFileOp1" try: setting = Setting.create_setting_from_file(file) except KeyError: self.fail("raise KeyError unexpectedly")
def create_from_args(cls, args): setting = Setting.create_setting_from_file(args) assembler = cls(setting, args.debug) return assembler
def test_init_program(self): setting = Setting(); setting.add_all(genovo_infile="wdir_all_reads.fa", genovo_pdir=self.genovo_dir) setting.add_all(glimmer_pdir=self.glimmer_dir) setting.add_all(wdir=self.working_dir) # setting.add_all(metasim_model_infile="ErrorModelSolexa36bp.mconf", metasim_no_reads=10, metasim_pdir=self.metasim_dir, # metasim_taxon_infile="MetaSim_bint.mprf") setting.add_all(mine_pdir=self.mine_dir, mine_comparison_style="-allPairs") setting.add_all(blast_infile="dictionary", blast_e_value=1e-15, blast_wdir=self.blast_dir, blast_outfile=None) assembly = SoftwareAssembler(setting) assembly.init_program()
def test_Setting_get_mine(self): setting = Setting() setting.add_all(filename="Outfile") setting.debug = True # setting.print_all() # self.assertRaises(KeyError, setting._get_mine()) setting.add_all(mine_outfile="mineOut", mine_pdir="mine_pdir", mine_comparison_style="-allPairs") setting.add("mine_infile", "infile") setting.add("wdir", "working_dir") setting.add("csv_files", "file1,file2,file3") expected = {"mine_infile": "infile", "filename": "Outfile", "mine_outfile": "mineOut", "mine_pdir": "mine_pdir", "mine_comparison_style": "-allPairs", "wdir": "working_dir", "check_exist": True, "mine_cv": 0.0, "mine_exp": 0.6, "mine_clumps": 15, "mine_jobID": None, "csv_files": ["file1", "file2", "file3"]} self.assertEqual(expected, setting.check_parameters_program("mine")) setting.add_all(mine_infile="mineInfile") expected["mine_infile"] = "mineInfile"
def test_Setting_get_genovo(self): setting = Setting() setting.add_all(assembler_infile="gInfile", filename="gOutfile", genovo_thresh=2) # setting.print_all() self.assertRaises(KeyError, setting.check_parameters_program, "genovo") setting = Setting() setting.add_all(assembler_infile="gInfile", filename="gOutfile", genovo_num_iter=2) self.assertRaises(KeyError, setting.check_parameters_program, "genovo") setting.add("genovo_thresh", 10) setting.add_all(genovo_thresh=14, assembler_pdir="g_p_dir", wdir=self.wdir) expected = {"assembler_infile": "gInfile", "filename": "gOutfile", "genovo_num_iter": 2, "genovo_thresh": 14, "assembler_pdir": "g_p_dir", "wdir": self.wdir, "check_exist": True, "assembler_outfile": None} self.assertEqual(expected, setting.check_parameters_program("genovo")) setting.add("wdir", "otherdir") expected["wdir"] = "otherdir" self.assertEqual(expected, setting.check_parameters_program("genovo")) setting = Setting() setting.add_all(assembler_infile="gInfile", genovo_thresh=14, genovo_pdir="g_p_dir", genovo_num_iter=2) setting.add("wdir", "otherdir") expected.pop("filename") self.assertEqual(expected, setting.check_parameters_program("genovo"))
def test_Setting_get_metasim(self): # "metasim_pdir", "metasim_model_infile", "metasim_taxon_infile", "metasim_no_reads" setting = Setting() setting.add_all(metasim_model_infile="mmInfile", filename="mOutfile", metasim_no_reads=200) # setting.print_all() self.assertRaises(KeyError, setting.check_parameters_program, "metasim") setting = Setting() setting.add_all(metasim_model_infile="mmInfile", filename="mOutfile", metasim_taxon_infile="tInfile") self.assertRaises(KeyError, setting.check_parameters_program, "metasim") setting.add("metasim_pdir", "m_p_dir") setting.add_all(metasim_no_reads=250, wdir=self.wdir) expected = {"metasim_model_infile": "mmInfile", "filename": "mOutfile", "metasim_taxon_infile": "tInfile", "metasim_pdir": "m_p_dir", "metasim_no_reads": 250, "wdir": self.wdir, "check_exist": True, "metasim_outfile": None} setting.debug = 0 self.assertEqual(expected, setting.check_parameters_program("metasim")) setting.add("wdir", "otherdir") expected["wdir"] = "otherdir" self.assertEqual(expected, setting.check_parameters_program("metasim")) setting = Setting() setting.add_all(metasim_model_infile="mmInfile", metasim_no_reads=250, metasim_taxon_infile="tInfile", metasim_pdir="m_p_dir") setting.add("wdir", "otherdir") expected.pop("filename") self.assertEqual(expected, setting.check_parameters_program("metasim"))
def test_Setting_get_pars(self): setting = Setting(genovo_infile="gInfile", genovo_thresh=14) setting.add_all(genovo_pdir="g_p_dir", genovo_num_iter=2, wdir="otherdir", check_exist=True) expected = {"genovo_infile": "gInfile", "genovo_num_iter": 2, "genovo_thresh": 14, "genovo_pdir": "g_p_dir", "check_exist": True, "genovo_outfile": None, "wdir": "otherdir"} print "W", setting.check_parameters_program("genovo") self.assertEqual(expected, setting.check_parameters_program("genovo")) setting = Setting() setting.add_all(filename="Outfile", genovo_outfile="infile", glimmer_outfile="glimOut", glimmer_pdir="glimp_dir", wdir="working_dir") expected = {"glimmer_infile": "infile", "genovo_outfile": "infile", "filename": "Outfile", "glimmer_outfile": "glimOut", "glimmer_pdir": "glimp_dir", "wdir": "working_dir", "check_exist": True } print setting.check_parameters_program("glimmer") self.assertEqual(expected, setting.check_parameters_program("glimmer")) setting.add("glimmer_infile", "glInfile") expected["glimmer_infile"] = "glInfile" self.assertEqual(expected, setting.check_parameters_program("glimmer"))
def __init__(self): self.settings = Setting.settings() self.handlers = Setting.handlers() self.handlers.append((r"/(apple-touch-icon\.png)", web.StaticFileHandler, dict(path= self.settings['static_path'])),) self.setup() print "MainApp initalize complete"
from core.setting import Setting st = Setting() n = st.get_setting_ip() print(n.get_port(), n.get_ip())
def test_Setting_get_blast(self): setting = Setting() setting.add_all(blast_infile="bInfile", blast_outfile="bOutfile") with self.assertRaises(KeyError): setting.check_parameters_program("blast") setting.add_all(blast_e_value=1e-15, wdir="working_dir", check_exist=True) expected = {"blast_infile": "bInfile", "blast_outfile": "bOutfile", "blast_e_value": 1e-15, "blast_batch_size": 20, "wdir": "working_dir", "check_exist": True } setting.debug = True self.assertEqual(expected, setting.check_parameters_program("blast")) setting.add("wdir", "otherdir") expected["wdir"] = "otherdir" self.assertEqual(expected, setting.check_parameters_program("blast")) setting = Setting() setting.add_all(blast_infile="bInfile") setting.add("wdir", "otherdir") setting.add("blast_e_value", 1e-15) setting.add("blast_outfile", "bOutfile") # expected.pop("filename") # TODO: debug switch setting.debug = True self.assertEqual(expected, setting.check_parameters_program("blast"))