def run(self): sample1 = pickle.load( gzip.open(self.sampleobjfile1, "rb") ) sample2 = pickle.load( gzip.open(self.sampleobjfile2, "rb") ) print self.size, os.path.basename(self.sampleobjfile1).split('.')[0], sample1.total, os.path.basename(self.sampleobjfile2).split('.')[0], sample2.total #sampling "size" sequences from sample: subsample1 = iseqlib.samplingSample( sample1, self.size ) #sampled sample subsample2 = iseqlib.samplingSample( sample2, self.size ) #sampled sample #Get different statistics: stats = PairSamplingStats() #initialize stats for the current subsample #Find Sizes of the Union of clones between subsample1 and subsample2: counts1 = [] counts2 = [] for header, seq in subsample1.seqs.iteritems(): counts1.append( seq.count ) if header in subsample2.seqs: counts2.append( subsample2.seqs[header].count ) else: counts2.append( 0 ) for header, seq in subsample2.seqs.iteritems(): if header not in subsample1.seqs: counts1.append( 0 ) counts2.append( seq.count ) if len(counts1) != len(counts2): raise ValueError("The count vectors of two compared samples must have equal length. Found %d and %d\n" %(len(counts1), len(counts2))) ## Initialize the R interface import rpy2.rinterface as rinterface rinterface.set_initoptions(('rpy2', '--no-save')) rinterface.initr() import rpy2.robjects as robjs from rpy2.robjects.packages import importr vegan = importr('vegan') vegdist = vegan.vegdist counts = counts1 counts.extend(counts2) rcountsVec = robjs.IntVector( counts ) #convert python list into R vector rcountsMatrix = robjs.r['matrix'](rcountsVec, nrow = 2, byrow=True) #indices = ['bray', 'horn', 'mountford', 'chao'] indices = self.options.similarityIndices #"manhattan", "euclidean", "canberra", "bray", "kulczynski", "jaccard", "gower", "morisita", "horn", "mountford", "raup" , "binomial" or "chao" for index in indices: disimilarity = vegdist( rcountsMatrix, method=index ) stats[index] = disimilarity[0] #Write to temp file: picklefile = os.path.join( self.outdir, "%d.pickle" % self.id) pickle.dump( stats, gzip.open(picklefile, "wb") )
def run(self): sample = pickle.load( gzip.open(self.sampleobjfile, "rb") ) #sampling "size" sequences from sample: subsample = iseqlib.samplingSample( sample, self.size ) #sampled sample #Get different statistics: stats = SingleSamplingStats() #initialize stats for the current subsample #1/ Number of uniq clones: stats.uniqClones = len( subsample.seqs ) #2/ Diversity Indices counts = [ seq.count for seq in subsample.seqs.values() ] #list of clone sizes ## Initialize the R interface import rpy2.rinterface as rinterface rinterface.set_initoptions(('rpy2', '--no-save')) rinterface.initr() import rpy2.robjects as robjs from rpy2.robjects.packages import importr vegan = importr('vegan') rcounts = robjs.IntVector( counts ) #convert python list into R vector ##Diversity indices (Simpson, InverseSimpson, Shannon) indices = self.options.diversityIndices #['simpson', 'invsimpson', 'shannon'] for index in indices: if index == 'uniqClones' or index == 'fisherAlpha': continue rval = vegan.diversity( rcounts, index ) stats[index] = rval[0] ## Fisher Alpha: rfisher = vegan.fisher_alpha( rcounts ) stats.fisherAlpha = rfisher[0] #Write to temp file: picklefile = os.path.join( self.outdir, "%d.pickle" % self.id) pickle.dump( stats, gzip.open(picklefile, "wb") )
def ready(self) -> None: """Perform initialization for back-end""" logger.info(f"CATMAID version {settings.VERSION}") # Make sure all settings variables are of the type we expect. self.validate_configuration() # If prepared statements are enabled, make sure they are created for # every new connection. Binding this signal handler has to happen before # the first database connection is created or connection pooling can not # be used with prepared statements safely. if settings.PREPARED_STATEMENTS: db_signals.connection_created.connect(prepare_db_statements) self.check_superuser() # Make sure the existing version is what we expect signals.pre_migrate.connect(check_old_version, sender=self) # Validate CATMAID environment after all migrations have been run signals.post_migrate.connect(validate_environment, sender=self) # Register history checks register(check_history_setup) # Enable or disable spatial update notifications register(check_spatial_update_setup) # Make sure the expected default client instance settings are set. register(check_client_settings) # Test if output paths are accessible register(check_media_path) # Init R interface, which is used by some parts of CATMAID if r_available: rinterface.set_initoptions((b'rpy2', b'--no-save', b'--no-restore', b'--no-init-file', b'--no-environ')) rinterface.initr()
import rpy2.robjects as ro from rpy2.robjects.packages import importr import rpy2.rinterface as ri ri.set_initoptions(('rpy2', '--verbose', '--no-save')) ri.initr() graphics = importr('graphics') grdevices = importr('grDevices') base = importr('base') stats = importr('stats') zoo = importr('zoo') #Need to add params to importr as xts and quantmod have conflicts xts = importr("xts", robject_translations = {".subset.xts": "_subset_xts2", "to.period": "to_period2"}) quantmod = importr('quantmod', robject_translations = {"skeleton.TA": "skeleton_TA2"}) AORD = ro.r('read.table("~/Documents/R/StrategyTester/Data/AORD.csv",header=T, sep=",")') #WIP - using quantmod, zoo, xts in Python. #Create Zoo object #indexZoo = ro.r.rownames(AORD) AORD = zoo.as_zoo(AORD) AORD = xts.as_xts(AORD) #Create MA zoo object #Creating EMA using quantmod chartData = AORD#.rx['2008-02::2008-08'] quantmod.chartSeries(chartData, theme="white") EMA1=quantmod.addEMA(n=10,col=2)
import os import string import traceback import rpy2.rinterface as rinterface rinterface.set_initoptions(('rpy2', '--vanilla', '--max-ppsize=500000', '--quiet')) import numpy from subprocess import Popen, PIPE, STDOUT import dendropy import rpy2.robjects as robjects from rpy2.robjects.packages import importr import tempfile from dendropy.interop import ape import rpy2 from rpy2.robjects import numpy2ri import math import stopwatch import multiprocessing as mp from multiprocessing import Pool, current_process, Manager from threading import Timer import platform import random from itertools import izip #mp_logger = mp.log_to_stderr() #mp_logger.setLevel(mp.SUBDEBUG) import logging import pandas as pd import time
#!/usr/bin/env python from __future__ import division import gc, sys, operator, scipy, datetime, multiprocessing, traceback from scipy.special import comb import talib as tl import rpy2.rinterface as rinterface rinterface.set_initoptions(('rpy2', '--max-ppsize=500000')) rinterface.initr() from rpy2 import robjects as ro from rpy2.robjects import r from rpy2.robjects.packages import importr #import analysis.model_learning as ml import data.stock_data_store as sd import numpy as np import utils.data_util as du s = sd.StockDataStore() global_ticker_data = dict() counter = multiprocessing.Value("i", 0) total = multiprocessing.Value("i", 0) start_time = None lock = multiprocessing.Lock() def get_time_left(start_time, num_complete, total): dtime = datetime.datetime.now() - start_time time_per_ticker = dtime.total_seconds() / num_complete diff = total - num_complete return datetime.timedelta(seconds=int(time_per_ticker * diff))
#!/usr/bin/env python from __future__ import division import gc, sys, operator, scipy, datetime, multiprocessing, traceback from scipy.special import comb import talib as tl import rpy2.rinterface as rinterface rinterface.set_initoptions(('rpy2', '--max-ppsize=500000')) rinterface.initr() from rpy2 import robjects as ro from rpy2.robjects import r from rpy2.robjects.packages import importr #import analysis.model_learning as ml import data.stock_data_store as sd import numpy as np import utils.data_util as du s = sd.StockDataStore() global_ticker_data = dict() counter = multiprocessing.Value("i", 0) total = multiprocessing.Value("i", 0) start_time = None lock = multiprocessing.Lock() def get_time_left(start_time, num_complete, total): dtime = datetime.datetime.now() - start_time time_per_ticker = dtime.total_seconds() /num_complete diff = total - num_complete return datetime.timedelta(seconds=int(time_per_ticker * diff))
# -*- coding: utf-8 -*- """ Created on Thu Mar 02 11:38:19 2017 ***** IT IS REALLY IMPORTANT TO NOTE THE RANGE OF CONFIGURABLES BELOW ***** @author: me """ import os os.environ['R_HOME'] = 'C:/Progra~1/R/R-3.3.2/' os.environ['R_USER'] = '******' #os.environ['R_HOME']='C:\\Program Files\\R\\R-3.3.2\\bin\\x64\\' import rpy2.rinterface as ri try: ri.set_initoptions(('rpy2', '--verbose', '--no-save')) ri.initr() except RuntimeError: pass lib_path = "'C:/Users/WINUSER/Documents/R/win-library/3.3'" from rpy2.robjects import pandas2ri pandas2ri.activate() import pandas.rpy.common as common #This module will get deprecated at some point.... import rpy2.robjects as ro import numpy as np import pandas as pd print ro.r(".libPaths(c(.libPaths()," + lib_path + "))")
def testSet_initoptions(self): with self.assertRaises(RuntimeError): rinterface.set_initoptions(('aa', '--verbose', '--no-save'))