code
stringlengths 658
1.05M
|
---|
from __future__ import print_function
from __future__ import absolute_import
import os
import sys
import simplejson
from metatlas.kbase.trns_transform_mzML_LCMS_to_MetaboliteAtlas2_MAFileInfo \
import transform, main
from metatlas.mzml_loader import get_test_data
def test_transform():
path = prep()
setup = dict(polarity='negative',
group='test',
retention_correction='none',
normalization_factor='11')
transform(input_directory=os.path.dirname(path),
working_directory=os.path.dirname(path),
**setup)
check_dir(path, **setup)
def prep():
path = get_test_data()['basic']
if os.path.exists(path.replace('.mzML', '_finfo.json')):
os.remove(path.replace('.mzML', '_finfo.json'))
return path
def check_dir(path, **setup):
assert os.path.exists(path.replace('.mzML', '_finfo.json'))
with open(path.replace('.mzML', '_finfo.json')) as fid:
data = simplejson.load(fid)
print(data)
assert data['mzml_file_name'] == os.path.basename(path).replace('.mzML',
'')
assert data['atlases'] == []
for (key, value) in setup.items():
assert data[key] == value
def test_transform_main():
return
path = prep()
sys.argv = ['transform', '--shock_service_url', '',
'--input_directory', os.path.dirname(path),
'--working_directory', os.path.dirname(path),
'--debug']
main()
check_dir(path)
|
#!/usr/env python
# -*- coding: utf-8 -*-
import os
from config import load_config
class LBSociam(object):
"""
Classe global com as configurações
"""
def __init__(self):
"""
Parâmetro construtor
"""
config = load_config()
self.twitter_sources = config.get('twitter', 'sources')
self.twitter_hashtags = config.get('twitter', 'hashtags')
self.twitter_consumer_key = config.get('twitter', 'consumer_key')
self.twitter_consumer_secret = config.get('twitter', 'consumer_secret')
self.twitter_access_token = config.get('twitter', 'access_token')
self.twitter_access_secret = config.get('twitter', 'access_secret')
self.lbgenerator_rest_url = config.get('lbgenerator', 'rest_url')
self.es_url = config.get('lbgenerator', 'es_url')
self.geo_url = config.get('lbgenerator', 'geo_url')
lbsociam_data_dir = config.get('lbsociam', 'data_dir')
if os.path.isdir(lbsociam_data_dir):
self.lbsociam_data_dir = lbsociam_data_dir
else:
os.mkdir(lbsociam_data_dir)
self.lbsociam_data_dir = lbsociam_data_dir
self.processes = config.get('lbsociam', 'processes')
self.max_size = config.get('lbsociam', 'max_size')
self.status_base = config.get('lbsociam', 'status_base')
self.dictionary_base = config.get('lbsociam', 'dictionary_base')
self.gmaps_api_key = config.get('maps', 'api_key')
|
import pytest
import numpy as np
import pickle
import symfeat as sf
@pytest.fixture
def data():
np.random.seed(42)
d = np.random.normal(size=(10, 2))
d[0, 0] = 0
return d
def test_ConstantFeature(data):
const = sf.ConstantFeature()
assert const.name == "1"
np.testing.assert_allclose(data[:, 0]**0, const.transform(data))
@pytest.mark.parametrize("index", range(2))
@pytest.mark.parametrize("exponent", [1, 2, -1, -2])
def test_SimpleFeature(exponent, data, index):
simple = sf.SimpleFeature(exponent, index=index)
np.testing.assert_allclose(data[:, index]**exponent, simple.transform(data))
def test_SimpleFeature_raise():
with pytest.raises(ValueError):
sf.SimpleFeature(0)
def test_SimpleFeature_name():
simple = sf.SimpleFeature(1)
assert simple.name == "x_0"
simple = sf.SimpleFeature(2, index=2)
assert simple.name == "x_2**2"
def test_OperatorFeature(data):
simple = sf.SimpleFeature(1)
operator = np.exp
operator_name = "exp"
op = sf.OperatorFeature(simple, operator, operator_name=operator_name)
assert op.name == "{}(x_0)".format(operator_name)
np.testing.assert_allclose(operator(data[:, simple.index]), op.transform(data))
def test_ProductFeature(data):
simple10 = sf.SimpleFeature(1, index=0)
simple11 = sf.SimpleFeature(1, index=1)
prod = sf.ProductFeature(simple10, simple11)
assert prod.name == "x_0*x_1"
np.testing.assert_allclose(data[:, 0]*data[:, 1], prod.transform(data))
def test_SymbolicFeatures(data):
operators = {"log": np.log}
exponents = [2]
sym = sf.SymbolicFeatures(exponents, operators)
features = sym.fit_transform(data)
names = sym.names
assert len(names) == features.shape[1]
assert features.shape[0] == data.shape[0]
np.testing.assert_allclose(features[:, 0], np.ones_like(data[:,0]))
def test_SymbolicFeatures_remove_id(data):
"""ProductFeature x_i * x_i**2 == x_i**3
"""
operators = {}
exponents = [1, 2, 3]
sym = sf.SymbolicFeatures(exponents, operators).fit(data)
# const + simple * 2 + products - excluded
assert len(sym.names) == 1 + 2*3 + 15 - 2
def test_SymbolicFeatures_redundant_data():
data = np.ones(shape=(10, 10))
exponents = [1]
operators = {}
sym = sf.SymbolicFeatures(exponents, operators).fit(data)
assert len(sym.names) == 1
def test_SymbolicFeatures_no_const():
data = np.ones(shape=(10, 10))
exponents = [1]
operators = {}
sym = sf.SymbolicFeatures(exponents, operators, const=False).fit(data)
assert sym.names[0] == "x_0"
def test_SymbolicFeatures_pickle(data):
exponents = [1]
operators = {}
sym = sf.SymbolicFeatures(exponents, operators)
assert pickle.loads(pickle.dumps(sym)).__dict__ == sym.__dict__
sym.fit(data)
assert pickle.loads(pickle.dumps(sym)).names == sym.names
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2013 Didotech srl (info at didotech.com)
#
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import fields, osv
from tools.translate import _
class module(osv.osv):
_inherit = "ir.module.module"
def _check_upgrade(self, cr, uid, ids, field_name=None, arg=None, context=None):
installed_module_ids = self.search(cr, uid, [('state', 'in', ['installed', 'to upgrade', 'to remove'])])
for module in self.browse(cr, uid, installed_module_ids):
if not module.latest_version == self.get_module_info(module.name).get('version', '') and not module.need_upgrade:
self.write(cr, uid, module.id, {'need_upgrade': True})
res = {}
for module_id in ids:
res[module_id] = True
return res
def _need_upgrade(self, cr, uid, ids, field_name=None, arg=None, context=None):
res = dict.fromkeys(ids, '')
for module in self.browse(cr, uid, ids):
if not module.latest_version == self.get_module_info(module.name).get('version', ''):
res[module.id] = True
else:
res[module.id] = False
return res
_columns = {
'need_upgrade': fields.function(_need_upgrade, string=_('Need Upgrade'), method=True, type='boolean', store=True),
'check_upgrade': fields.function(_check_upgrade, string=_('Need Upgrade'), method=True, type='boolean', store=False)
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.