def latex_mean_low_up(mean, low, up, sig=2): #latexstr = "%.10f_{-%.10f}^{+%.10f}" % (mean,low,up) f_low, round_to1 = utils.round_sig(low, return_round_to=True, sig=sig) f_up, round_to2 = utils.round_sig(up, return_round_to=True, sig=sig) round_to = max(round_to1, round_to2) f_mean = round(mean, round_to) latexstr = "$%s_{-%s}^{+%s}$" % (f_mean, f_low, f_up) return latexstr
def pheno_pathway_assoc_row_generator(): # doesn't output primary key, let's sqlite3 auto-increment instead for i, (phecode, genesettype) in enumerate(itertools.product(phecodes, genesettypes)): phecode_id = phecode_ids[phecode] filename = 'PheCode_{}_{}.wConditional.txt.gz'.format(phecode, genesettype) print(i, filename) with read_maybe_gzip(pheno_dir_path / filename, 'rt') as f: for i, line in enumerate(f): try: parts = line.split() if len(parts) == 6: # This is the normal format, with 2 unused columns name, url, pval_string, _, selected_genes_string, _ = line.split() elif len(parts) == 4: # This is the trimmed format without the 2 unused columns name, url, pval_string, selected_genes_string = line.split() else: raise Exception("wrong number of columns") if pval_string == 'NA' and selected_genes_string == 'NA': # I don't know why these lines exist but there's a lot of them. continue selected_genes = selected_genes_string.split(',') try: assert name in pathways, line assert pathways[name]['url'] == url, line assert 0 <= float(pval_string) <= 1, line assert 1 <= len(selected_genes) < 20e3, line assert all(g in pathways[name]['genes'] for g in selected_genes), line except Exception: raise Exception(line) pval = round_sig(float(pval_string), 3) yield (phecode_id, pathway_ids[name], pval, selected_genes_string) except Exception as exc: raise Exception("Failed on line {} of file {} which is {}".format(i, pheno_dir_path/filename, repr(line))) from exc
def pheno_gene_assoc_row_generator(): for phecode, pheno_id in phecode_ids.items(): print(' - reading pheno#{}: {}'.format(pheno_id, phecode)) filepath = '../input_data/genes/OUTF_PheCode_{}.txt.gz'.format(phecode) with read_maybe_gzip(filepath, 'rt') as f: delimiter = '\t' if '\t' in next(f) else ' ' with read_maybe_gzip(filepath, 'rt') as f: for i, row in enumerate(csv.reader(f, delimiter=delimiter)): try: if len(row) == 2: gene, pval_str = row elif len(row) == 8: gene, pval_str = row[0], row[4] else: raise Exception( "Wrong number of parts in line {} of file {} which is {}" .format(i, filepath, repr(row))) except ValueError as exc: raise Exception( "Failed on line {} of file {} which is {}".format( i, filepath, repr(row))) from exc if gene in gene_ids and pval_str != "NA": pval = round_sig(float(pval_str), 3) assert 0 <= pval <= 1 yield (pheno_id, gene_ids[gene], pval)
def latex_mean(mean, std, sig=2): #latexstr = "%.10f_{-%.10f}^{+%.10f}" % (mean,low,up) f_std, round_to = utils.round_sig(std, return_round_to=True, sig=sig) f_mean = round(mean, round_to) latexstr = "$%s \pm %s$" % (f_mean, f_std) return latexstr
text_file = open("output.txt", "w") print("-------------") if min_n == -1: print("gd = ", gd, " not found") else: print("t0 = ", t0, "n =", min_n) # Ahora checkeamos si cumple la condicion b.calcular(min_n) mag, pha = b.evaluarAproximacion(fa) at = -mag mag, pha = b.evaluarAproximacion(fp) at_fp = -mag gd = b.evaluarRetardoDeGrupo(fp, fp * 0.001) * 1000 if at > 40: print("Gd(fp) = ", round_sig(gd, 4), "ms At(fp) = ", round_sig(at_fp, 4), " At(fa) = ", round_sig(at, 4), " Cumple") print("H(s) = ", etapas.getFacto2orderExpression(b.tf)) print("coef = ", b.coef) else: print("Gd(fp) = ", round_sig(gd, 4), " ms At(fp) = ", round_sig(at_fp, 4), "At(fa) = ", round_sig(at, 4)) print("H(s) = ", etapas.getFacto2orderExpression(b.tf)) print("coef = ", b.coef)
def plot_moments(self, title='moment diagram', figsize=(10, 4), scale=1, steps=10, fontsize=12, round=3): scale = scale * np.max(self.elements['L']) / 3 / np.max( np.abs(self.moment)) relativeOffset = scale * np.max(self.elements['L']) fig, ax = plt.subplots(figsize=figsize) ax.grid(which='major', linestyle=':', linewidth='0.5', color='black') element_summary = [] for i in range(len(self.elements)): #elements x_el = [ utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'x'), utils.df_value(self.nodes, self.elements['n2'][i], 'name', 'x') ] y_el = [ utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'y'), utils.df_value(self.nodes, self.elements['n2'][i], 'name', 'y') ] ax.plot(x_el, y_el, '-', linewidth=3, marker='o', color='black') #moments x1, x2, y1, y2 = elmCoord(self.elements, self.nodes, i) s = (y2 - y1) / self.elements['L'][i] c = (x2 - x1) / self.elements['L'][i] if self.elements['name'][i] in self.forces_distributed[ 'element'].values: x_mom = [x_el[0]] y_mom = [y_el[0]] moments = [] L = self.elements['L'][i] steps = steps w1 = utils.df_value(self.forces_distributed, self.elements['name'][i], 'element', 'n1') w2 = utils.df_value(self.forces_distributed, self.elements['name'][i], 'element', 'n2') for j in range(0, steps + 1): x = L / steps * j w2_temp = w1 + (w2 - w1) * x / L # area=np.trapz([w1,w2_temp], x=[0,L]) # leverarm = w2_temp-utils.centroidX([[0,w1],[x,w2_temp]]) area = (w1 + w2_temp) / 2 * x if area != 0: leverarm = (w1 * x**2 / 2 + (w2_temp - w1) * x**2 / 6) / area else: leverarm = 0 moment = -(-self.moment[i * 2] + self.shear[i * 2] * x + area * leverarm) #upsidedown moments moments.append(moment) x_mom.append( utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'x') + x + moment * s * scale) y_mom.append( utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'y') + moment * c * scale) # x_mom.append(utils.df_value(self.nodes,self.elements['n2'][i],'name','x')+s*self.moment[i*2+1]*scale) # y_mom.append(utils.df_value(self.nodes,self.elements['n2'][i],'name','y')+c*self.moment[i*2+1]*scale) x_mom.append(x_el[1]) y_mom.append(y_el[1]) ax.text(x_mom[1] + relativeOffset * c, y_mom[1] + utils.matchSign(relativeOffset, y_mom[1]), utils.round_sig(moments[0], round), fontsize=fontsize) ax.text(x_mom[-2] - 4 * relativeOffset * c, y_mom[-2] + utils.matchSign(relativeOffset, y_mom[-2]), utils.round_sig(moments[-1], round), fontsize=fontsize) if utils.maxAbs(moments[0], moments[-1]) > 0: indice = min( (val, idx) for (idx, val) in enumerate(moments))[1] else: indice = max( (val, idx) for (idx, val) in enumerate(moments))[1] ax.text(x_mom[indice + 1], y_mom[indice] + utils.matchSign(relativeOffset, y_mom[indice + 1]), utils.round_sig(moments[indice], round), fontsize=fontsize) element_summary.append([ self.elements['name'][i], utils.round_sig(moments[0], round), utils.round_sig(moments[-1], round), utils.round_sig(moments[indice], round), self.shear[i * 2], self.shear[i * 2 + 1] ]) else: x_mom = [ x_el[0], utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'x') + s * self.moment[i * 2] * scale, utils.df_value(self.nodes, self.elements['n2'][i], 'name', 'x') - s * self.moment[i * 2 + 1] * scale, x_el[1] ] y_mom = [ y_el[0], utils.df_value(self.nodes, self.elements['n1'][i], 'name', 'y') + c * self.moment[i * 2] * scale, utils.df_value(self.nodes, self.elements['n2'][i], 'name', 'y') - c * self.moment[i * 2 + 1] * scale, y_el[1] ] ax.text(x_mom[1] + relativeOffset * c, y_mom[1] + utils.matchSign(relativeOffset, y_mom[1]), utils.round_sig(self.moment[i * 2], round), fontsize=fontsize) ax.text(x_mom[-2] - 4 * relativeOffset * c, y_mom[-2] + utils.matchSign(relativeOffset, y_mom[-2]), utils.round_sig(self.moment[i * 2 + 1], round), fontsize=fontsize) element_summary.append([ self.elements['name'][i], utils.round_sig(self.moment[i * 2], round), utils.round_sig(self.moment[i * 2 + 1], round), (utils.round_sig(self.moment[i * 2], round) + utils.round_sig(self.moment[i * 2 + 1], round)) / 2, self.shear[i * 2], self.shear[i * 2 + 1] ]) ax.plot(x_mom, y_mom, '-', linewidth=2, marker='', color='blue') self.element_summary = pd.DataFrame( element_summary, columns=['name', 'm1', 'm2', 'mMid', 'S1', 'S2']) plt.axis('equal') ax.set_title(title) plt.show()