Пример #1
0
    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)
Пример #2
0
Файл: test.py Проект: PBR/MQ2
    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)
Пример #3
0
 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), [])
Пример #4
0
 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')))
Пример #5
0
 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), [])
Пример #6
0
 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), [])
Пример #7
0
 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)
Пример #8
0
 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')))
Пример #9
0
 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')))
Пример #10
0
 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)
Пример #11
0
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))
Пример #12
0
 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)
Пример #13
0
 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)
Пример #14
0
 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)
Пример #15
0
 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)
Пример #16
0
 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)
Пример #17
0
 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)
Пример #18
0
    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))
Пример #19
0
 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)
Пример #20
0
 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), [])
Пример #21
0
 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)
Пример #22
0
 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)
Пример #23
0
    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))
Пример #24
0
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))
Пример #25
0
    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), [])
Пример #26
0
    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), [])
Пример #27
0
 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')))
Пример #28
0
 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')))
Пример #29
0
 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')))
Пример #30
0
 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')))
Пример #31
0
 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')))