def test_get_plugin_and_folder_with_folder(self): """ Test the get_plugin_and_folder function with too many inputs """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) plugin2, folder2 = mq2.get_plugin_and_folder(inputdir=folder) self.assertEqual(plugin, plugin2) self.assertEqual(folder, folder2)
def test_get_plugin_and_folder_with_folder(self): """ Test the get_plugin_and_folder function with too many inputs """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) plugin2, folder2 = mq2.get_plugin_and_folder( inputdir=folder) self.assertEqual(plugin, plugin2) self.assertEqual(folder, folder2)
def test_plugin_get_files(self): """ Test the get_files method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_files(folder)), 1) self.assertTrue(plugin.get_files(folder)[0].endswith('/rqtl_out.csv')) self.assertEqual(plugin.get_files(None), [])
def test_run_mq2_from_file(self): """ Test the run_mq2 function from a file. """ plugin, folder = mq2.get_plugin_and_folder( inputfile=TEST_INPUT_FILE) mq2.run_mq2(plugin, folder=TEST_INPUT_FILE, lod_threshold=3) self.assertEqual(read_file('qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls.exp'))) self.assertEqual(read_file('map.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'map.exp'))) self.assertEqual(read_file('map_with_qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'map_with_qtls.exp'))) self.assertEqual(read_file('qtls_matrix.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls_matrix.exp'))) self.assertEqual(read_file('qtls_with_mk.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls_with_mk.exp'))) self.assertEqual(read_file('MapChart.map'), read_file(os.path.join( TEST_FOLDER, 'csv', 'MapChart.exp')))
def test_plugin_get_files(self): """ Test the get_files method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_files(folder)), 1) self.assertTrue(plugin.get_files(folder)[0].endswith('/rqtl_out.csv')) self.assertEqual(plugin.get_files(None), [])
def test_plugin_get_session_identifiers(self): """ Test the get_session_identifiers method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_session_identifiers(folder)), 1) self.assertEqual(plugin.get_session_identifiers(folder), ['2']) self.assertEqual(plugin.get_session_identifiers(None), [])
def test_plugin_get_session_identifiers_failed(self): """ Test the get_session_identifiers method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertRaises(MQ2.MQ2Exception, plugin.get_session_identifiers, folder=os.path.join(TEST_FOLDER, 'fake.xls'), inputfile=folder)
def test_plugin_valid_file(self): """ Test the valid_file method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertFalse(plugin.valid_file(TEST_INPUT_PASSED)) self.assertTrue(plugin.valid_file( os.path.join(folder, 'rqtl_output', 'rqtl_out.csv')))
def test_plugin_valid_file(self): """ Test the valid_file method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertFalse(plugin.valid_file(TEST_INPUT_PASSED)) self.assertTrue( plugin.valid_file( os.path.join(folder, 'rqtl_output', 'rqtl_out.csv')))
def test_run_mq2_invalid_input(self): """ Test the run_mq2 function with an invalid MapQTL zip input. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_FAILED) self.assertRaises( MQ2.MQ2NoMatrixException, mq2.run_mq2, plugin, folder, lod_threshold=3, session=2)
def session(session_id): """ Shows the session page. This page shows the different experiments ran on this session. A session being a MapQTL output zip file and a JoinMap map file, experiments are defined by the parameters used to find the QTLs within this MapQTL output. @param session_id the session identifier uniquely identifying the MapQTL zip file and the JoinMap map file. """ print 'mq2 %s -- %s -- %s' % (datetime.datetime.now(), request.remote_addr, request.url) if session_id == CONFIG.get('mq2', 'sample_session'): global UPLOAD_FOLDER UPLOAD_FOLDER = os.path.join(os.path.abspath(__file__), APP.static_folder) upload_folder = os.path.join(UPLOAD_FOLDER, session_id) try: plugin, folder = get_plugin_and_folder( inputzip=os.path.join(upload_folder, 'input.zip')) except IOError: flash('Could not extract the zip archive.', 'errors') return redirect(url_for('index')) if plugin.session_name: form = InputFormSession(sessions=sorted( plugin.get_session_identifiers(folder)), sessions_label=plugin.session_name) else: form = InputForm() if not (session_id in os.listdir(UPLOAD_FOLDER) or session_id in os.listdir(APP.static_folder)): flash('This session does not exists') return redirect(url_for('index')) if form.validate_on_submit(): lod_threshold = form.lod_threshold.data session = None if plugin.session_name: session = form.session.data output = None try: output = mq2_run(session_id, plugin, folder, lod_threshold=lod_threshold, session=session) except MQ2Exception, err: form.errors['MQ2'] = err if output: flash("Experiment already run in experiment: <a href='%s'>" "%s</a>" % (url_for('results', session_id=session_id, exp_id=output), output))
def test_run_mq2_invalid_session(self): """ Test the run_mq2 function with MapQTL zip input and the wrong session identifier. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertRaises( MQ2.MQ2NoSuchSessionException, mq2.run_mq2, plugin, folder, lod_threshold=3, session=1)
def test_run_mq2_invalid_lod(self): """ Test the run_mq2 function with MapQTL zip input and an invalid LOD threshold. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertRaises( MQ2.MQ2Exception, mq2.run_mq2, plugin, folder=folder, lod_threshold='a', session=2)
def test_run_mq2_no_folder(self): """ Test the run_mq2 function with MapQTL zip input and without folder. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertRaises( MQ2.MQ2Exception, mq2.run_mq2, plugin, folder=None, lod_threshold=3, session=2)
def test_run_mq2_kw(self): """ Test the run_mq2 function with MapQTL zip input of a Kruskal-Wallis analysis. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_KW) self.assertRaises( MQ2.MQ2Exception, mq2.run_mq2, plugin, folder, lod_threshold=3, session=2)
def test_plugin_get_session_identifiers_failed(self): """ Test the get_session_identifiers method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertRaises( MQ2.MQ2Exception, plugin.get_session_identifiers, folder=os.path.join(TEST_FOLDER, 'fake.xls'), inputfile=folder)
def test_plugin_valid_file(self): """ Test the valid_file method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertFalse(plugin.valid_file(TEST_INPUT_PASSED)) self.assertTrue( plugin.valid_file(os.path.join(folder, os.listdir(folder)[0]))) self.assertFalse(plugin.valid_file(TEST_FAKE_INPUT_FILE))
def test_plugin_get_files(self): """ Test the get_files method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_files(folder)), 2) self.assertTrue( plugin.get_files(folder)[0].endswith( '/Session 2 (IM)_A_trait01.mqo')) self.assertEqual(plugin.get_files(None), [])
def test_get_plugin_and_folder(self): """ Test the get_plugin_and_folder function with MapQTL zip input. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertTrue( os.path.basename(folder).startswith( date.today().strftime('%Y%m%d'))) self.assertEqual(plugin.name, 'CSV plugin') self.assertEqual(plugin.session_name, None)
def test_get_plugin_and_folder(self): """ Test the get_plugin_and_folder function with MapQTL zip input. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertTrue(os.path.basename( folder).startswith(date.today().strftime('%Y%m%d'))) self.assertEqual(plugin.name, 'CSV plugin') self.assertEqual(plugin.session_name, None)
def test_plugin_valid_file(self): """ Test the valid_file method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertFalse(plugin.valid_file(TEST_INPUT_PASSED)) self.assertTrue(plugin.valid_file( os.path.join(folder,os.listdir(folder)[0]))) self.assertFalse(plugin.valid_file( TEST_FAKE_INPUT_FILE))
def session(session_id): """ Shows the session page. This page shows the different experiments ran on this session. A session being a MapQTL output zip file and a JoinMap map file, experiments are defined by the parameters used to find the QTLs within this MapQTL output. @param session_id the session identifier uniquely identifying the MapQTL zip file and the JoinMap map file. """ print 'mq2 %s -- %s -- %s' % (datetime.datetime.now(), request.remote_addr, request.url) if session_id == CONFIG.get('mq2', 'sample_session'): global UPLOAD_FOLDER UPLOAD_FOLDER = os.path.join(os.path.abspath(__file__), APP.static_folder) upload_folder = os.path.join(UPLOAD_FOLDER, session_id) try: plugin, folder = get_plugin_and_folder( inputzip=os.path.join(upload_folder, 'input.zip')) except IOError: flash('Could not extract the zip archive.', 'errors') return redirect(url_for('index')) if plugin.session_name: form = InputFormSession( sessions=sorted(plugin.get_session_identifiers(folder)), sessions_label=plugin.session_name) else: form = InputForm() if not (session_id in os.listdir(UPLOAD_FOLDER) or session_id in os.listdir(APP.static_folder)): flash('This session does not exists') return redirect(url_for('index')) if form.validate_on_submit(): lod_threshold = form.lod_threshold.data session = None if plugin.session_name: session = form.session.data output = None try: output = mq2_run(session_id, plugin, folder, lod_threshold=lod_threshold, session=session) except MQ2Exception, err: form.errors['MQ2'] = err if output: flash("Experiment already run in experiment: <a href='%s'>" "%s</a>" % (url_for('results', session_id=session_id, exp_id=output), output))
def test_plugin_get_session_identifiers(self): """ Test the get_session_identifiers method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_session_identifiers(folder)), 1) self.assertEqual(plugin.get_session_identifiers(folder), ['Sheet1']) self.assertEqual(plugin.get_session_identifiers(None), []) self.assertEqual( plugin.get_session_identifiers( folder=os.path.join(TEST_FOLDER, 'fake.xls')), []) self.assertEqual(plugin.get_session_identifiers(inputfile=folder), [])
def test_plugin_get_session_identifiers(self): """ Test the get_session_identifiers method of the plugin. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) self.assertEqual(len(plugin.get_session_identifiers(folder)), 1) self.assertEqual(plugin.get_session_identifiers(folder), ['Sheet1']) self.assertEqual(plugin.get_session_identifiers(None), []) self.assertEqual(plugin.get_session_identifiers( folder=os.path.join(TEST_FOLDER, 'fake.xls')), []) self.assertEqual(plugin.get_session_identifiers( inputfile=folder), [])
def test_run_mq2(self): """ Test the run_mq2 function from a zip archive. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) mq2.run_mq2(plugin, folder, lod_threshold=3, session='Sheet1') self.assertEqual( read_file('qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'xls', 'qtls.exp'))) self.assertEqual( read_file('map.csv'), read_file(os.path.join(TEST_FOLDER, 'xls', 'map.exp'))) self.assertEqual( read_file('map_with_qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'xls', 'map_with_qtls.exp'))) self.assertEqual( read_file('qtls_with_mk.csv'), read_file(os.path.join(TEST_FOLDER, 'xls', 'qtls_with_mk.exp')))
def test_run_mq2(self): """ Test the run_mq2 function from a zip archive. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) mq2.run_mq2(plugin, folder, lod_threshold=3, session='Sheet1') self.assertEqual(read_file('qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'xls', 'qtls.exp'))) self.assertEqual(read_file('map.csv'), read_file(os.path.join( TEST_FOLDER, 'xls', 'map.exp'))) self.assertEqual(read_file('map_with_qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'xls', 'map_with_qtls.exp'))) self.assertEqual(read_file('qtls_with_mk.csv'), read_file(os.path.join( TEST_FOLDER, 'xls', 'qtls_with_mk.exp')))
def test_run_mq2_from_file(self): """ Test the run_mq2 function from a file. """ plugin, folder = mq2.get_plugin_and_folder(inputfile=TEST_INPUT_FILE) mq2.run_mq2(plugin, folder=TEST_INPUT_FILE, lod_threshold=3) self.assertEqual( read_file('qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls.exp'))) self.assertEqual( read_file('map.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'map.exp'))) self.assertEqual( read_file('map_with_qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'map_with_qtls.exp'))) self.assertEqual( read_file('qtls_matrix.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls_matrix.exp'))) self.assertEqual( read_file('qtls_with_mk.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls_with_mk.exp'))) self.assertEqual( read_file('MapChart.map'), read_file(os.path.join(TEST_FOLDER, 'csv', 'MapChart.exp')))
def test_run_mq2(self): """ Test the run_mq2 function with MapQTL zip input. """ plugin, folder = mq2.get_plugin_and_folder(inputzip=TEST_INPUT_PASSED) mq2.run_mq2(plugin, folder, lod_threshold=3, session=2) self.assertEqual( read_file('qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls.exp'))) self.assertEqual( read_file('map.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'map.exp'))) self.assertEqual( read_file('map_with_qtls.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'map_with_qtls.exp'))) self.assertEqual( read_file('qtls_matrix.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls_matrix.exp'))) self.assertEqual( read_file('qtls_with_mk.csv'), read_file(os.path.join(TEST_FOLDER, 'csv', 'qtls_with_mk.exp'))) self.assertEqual( read_file('MapChart.map'), read_file(os.path.join(TEST_FOLDER, 'csv', 'MapChart.exp')))
def test_run_mq2(self): """ Test the run_mq2 function with MapQTL zip input. """ plugin, folder = mq2.get_plugin_and_folder( inputzip=TEST_INPUT_PASSED) mq2.run_mq2(plugin, folder, lod_threshold=3, session=2) self.assertEqual(read_file('qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls.exp'))) self.assertEqual(read_file('map.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'map.exp'))) self.assertEqual(read_file('map_with_qtls.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'map_with_qtls.exp'))) self.assertEqual(read_file('qtls_matrix.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls_matrix.exp'))) self.assertEqual(read_file('qtls_with_mk.csv'), read_file(os.path.join( TEST_FOLDER, 'csv', 'qtls_with_mk.exp'))) self.assertEqual(read_file('MapChart.map'), read_file(os.path.join( TEST_FOLDER, 'csv', 'MapChart.exp')))