def dbInit(): sqlPaths = [ AppSettings().dropSQLTablePath, AppSettings().createSQLTablePath, AppSettings().fillSQLTablesPath ] with open(AppSettings().allSqlCommandsPath, 'w') as total: for sqlPath in sqlPaths: with open(sqlPath, 'r') as f: content = f.read() total.write(content + '\n') applySQLcommands(AppSettings().allSqlCommandsPath)
def generate(self): dna = Chromosome() cfg = AppSettings() if not os.path.exists("reports"): # pragma: no cover os.makedirs("reports") f = open("reports/_" + str(int(time.time())) + ".txt", "w") f.write("==========================\n" + "==========================\n" + "==\n" "== Genetics\n\n" + "nucleotides: " + dna.nucleotides() + "\n" + "expected length: " + str(cfg.genetics.chromosome_length) + "\n\n" + "Examples: \n") for i in range(1, 10): dna = Chromosome() f.write(dna.sequence + "\n") lengths = [] for i in range(1, 1000): dna = Chromosome() lengths.append(len(dna.sequence)) f.write(f"\n\nmean_length (standard deviation): " + \ f"{statistics.mean(lengths)} " + \ f"({statistics.stdev(lengths)})") f.close()
def build(self): self.bind(on_start=self.post_build_init) self.root = Shell() self.dir = os.path.join(os.path.dirname(__file__)) self.app_settings = AppSettings() self.app_settings.pre_load_settings() self.app_settings.load_settings() self._setup()
def __init__(self): self.appSettings = AppSettings() self.lbtesting = os.getenv('LB-TESTING') or '0' if self.lbtesting == '1': # print('Using AppSettingsTest') self.appSettings = AppSettingsTest() self.process()
def __init__(self): super().__init__() self.settings = AppSettings() self.d_print("XpathEva constructor") self.filename = "" self.xpath_query = "" openFile = QAction(QIcon('open.png'), 'Open', self) openFile.setShortcut('Ctrl+O') openFile.setStatusTip('Open new File') openFile.triggered.connect(self.show_dialog) appQuit = QAction(QIcon('quit.png'), 'Quit', self) appQuit.setShortcut('Ctrl+Q') appQuit.setStatusTip('Quit') appQuit.triggered.connect(self._quit) menu_bar = self.menuBar() fileMenu = menu_bar.addMenu('&File') fileMenu.addAction(openFile) fileMenu.addAction(appQuit) self.filename_label_default_text = "Filename: " self.filename_label = QLabel(self) self.filename_label.setText(self.filename_label_default_text) self.query_edit = QLineEdit() self.query_result = QTextEdit() self.evaluate_btn_filler = HSpaceFiller() self.evaluate_button = QPushButton("Evaluate") self.evaluate_button.clicked.connect(self.evaluate_query) self.vbox = QVBoxLayout() self.evaluate_button_layout = QHBoxLayout() self.evaluate_button_layout.addWidget(self.evaluate_btn_filler) self.evaluate_button_layout.addWidget(self.evaluate_button) self.vbox.addWidget(self.filename_label) self.vbox.addWidget(self.query_edit) self.vbox.addWidget(self.query_result) # self.vbox.addWidget(self.evaluate_button) self.vbox.addLayout(self.evaluate_button_layout) self.central_widget = QWidget() self.central_widget.setLayout(self.vbox) self.setCentralWidget(self.central_widget) self.setGeometry(self.settings.x_position, self.settings.y_position, self.settings.window_width, self.settings.window_height) self.setWindowTitle('XpathEva') self.statusBar().showMessage('Ready') self.show() self.xpath_query_result = XpathQueryResult
def test_inversion_diffs(self): cfg = AppSettings() reps = 1000 deltas = [] # observed number of differences for _ in range(0, reps): dna = Chromosome() old_seq = dna.sequence dna.inversion() deltas.append( sum(1 for a, b in zip(old_seq, dna.sequence) if a != b)) pmfs = [] expected_deltas = [] # expected differences # Assumes the length of an inversion is drawn from a negative binomial # distribution. Calculates the probability of each length until # 99.99% of the distribution is accounted for. The expected number of # differences for each length is multiplied by the probability of that length # and the sum of that gives the expected differences overall. k = 0 while sum(pmfs) <= 0.9999: pmf = nbinom.pmf(k, 1, (1 - cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length))) pmfs.append(pmf) diffs = math.floor( k / 2) * (1 - 1 / len(Chromosome.nucleotides())) * 2 expected_deltas.append(pmf * diffs) k += 1 expected_delta = sum(expected_deltas) # Since we are multiplying the binomial distribution (probably of differences at # a given lenght) by a negative binomial distribution (probability of a length) # we must compute the variance of two independent random variables # is Var(X * Y) = var(x) * var(y) + var(x) * mean(y) + mean(x) * var(y) # http://www.odelama.com/data-analysis/Commonly-Used-Math-Formulas/ mean_binom = cfg.genetics.mutation_length var_binom = binom.var(mean_binom, 1 / (len(Chromosome.nucleotides()))) mean_nbinom = cfg.genetics.mutation_length var_nbinom = nbinom.var(cfg.genetics.mutation_length, mean_nbinom / (1 + mean_nbinom)) var = var_binom * var_nbinom + \ var_binom * mean_nbinom + \ mean_binom * var_nbinom observed_delta = sum(deltas) / reps conf_99 = ((var / reps)**(1 / 2)) * 5 assert expected_delta - conf_99 < observed_delta < expected_delta + conf_99
def getDb(): dbParams = AppSettings().dbParams() db = QtSql.QSqlDatabase.addDatabase("QMYSQL") db.setHostName(dbParams['host']) db.setDatabaseName(dbParams['db']) db.setUserName(dbParams['user']) db.setPassword(dbParams['passwd']) ok = db.open() if not ok: QtGui.QMessageBox.warning(None, "Error", "Invalid database!") sys.exit(-1) return db
def __init__(self, sequence=None): if sequence is not None: self.sequence = sequence return cfg = AppSettings() self.sequence = "" p = cfg.genetics.chromosome_length / (1 + cfg.genetics.chromosome_length) while (random.random() <= p): self.sequence += random.choice(self.nucleotides())
def substitutions(self): """Randomly changes charcters in the dna according to the poisson distribution. expected changes length * mutation rate * nonsynomous substitutions.""" cfg = AppSettings() num = poisson.rvs(cfg.genetics.mutation_rate * len(self.sequence)) positions = nrand.randint(0, len(self.sequence), size=num) for pos in positions: self.sequence = self.sequence[:pos] + \ random.choice(self.nucleotides()) + \ self.sequence[(pos + 1):]
def __init__(self): super().__init__() # use for testing, set os.environ['LB-TESTING'] = '1' to turn or '0' to turn off self.appSettings = AppSettings() self.lbtesting = os.getenv('LB-TESTING') or '0' if self.lbtesting == '1': #print('Using AppSettingsTest') self.appSettings = AppSettingsTest() self.data = None self.copyFile = None self.default_folder = None # '{}/temp'.format(str(Path.home())) self.child_folder_dict = AppSettings().getProjectFolders() # self.lbproject_name = os.getenv('LB_PROJECT_name') or 'example' #self.lbproject_name = self.working_folder_name_default = 'example' self.env_default = 'dev' self.description = ['NEED TO ADD DESCRIPTION'] self.fixEnv()
def deletion(self): """Deletes a random sequence of characters from a random position on the string. The length is taken from the negative binomial distribution.""" # Prevents an out of bounds error for random.randint() if (len(self.sequence) == 0): return pos = random.randint(0, len(self.sequence) - 1) cfg = AppSettings() p = cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length) while (random.random() <= p): self.sequence = self.sequence[:pos] + self.sequence[(pos + 1):]
def __init__(self, foldername=None, filename='context.template.list.json'): super().__init__(foldername, filename) self.tagid = 'templates' self.lbtesting = os.getenv('LB-TESTING') or '0' self.appSettings = AppSettings() #print('lbtesting', self.lbtesting) if self.lbtesting == '1': self.appSettings = AppSettingsTest() # default to source code resource, assume we are going to copy #self.setFolderName(self.appSettings.getResourceFolder('shared')) self.setFolderName((self.appSettings.getFolder('shared-folder'))) self.setFolderName(self.appSettings.getFolder('shared-folder')) self.read()
def insertion(self): """Inserts a random length of random nucleotide characters into a sequence at a random location. """ if (len(self.sequence) <= 1): pos = 0 else: pos = random.randint(0, len(self.sequence) - 1) cfg = AppSettings() p = cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length) while (random.random() <= p): self.sequence = self.sequence[:pos] + \ random.choice(self.nucleotides()) + \ self.sequence[pos:]
def test_random_chromosome_length(self): """Ensures that random chromosomes are created at the correct average length.""" reps = 1000 cfg = AppSettings() lengths = [] for _ in range(0, reps): chrom = Chromosome() lengths.append(len(chrom.sequence)) mean_length = float(sum(lengths)) / len(lengths) expected_length = cfg.genetics.chromosome_length p = 1 - (expected_length / (1 + expected_length)) conf_99 = (nbinom.var(1, p) / reps)**(1 / 2) * 4 assert (expected_length - conf_99) <= mean_length <= (expected_length + conf_99)
def init_application(config_path=None): """ Set up the 3 main classes: Configuration, Personality and Context This should be something that we can setup a unit test with :param config_path: :return: """ global app_config global terminal_old_settings terminal_old_settings = termios.tcgetattr(sys.stdin) app_config = AppSettings(config_path) personality = PersonalitySettings(app_config) states = personality.get_states() context = UserContext(states, app_config, personality) app_config.context = context globalvars.app_context = context
def inversion(self): if (len(self.sequence) <= 1): pos = 0 else: pos = random.randint(0, len(self.sequence) - 1) cfg = AppSettings() p = cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length) length = nbinom.rvs( 1, cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length)) self.sequence = self.sequence[:pos] + \ self.sequence[pos:(pos + length)][::-1] + \ self.sequence[(pos + length):]
def __init__(self, app, *args): QWidget.__init__(self, *args) self.session = None self.repo = None self.app = app self.system = SystemSettings() self.settings = AppSettings() self.main_layout = QHBoxLayout() self.setLayout(self.main_layout) self.launcher = InitialPanel(self.system, self.settings) self.main_layout.addWidget(self.launcher) self.main_layout.setContentsMargins(0, 0, 0, 0) self.launcher.on_settings_ready.connect(self.setSettings) self.launcher.on_root_selection.connect(self.start_session)
def test_insertion_length(self): """Tests that insertion mutations are of the correct length""" cfg = AppSettings() reps = 1000 deltas = [] for _ in range(0, reps): dna = Chromosome() init_length = len(dna.sequence) dna.insertion() deltas.append(len(dna.sequence) - init_length) expected_delta = cfg.genetics.mutation_length var = nbinom.var( 1, cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length)) conf_99 = ((var / reps)**(1 / 2)) * 4 observed_delta = (sum(deltas) / reps) assert (expected_delta - conf_99) < observed_delta < (expected_delta + conf_99)
def test_substitutions_changes(self): """Test that substitions occur at the expected rate.""" cfg = AppSettings() reps = 1000 deltas = [] for _ in range(0, reps): seq = "a" * 100 dna = Chromosome(seq) dna.substitutions() deltas.append(sum(1 for a, b in zip(seq, dna.sequence) if a != b)) # Expand the conf_99 to compensate for repeated mutations in the same place expected_delta = cfg.genetics.mutation_rate * 100 * \ (1 - 1/len(Chromosome.nucleotides())) # Because there is a little slop around synonymous substitions I multiply # the confidence by 10 just to limit the number of failing tests. conf_99 = ((poisson.var(cfg.genetics.mutation_rate * 100) / 1000) **(1 / 2)) * 10 observed_delta = sum(deltas) / reps assert (expected_delta - conf_99) < observed_delta < (expected_delta + conf_99)
def test_deletion_length(self): """Test that deletions return the correct averge length""" cfg = AppSettings() reps = 1000 deltas = [] for _ in range(0, reps): dna = Chromosome() init_length = len(dna.sequence) dna.deletion() deltas.append(init_length - len(dna.sequence)) expected_delta = cfg.genetics.mutation_length var = nbinom.var( 1, cfg.genetics.mutation_length / (1 + cfg.genetics.mutation_length)) # Because there is a little slop around short strings or positions near the # end of the string, I multiply # the confidence by 10 just to limit the number of failing tests. conf_99 = ((var / reps)**(1 / 2)) * 10 observed_delta = sum(deltas) / reps assert (expected_delta - conf_99) < observed_delta < (expected_delta + conf_99)
import time from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient #Define some globals GPIO.setmode(GPIO.BCM) camera = RCamera() #Camera connected to camera pins credentials: Credentials = Credentials() device_client: IoTCClient = None #IoTHubDeviceClient.create_from_connection_string(credentials.get_credentail_info(CredentialInfo.connection_string)) start_time = datetime.now() tfclassifier = TFClassify() tfclassifier2 = TFClassify2() log: logging.Logger = app_logger.get_logger() log.info(f"TensorFlow took {datetime.now() - start_time} seconds to load") modelTier = "tier1" _app_settings = AppSettings() _app_settings.ensure_label_folders_exist(modelTier) modelTier2 = "tier2" _app_settings2 = AppSettings() _app_settings.ensure_label_folders_exist(modelTier2) # Set the trigger word for setting a sub tier model lookup _subTierTrigger = _app_settings.get_SubTierTrigger(modelTier) _subTierTrigger2 = _app_settings2.get_SubTierTrigger(modelTier2) _USE_TEST_MODE = False _USE_BLOB_STORGE = False #_app_settings = AppSettings() #These commands are sent by IoT Central to the device
def nucleotides(): """Returns all the nucleotides that can be used in a dna string""" cfg = AppSettings() return (cfg.genetics.behaviors + cfg.genetics.gene_delimiter + cfg.genetics.receptor_delimiter + cfg.genetics.wildcards)
def __init__(self): self.appSettings = AppSettings() self.lbtesting = os.getenv('LB-TESTING') or '0' if self.lbtesting == '1': self.appSettings = AppSettingsTest() # self.type_map = { 'database': { 'prefix': '01', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'role': { 'prefix': '03', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'validate-function': { 'prefix': '04', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'table': { 'prefix': '05', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'function': { 'prefix': '07', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'interface-upsert': { 'prefix': '09', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'interface-select': { 'prefix': '09', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'interface-test': { 'prefix': '99', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'initialize': { 'prefix': '11', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'grant': { 'prefix': '13', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'test': { 'prefix': '99', 'ext': 'sql', 'folder-key': 'sql-folder' }, 'script-sh': { 'prefix': '15', 'ext': 'sh', 'folder-key': 'script-folder' }, 'config-sh': { 'prefix': '15', 'ext': 'config.sh', 'folder-key': 'umbrella-folder' }, 'setup-sh': { 'prefix': '15', 'ext': 'sh', 'folder-key': 'umbrella-folder' }, 'dockerfile-admin': { 'prefix': '17', 'ext': '', 'folder-key': 'admin-folder' }, 'dockerfile-db': { 'prefix': '17', 'ext': '', 'folder-key': 'db-folder' }, 'dockerfile-web': { 'prefix': '17', 'ext': '', 'folder-key': 'web-folder' }, 'docker-compose': { 'prefix': '19', 'ext': 'yml', 'folder-key': 'code-folder' }, 'environment': { 'prefix': '21', 'ext': 'env', 'folder-key': 'web-folder' }, } self.process()
def main(): from test_func import test_table, test_db from configuration_interface import InterfaceConfiguration from pprint import pprint import os os.environ['LB-TESTING'] = '0' #pprint(MakeList()) #if os.environ['LB-TESTING'] == '1': #appSettings = AppSettingsTest() #else: # appSettings = AppSettings() appSettings = AppSettings() #print('* appSettings') #pprint(appSettings) # out_file = TextFile(appSettings.getAppFolder(), '00.templates_gen.py') ####################### ## WRITE TEMPLATE CLASSES ##################### #print('cwd', os.getcwd()) out_file_list = [] out_file = TextFile(os.getcwd(), '00.templates_gen.py') out_file.append('import sys') out_file.append('print(sys.path)') out_file.append('import os') out_file.append('from pathlib import Path') out_file.append('import settings') out_file.append( 'print(\'os.getenv\', os.getenv(\'LB_WORKING_FOLDER_NAME\'))') out_file.append('print(\'change projects in .env\')') out_file.append('from templates import Template') out_file.append('from app_settings import AppSettings, AppSettingsTest') progeny = MakeAPIConfigurations() # gen api json files makeList = MakeList() #print('---- MakeList ---- ') #pprint(makeList) #exit(0) #pprint([makeList[f]['out-filename'] for f in makeList]) class_list = [] for _key in makeList: #print('key', _key) #class_list.append(self.getClassName(filename)) tmpl_file = TextFile(makeList[_key]['tmpl-folder'], makeList[_key]['tmpl-filename']).read() conf_file = TextFile(makeList[_key]['conf-folder'], makeList[_key]['conf-filename']).read() #print('key', _key, makeList[_key]['class-name']) class_list.append(makeList[_key]['class-name']) # use later out_file.append(' ') out_file.append('class {}(Template):'.format( makeList[_key]['class-name'])) out_file.append(' ') out_file.append(' def __init__(self):') out_file.append(' super().__init__({})') out_file.append(' ') out_file.append(' def process(self):') out_file.append(' super().process()') out_file.append(' print(\'{}\'.format(\'\\n\'.join(self)))') out_file.append( ' self.copy(self.getOutputFolder(), self.getOutputName())') out_file.append( ' self.permissions(self.getOutputFolder(), self.getOutputName())' ) out_file.append(' return self') out_file.append(' ') #out_file.append(' def getInputTemplate(self): return \'{}\''.format(makeList[_key]['conf-filename'])) out_file.append(' def getInputTemplate(self): return \'{}\''.format( makeList[_key]['tmpl-filename'])) #out_file.append(' def getTemplateSourceName(self): return \'{}\''.format(makeList[_key]['tmpl-filename'])) out_file.append(' def getOutputFolder(self): return \'{}\''.format( makeList[_key]['out-folder'])) out_file.append(' def getOutputName(self): return \'{}\''.format( makeList[_key]['out-filename'])) #out_file.append(' def getOutputFileName(self): return \'{}/{}\''.format(makeList[_key]['out-folder'], makeList[_key]['out-filename'])) print(' * ', makeList[_key]['out-filename'], '\t\t', makeList[_key]['out-folder']) #out_file_list.append('{} {}'.format(makeList[_key]['out-folder'], makeList[_key]['out-filename'])) out_file.append(' def getTemplateList(self):') out_file.append(' return \'\'\'') for ln in tmpl_file: # add lines from template out_file.append(ln) out_file.append('\'\'\'.split(\'\\n\')') out_file.append(' ') out_file.append(' def getDictionary(self):') out_file.append(' return \\') for ln in conf_file: # add lines from template out_file.append('\t\t\t{}'.format(ln)) out_file.append(' ') out_file.append('##########') out_file.append('##########') out_file.append('##########') out_file.append('def main():') # out_file.append(' if self.lbtesting = os.getenv(\'LB-TESTING\') or \'0\'') out_file.append(' appSettings = AppSettings()') out_file.append(' if \'LB-TESTING\' in os.environ:') out_file.append(' appSettings = AppSettingsTest()') for class_name in class_list: out_file.append(' {}()'.format(class_name)) out_file.append('if __name__ == "__main__":') out_file.append(' main()') out_file.write() print('output to ', out_file.getFolderName(), out_file.getFileName()) #showFolders() print('output files') pprint(makeList[_key]['out-filename']) os.environ['LB-TESTING'] = '0'
def cacheRoot(self): return os.path.join(AppSettings().cacheRoot, self.category)
def setUpClass(cls): if os.path.exists(AppSettings()._cacheRoot): shutil.rmtree(AppSettings()._cacheRoot)
value = args[0] if type(args) == list else args self.messaged.emit(value) ## Main app entry point if __name__ == "__main__": launch_notifier = LaunchWorker() #If we make it this far, there is no other instance running thread = QThread() worker = LaunchWorker() worker.moveToThread(thread) thread.started.connect(worker.run) thread.start() #Settings need to be loaded seperately AppInstance.settings = AppSettings() first_launch = AppInstance.settings.on_load() app = QApplication(sys.argv) if test_rpc_status(first_launch): AppInstance.on_init() #Finally init/run main window window = MainWindow() window.show() worker.messaged.connect(window.on_url_handled) logging.info("App Startup") error = None try:
@property def ftpRoot(self): return ftpPathNorm(self.ftpParams['root-dir']) @property def rootDir(self): return ftpJoin(self.ftpRoot, self._category) def checkExist(self, ftpPath): pass def upload(self, localPath, ftype='TXT'): if ftype == 'TXT': with open(localPath) as f: self.ftp.storlines('STOR ' + localPath, f) else: with open(localPath, 'rb') as f: self.ftp.storbinary('STOR ' + localPath, f, 1024) class FtpAudioManager(FtpManager): def __init__(self): FtpManager.__init__(self, 'audio') if __name__ == '__main__': AppSettings(AppMode.DEVELOP) manager = FtpAudioManager() manager.upload(r'C:\1.txt')
from django.db.models.signals import pre_save from .models import AfricasTalking, PhoneNumbers from app_settings import AppSettings phone_number_model = AppSettings().get_phone_number_model() # default configuration should always be one incase we have multiples def one_default(sender, instance, **kwargs): if instance.default is True: africastalking_objs = AfricasTalking.objects.all() for obj in africastalking_objs: if obj.default is True: obj.default = False obj.save() def one_phone_numbers_entry(sender, instance, **kwargs): latest_entry = PhoneNumbers.objects.last() if latest_entry: phone_numbers = latest_entry.phone_numbers old_phone_numbers = phone_numbers.split(',')[:-1] phone_number = ',%(phone_number)s' % dict(phone_number=instance.phone_number) new_phone_numbers = old_phone_numbers print type(new_phone_numbers) else: phone_number = '%(phone_number)s,' % dict(phone_number=instance.phone_number) PhoneNumbers.objects.create(phone_numbers=phone_number) pre_save.connect(one_default, sender=AfricasTalking)
def __init__(self, category=''): self._category = category self.ftpParams = AppSettings().ftpParams self.ftp = FTP(self.ftpParams['host']) self.login() self.garanteeExistPath(self.rootDir)