def driver(image_file, algorithm, binary_threshold, canny_low, canny_high, window_height, window_width, tracking, gap, repeat, transpose, debug, quiet): align = Alignment(image_file) params = { 'binary_threshold': binary_threshold, 'canny_thresh_low': canny_low, 'canny_thresh_high': canny_high, 'window_height': window_height, 'window_width' : window_width, 'gap': gap, 'transpose': transpose, 'debug': debug, 'quiet': quiet } if tracking: tracking(params, algorithm, repeat) elif algorithm: print(align.compute_center(algorithm, params));
def parseContents(contents, section): if section==1: readNames = [] contained = {} for line in contents: if line[0]!=' ': readNames.append(line.strip()) else: tokens = line.strip().split() readNames.append(tokens[0]) contained[tokens[0]] = tokens[-1] return readNames, contained elif section==2: aln = Alignment() iSeqStart = -1 L = 0 for line in contents: if line==Tokens.ruler: # Ruler line iSeqStart = line.find('.')-4 # = 22 ??? if iSeqStart!=22: print "!!! iSeqStart:", iSeqStart elif line[0]==' ': # Separator line pass else: line = line.rstrip() name = line[0:iSeqStart].strip() seq = line[iSeqStart:] if name!='consensus': if not name in aln.seqDict: seq = seq.replace(' ', '.') seq = '.'*L + seq aln.append(name, seq) else: aln.append(name, seq) L = len(aln['consensus']) # Pad short sequences with '.' for name in aln: aln[name] = aln[name] + '.'*(L-len(aln[name])) return aln else: raise Exception("cap3.parseContents")
def constrain_mutant_to_wt(mutant_pose, wt_pose, mut_focus_residues, wt_focus_residues, constrain=True, shell=6): aligner = Alignment(mutant_pose, wt_pose) # Get chain info (this is a roundabout way of getting this and # should probably be refactored at some point.) # Initially this just used the Rosetta chain, but (older?) versions # of PyRosetta do not seem to support that. tchain = mutant_pose.pdb_info().chain(mut_focus_residues[0]) mchain = wt_pose.pdb_info().chain(wt_focus_residues[0]) # Create a selection shell aligner.create_shell(shell, mut_focus_residues, mobile_focus_list=wt_focus_residues, tchain=tchain, mchain=mchain) aligner.match_align() if constrain: alignment_dict = {} assert (len(mut_focus_residues) == len(wt_focus_residues)) for i in range(0, len(mut_focus_residues)): alignment_dict[(wt_focus_residues[i], mut_focus_residues[i])] = ['N', 'C', 'CA'] csts = constraints_from_pose(aligner.mobile, aligner.target, alignment_dict) for cst in csts: aligner.target.add_constraint(cst) return aligner
#!/usr/bin/env python """ stockholm2phylip.py <stockholm filename> <phylip filename> Author: Tony Papenfuss Date: Sun May 6 13:34 EST 2007 """ import os, sys from align import Alignment iFilename = sys.argv[1] oFilename = sys.argv[2] alignment = Alignment.loadStockholm(iFilename) for name in alignment: alignment[name] = alignment[name].replace('.', '-') alignment.savePhylip(oFilename)
def main(): # m = examples["diff"] # print PermanentSampler(0.5,0.1).estimate_permanent(m) # r_perm = ryser(m) # #n_perm = naive_permanent(m) # print r_perm # #print n_perm from align import Align from align import Alignment import sys mode = model_names[sys.argv[3]] align = Align.from_files("data/eng-fr.full.fr", "data/eng-fr.full.en") e_types, f_types = align.types() prob_model = dist.ProbModel(f_types, e_types) test_align = Align.from_files("data/eng-fr.dev.fr", "data/eng-fr.dev.en", True) gold_align = Alignment.read_alignments("data/eng-fr.dev.align") if sys.argv[1] == "train": dists = prob_model.rand_dists_sparse() instances = align.instances() test_instances = test_align.instances() for r in range(20): if mode == MANYTOONE: score, _ = dev_assess(test_instances, gold_align, dists, prob_model, viterbi_align_manyone) else: score, _ = dev_assess(test_instances, gold_align, dists, prob_model, viterbi_align_oneone) dists = em(instances, dists, mode, prob_model) #print "Dist 'le'" #for i, lscore in enumerate(dists['le']): # if lscore > 1e-4: # print i, align.eng_to_ind(i), lscore print "Score is:", score final_dist = dists pickle.dump(final_dist, open(sys.argv[2], 'wb')) elif sys.argv[1] == "test": dists = pickle.load(open(sys.argv[2], 'rb')) instances = test_align.instances() if mode == MANYTOONE: score, alignments = dev_assess(instances, gold_align, dists, prob_model, viterbi_align_manyone) else: score, alignments = dev_assess(instances, gold_align, dists, prob_model, viterbi_align_oneone) print score f_out = open("out.f", 'w') e_out = open("out.e", 'w') a_out = open("out.a", 'w') gold_out = open("out.gold.a", 'w') for ins, align in zip(instances, alignments): print >> f_out, " ".join(ins.f) print >> e_out, " ".join(ins.e) print >> a_out, " ".join([str(e) + "-" + str(f) for e, f in align]) print >> gold_out, " ".join( [str(e) + "-" + str(f) for e, f in gold_align[ins.num]])
import cv2 from align import Alignment X = Alignment() def read(path): img = cv2.imread(path) height = img.shape[0] width = img.shape[1] ratio = height / width return cv2.resize(img, (int(500 * ratio), 500)) def draw_rec(event, x, y, flags, param): global ix, iy, ex, ey, drawing, mode if event == cv2.EVENT_LBUTTONDOWN: ix, iy = x, y elif event == cv2.EVENT_LBUTTONUP: ex, ey = x, y def get_crop_size(image): cv2.namedWindow('draw_rectangle') cv2.setMouseCallback('draw_rectangle', draw_rec, image) print("Choose your area of interest!") while 1: cv2.imshow('draw_rectangle', image) k = cv2.waitKey(1) & 0xFF if k == ord('a'):
def tracking(params, algorithm='pin', repeat=1): #### ENABLE TAB COMPLETION readline.parse_and_bind('tab: complete') ################################################# pixel_size = 1.172 ## um / pixel slit_center_x = 1000 slit_center_y = 600 ################################################# ### MOTOR SETTINGS ################################################# mtr_samXE = PyEpics.Motor('1ide1:m34') mtr_samYE = PyEpics.Motor('1ide1:m35') mtr_samZE = PyEpics.Motor('1ide1:m36') mtr_samTh = PyEpics.Motor('1ide1:m86') mtr_samChi = PyEpics.Motor('1ide1:m87') mtr_samOme = PyEpics.Motor('1ide:m9') mtr_aeroXE = PyEpics.Motor('1ide1:m101') mtr_aeroZE = PyEpics.Motor('1ide1:m102') ################################################# pname = '/home/beams/S1IDUSER/mnt/s1c/mli_nov19/tomo' for i in range(repeat): ################################################# ### ALIGN ROTATION AXIS TO THE HS ################################################# ### MOVE STAGE TO 0 mtr_samOme.move(0, wait=True) ### TAKE AN IMAGE AT OME 0 PyEpics.caput('1idPG1:cam1:Acquire', 1) time.sleep(3) fname = PyEpics.caget('1idPG1:TIFF1:FileName_RBV', 'str') + "_%06d" % ( PyEpics.caget('1idPG1:TIFF1:FileNumber_RBV') - 1) + '.tif' pfname = os.path.join(pname, fname) print(pfname) align0 = Alignment(pfname) x0, y0 = align0.compute_center(algorithm, params) print(f"pin x,y position when omega is 0 : (x = {x0}, y = {y0}") if (x0 == -1) or (y0 == -1): print("Alignment failed at zero degress") break ### MOVE STAGE TO 180 mtr_samOme.move(180, wait=True) ### TAKE AN IMAGE AT OME 180 PyEpics.caput('1idPG1:cam1:Acquire', 1) time.sleep(3) fname = PyEpics.caget('1idPG1:TIFF1:FileName_RBV', 'str') + "_%06d" % ( PyEpics.caget('1idPG1:TIFF1:FileNumber_RBV') - 1) + '.tif' pfname = os.path.join(pname, fname) align180 = Alignment(pfname) x180, y180 = align180.compute_center(algorithm, params) if (x180 == -1) or (y180 == -1): print("Alignment failed at 180 degrees") break print(f"pin x,y position when omega is 180 : (X = {x180}, y = {180})") ### COMPUTE MOTIONS TO MAKE mid_x = (x180 + x0) / 2 half_delta_x = (x180 - x0) / 2 print(mid_x) print(half_delta_x) ### NEED TO CHECK / FIGURE OUT THE SIGNS ON THESE aeroXE_motion = ((mid_x - slit_center_x) * pixel_size) / 1000 samXE_motion = -(half_delta_x * pixel_size) / 1000 print('motions to execute') print(aeroXE_motion) print(samXE_motion) mtr_aeroXE.move(aeroXE_motion, relative=True, wait=True) mtr_samXE.move(samXE_motion, relative=True, wait=True)
def main(): # m = examples["diff"] # print PermanentSampler(0.5,0.1).estimate_permanent(m) # r_perm = ryser(m) # #n_perm = naive_permanent(m) # print r_perm # #print n_perm from align import Align from align import Alignment import sys mode = model_names[sys.argv[3]] align = Align.from_files("data/eng-fr.full.fr","data/eng-fr.full.en") e_types, f_types = align.types() prob_model = dist.ProbModel(f_types, e_types) test_align = Align.from_files("data/eng-fr.dev.fr","data/eng-fr.dev.en", True) gold_align= Alignment.read_alignments("data/eng-fr.dev.align") if sys.argv[1] == "train": dists = prob_model.rand_dists_sparse() instances = align.instances() test_instances = test_align.instances() for r in range(20): if mode == MANYTOONE: score,_ = dev_assess(test_instances, gold_align, dists, prob_model, viterbi_align_manyone) else: score,_ = dev_assess(test_instances, gold_align, dists, prob_model, viterbi_align_oneone) dists = em(instances, dists, mode, prob_model) #print "Dist 'le'" #for i, lscore in enumerate(dists['le']): # if lscore > 1e-4: # print i, align.eng_to_ind(i), lscore print "Score is:", score final_dist = dists pickle.dump(final_dist, open(sys.argv[2], 'wb')) elif sys.argv[1] == "test": dists = pickle.load(open(sys.argv[2], 'rb')) instances = test_align.instances() if mode == MANYTOONE: score,alignments = dev_assess(instances, gold_align, dists, prob_model, viterbi_align_manyone) else: score,alignments = dev_assess(instances, gold_align, dists, prob_model, viterbi_align_oneone) print score f_out = open("out.f", 'w') e_out = open("out.e", 'w') a_out = open("out.a", 'w') gold_out = open("out.gold.a", 'w') for ins,align in zip(instances,alignments): print >>f_out, " ".join( ins.f) print >>e_out, " ".join(ins.e) print >>a_out, " ".join([str(e)+"-"+str(f) for e, f in align]) print >>gold_out, " ".join([str(e)+"-"+str(f) for e, f in gold_align[ins.num]])