void replicateAllOrig(const EncryptedArray& ea, const Ctxt& ctxt, ReplicateHandler *handler, RepAux* repAuxPtr) { long nSlots = ea.size(); long n = GreatestPowerOfTwo(nSlots); // 2^n <= nSlots Ctxt ctxt1 = ctxt; if ((1L << n) < nSlots) SelectRange(ea, ctxt1, 0, 1L << n); RepAux repAux; if (repAuxPtr==NULL) repAuxPtr = &repAux; recursiveReplicate(ea, ctxt1, n, n, 0, 1L << n, *repAuxPtr, handler); if ((1L << n) < nSlots) { ctxt1 = ctxt; SelectRange(ea, ctxt1, 1L << n, nSlots); ea.rotate(ctxt1, -(1L << n)); recursiveReplicate(ea, ctxt1, n, n, 1L << n, nSlots, *repAuxPtr, handler); } }
// // Mouse click handler for target tree. // void CPageDisk::OnClickTTargets(NMHDR * pNMHDR, LRESULT * pResult) { CPoint point; TV_HITTESTINFO test_info; TargetSelType state; // Get the cursor position. GetCursorPos(&point); test_info.pt = point; m_TTargets.ScreenToClient(&(test_info.pt)); // Check to see whether the cursor is on an item. m_TTargets.HitTest(&test_info); // Check that we have an disk item. if (!test_info.hItem) return; // A new target assignment is being made. Clear the results since they are // for a configuration we no longer have. theApp.pView->ResetDisplayforNewTest(); // Toggle the selection if the control key is pressed. if (GetKeyState(VK_CONTROL) & 0x8000 && GetSelectionCheck(test_info.hItem) == TargetChecked) { state = TargetUnChecked; } else { state = TargetChecked; } switch (theApp.pView->m_pWorkerView->GetSelectedType()) { case WORKER: case MANAGER: // A shift click extends the selection from the last selected item // to the currently focused item. When the control key is also // pressed, any previous selection is not cleared. if ((GetKeyState(VK_SHIFT) & 0x8000) && selected) { // We have a previous item (not the first click) and the shift // key is down. SelectRange(selected, test_info.hItem, !(GetKeyState(VK_CONTROL) & 0x8000)); } else if (GetKeyState(VK_CONTROL) & 0x8000) { // The control key is down. SelectRange(test_info.hItem, test_info.hItem, FALSE, state); } else { SelectRange(test_info.hItem, test_info.hItem, TRUE, state); } break; default: ErrorMessage("Unexpected selection type in CPageNetwork::" "OnClickTTargets()."); return; } // immediately refresh the display (create/delete NetClients as needed) StoreTargetSelection(); *pResult = 0; }
// selects range of slots [lo..hi) static void SelectRange(const EncryptedArray& ea, Ctxt& ctxt, long lo, long hi) { ZZX mask; SelectRange(ea, mask, lo, hi); ctxt.multByConstant(mask); }
void CDDBaseGrid::SelectRow(long row) { if (row >= 0 && row < GetNumberRows() && GetNumberCols() > 0) { SetMultiSelectMode(TRUE); GotoRow(row); SelectRange(0, row, (GetNumberCols() - 1), row); } }
// // Multi selection keyboard handler for the tree control. // void CPageDisk::KeyMultiSel( WORD wVKey ) { BOOL shift = GetKeyState( VK_SHIFT ) & 0x8000; BOOL control = GetKeyState( VK_CONTROL ) & 0x8000; // Make sure there are disks. if ( !highlighted ) return; switch ( wVKey ) { case VK_UP: if ( !selected && shift ) selected = highlighted; SetFocusUp(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_DOWN: if ( !selected && shift ) selected = highlighted; SetFocusDown(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_HOME: if ( !selected && shift ) selected = highlighted; SetFocusHome(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_END: if ( !selected && shift ) selected = highlighted; SetFocusEnd(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_SPACE: if ( shift ) { // Extend the selection. Clear any other items if the control // key is not pressed. SelectRange( selected, highlighted, !control, TargetChecked ); } else if ( control ) // toggle. { // Toggle the selection, but do not clear any other items. if ( GetSelectionCheck( highlighted ) == TargetChecked ) { SelectRange( highlighted, highlighted, FALSE, TargetUnChecked ); } else { SelectRange( highlighted, highlighted, FALSE, TargetChecked ); } } else // normal { // Select only the highlighted item and clear any other. SelectRange( highlighted, highlighted, TRUE, TargetChecked ); } ShowFocus(); StoreTargetSelection(); break; case 'A': if ( control ) { SetAllCheck( TargetChecked ); StoreTargetSelection(); } } }
void wxVListBox::DoHandleItemClick(int item, int flags) { // has anything worth telling the client code about happened? bool notify = false; if ( HasMultipleSelection() ) { // select the iteem clicked? bool select = true; // NB: the keyboard interface we implement here corresponds to // wxLB_EXTENDED rather than wxLB_MULTIPLE but this one makes more // sense IMHO if ( flags & ItemClick_Shift ) { if ( m_current != wxNOT_FOUND ) { if ( m_anchor == wxNOT_FOUND ) m_anchor = m_current; select = false; // only the range from the selection anchor to new m_current // must be selected if ( DeselectAll() ) notify = true; if ( SelectRange(m_anchor, item) ) notify = true; } //else: treat it as ordinary click/keypress } else // Shift not pressed { m_anchor = item; if ( flags & ItemClick_Ctrl ) { select = false; if ( !(flags & ItemClick_Kbd) ) { Toggle(item); // the status of the item has definitely changed notify = true; } //else: Ctrl-arrow pressed, don't change selection } //else: behave as in single selection case } if ( select ) { // make the clicked item the only selection if ( DeselectAll() ) notify = true; if ( Select(item) ) notify = true; } } // in any case the item should become the current one if ( DoSetCurrent(item) ) { if ( !HasMultipleSelection() ) { // this has also changed the selection for single selection case notify = true; } } if ( notify ) { // notify the user about the selection change SendSelectedEvent(); } //else: nothing changed at all }
// // Single selection keyboard handler for the tree control. // void CPageNetwork::KeySingleSel(WORD wVKey) { BOOL shift = GetKeyState(VK_SHIFT) & 0x8000; BOOL control = GetKeyState(VK_CONTROL) & 0x8000; // Make sure there are interfaces. if (!highlighted) return; switch (wVKey) { case VK_UP: SetFocusUp(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_DOWN: SetFocusDown(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_HOME: SetFocusHome(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_END: SetFocusEnd(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_SPACE: if (control) // toggle. { // Toggle the selection, but do not clear any other items. if (GetSelectionCheck(highlighted) == TargetChecked) { SelectRange(highlighted, highlighted, FALSE, TargetUnChecked); } else { SelectRange(highlighted, highlighted, FALSE, TargetChecked); } } else // normal selection. { // Extend the selection and clear any other items. SelectRange(highlighted, highlighted, TRUE, TargetChecked); } ShowFocus(); StoreTargetSelection(); break; } ShowSettings(); EnableWindow(); }
int main (int argc, char **argv) { puts("Program starts"); /* Checking command line, throw exception if not complete */ //printf("%s %s %s %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); if (argc != 12) { printf("\nUsage: %s <input file 1.pdb> <input file 2.pdb> <output file> <chain1> <chain2> <start1> <end1> <start2> <end2> <file name for score> <is on server>", argv[0]); printf("\nExample: %s 3hdd.pdb 1puf.pdb superpos_3hdd_1puf.pdb A B 5 60 zero inf max_score.txt 0\n\n", argv[0]); exit (1); } /* end if */ /* Done checking command line */ /* Reading command line arguments */ char *infile1, *infile2, *outfile, *max_score_filename; char *start1, *end1, *start2, *end2; char chain1, chain2; unsigned int SERVER; infile1 = (char *)malloc( sizeof(char)*(strlen(argv[1])+1) ); sscanf(argv[1],"%s", infile1); infile2 = (char *)malloc( sizeof(char)*(strlen(argv[2])+1) ); sscanf(argv[2],"%s", infile2); outfile = (char *)malloc( sizeof(char)*(strlen(argv[3])+1) ); sscanf(argv[3], "%s", outfile); sscanf(argv[4], "%c", &chain1); sscanf(argv[5], "%c", &chain2); start1 = (char *)malloc( sizeof(char)*(strlen(argv[6])+1) ); end1 = (char *)malloc( sizeof(char)*(strlen(argv[7])+1) ); start2 = (char *)malloc( sizeof(char)*(strlen(argv[8])+1) ); end2 = (char *)malloc( sizeof(char)*(strlen(argv[9])+1) ); sscanf(argv[6], "%s", start1); sscanf(argv[7], "%s", end1); sscanf(argv[8], "%s", start2); sscanf(argv[9], "%s", end2); max_score_filename = (char *)malloc( sizeof(char)*(strlen(argv[10])+1) ); sscanf(argv[10], "%s", max_score_filename); sscanf(argv[11], "%u", &SERVER); /* Done reading arguments */ /* DECLARATION AND ASSIGNMENT OF SOME VARIABLES */ struct atom *atoms_prot1 = NULL, *atoms_prot2 = NULL; struct atom *all_atoms_dna1 = NULL, *all_atoms_dna2 = NULL; struct atom *atoms_wat1 = NULL, *atoms_wat2 = NULL; struct atom *atoms_prot_CA1 = NULL, *atoms_prot_CA2 = NULL; struct atom *atoms_prot_C1 = NULL, *atoms_prot_C2 = NULL; struct atom *atoms_prot_i1 = NULL, *atoms_prot_i2 = NULL; struct atom *atoms_prot_j1 = NULL, *atoms_prot_j2 = NULL; struct atom *C_atoms_prot_i1 = NULL, *C_atoms_prot_j2 = NULL; struct atomname *list1, *list2; unsigned int maxnumber = 256; //primary number of atoms in each groups (DNA, protein, water) FILE *flow_out; unsigned int all_m1=0, n1=0, w1=0, i, j, all_m2=0, n2=0, w2=0; /* m - number of DNA atoms * n - number of protein atoms * w - number of water atoms */ char *dna_chains1 = (char *)malloc( sizeof(char)*(2+1) ); char *prot_chains1 = (char *)malloc( sizeof(char)*(2+1) ); char *dna_chains2 = (char *)malloc( sizeof(char)*(2+1) ); char *prot_chains2 = (char *)malloc( sizeof(char)*(2+1) ); /*** For server ***/ FILE *max_score; //printf("%s", max_score_filename); max_score = fopen(max_score_filename, "w"); if (max_score == NULL) { perror(max_score_filename); exit(1); } /* Reading PDB file */ puts("Reading 1st PDB file..."); readerPDB(infile1, &all_m1, &n1, &w1, maxnumber, &all_atoms_dna1, &dna_chains1, &atoms_prot1, &prot_chains1, &atoms_wat1, &list1); // pdb.c function, read PDB and put protein, DNA and water atoms in three different arrays printf("...done; %d atoms of dna, %d atoms of protein, %d atoms of water\n", all_m1, n1, w1); if (all_m1 == 0) {fprintf(max_score, "Error\nFirst structure has no DNA!"); exit(1); } if (chain1=='@') chain1 = prot_chains1[1]; else if ( inArray(chain1, prot_chains1)==0 ) { fprintf(max_score, "Error\nChain %c is not a protein chain in first structure", chain1); exit(1); } SelectChain(atoms_prot1, n1, &atoms_prot1, &n1, chain1); SelectRange(atoms_prot1, n1, &atoms_prot1, &n1, start1, end1); // pdb.c function printf("Atoms in selected chain: %u\n\n", n1); // print to stdout number of protein atoms in selected chain puts("Reading 2nd PDB file..."); readerPDB(infile2, &all_m2, &n2, &w2, maxnumber, &all_atoms_dna2, &dna_chains2, &atoms_prot2, &prot_chains2, &atoms_wat2, &list2); printf("...done; %d atoms of dna, %d atoms of protein, %d atoms of water\n", all_m2, n2, w2); if (all_m2 == 0) {fprintf(max_score, "Error\nSecond structure has no DNA!"); exit(1); } if (chain2=='@') chain2 = prot_chains2[1]; else if ( inArray(chain2, prot_chains2)==0 ) { fprintf(max_score, "Error\nChain %c is not a protein chain in second structure!", chain2); exit(1); } SelectChain(atoms_prot2, n2, &atoms_prot2, &n2, chain2); SelectRange(atoms_prot2, n2, &atoms_prot2, &n2, start2, end2); printf("Atoms in selected chain: %u\n\n", n2); dna_chains1[0] = ' '; dna_chains2[0] = ' '; /*** For server ***/ char dna_chain1, dna_chain2; //dna_chain2 = dna_chains2[1]; printf("DNA1 chains: %s; DNA2 chains: %s\n", dna_chains1, dna_chains2); /* Done reading */ /*** 3DNA block ***/ unsigned int *compl_list1, *compl_list2, n_pairs1, n_pairs2, pair1, pair2; int **compl_pairs1, **compl_pairs2; char **pairs1, **pairs2; run_3dna(infile1, &compl_list1, &compl_pairs1, &pairs1, &n_pairs1, SERVER, max_score_filename); run_3dna(infile2, &compl_list2, &compl_pairs2, &pairs2, &n_pairs2, SERVER, max_score_filename); /*** 3DNA block end ***/ /*** MAIN FOR CYCLE ***/ struct atom *best_atoms_dna1 = NULL, *best_atoms_dna2 = NULL; struct atom *best_dna1_chain1, *best_dna1_chain2, *best_dna2_chain1, *best_dna2_chain2; unsigned int *best_list_P1, *best_list_C11, *best_list_OP11, *best_list_OP21, *best_list_P2, *best_list_C12, *best_list_OP12, *best_list_OP22; unsigned int best_n_P1, best_n_P2; unsigned int best_dna1_chain1_n, best_dna1_chain2_n, best_dna2_chain1_n, best_dna2_chain2_n; unsigned int best_i_max_measure, best_j_max_measure; unsigned int best_compl1, best_compl2; unsigned int best_n_first_chain, best_m_first_chain; unsigned int best_pair1, best_pair2; double best_S_max = -1; for (pair1=1; pair1<=n_pairs1; pair1++) { struct atom *atoms_dna1 = NULL, *dna1_chain1 = NULL, *dna1_chain2 = NULL; unsigned int m1, dna1_chain1_n=0, dna1_chain2_n=0; SelectChain(all_atoms_dna1, all_m1, &dna1_chain1, &dna1_chain1_n, pairs1[pair1][1]); SelectChain(all_atoms_dna1, all_m1, &dna1_chain2, &dna1_chain2_n, pairs1[pair1][2]); atomlistmerge(&atoms_dna1, &m1, dna1_chain1, dna1_chain1_n, dna1_chain2, dna1_chain2_n); //printf("%u/%u\n", pair1, n_pairs1); /* Make lists of P, C1', OP1 atoms of dna and CA atoms of protein */ unsigned int *list_P1, *list_C11, *list_OP11, *list_OP21, *list_CA1, *list_C1; unsigned int n_P1, n_C11, n_OP11, n_OP21, n_CA1, n_C1; getAtomsNumbers(atoms_dna1, m1, &list_P1, &n_P1, "P"); // pdb.c function, get only indexes of atoms getAtomsNumbers(atoms_dna1, m1, &list_C11, &n_C11, "C1'"); getAtomsNumbers(atoms_dna1, m1, &list_OP11, &n_OP11, "OP1"); getAtomsNumbers(atoms_dna1, m1, &list_OP21, &n_OP21, "OP2"); getAtomsNumbers(atoms_prot1, n1, &list_CA1, &n_CA1, "CA"); getAtomsNumbers(atoms_prot1, n1, &list_C1, &n_C1, "C"); correctC1_P(atoms_dna1, &list_C11, &n_C11, list_P1, &n_P1); //for (i=1; i<=n_C11; i++) printf("%s.%c\n", atoms_dna1[list_C11[i]].ResNumber, atoms_dna1[list_C11[i]].Chain); //corrects list_C1 to use rule list_P[i] and list_C1[i+1] are in the same nucleotide atoms_prot_CA1 = (struct atom *)malloc( sizeof(struct atom)*(n_CA1+1) ); for (i=1; i<=n_CA1; i++) { atomcpy(&atoms_prot_CA1[i], atoms_prot1[list_CA1[i]]); //pdb.c function. Copy all properties of atom } atoms_prot_C1 = (struct atom *)malloc( sizeof(struct atom)*(n_C1+1) ); for (i=1; i<=n_C1; i++) { atomcpy(&atoms_prot_C1[i], atoms_prot1[list_C1[i]]); } printf("Done atoms:\tP %u\tC1 %u\tOP1 %u\tOP2 %u\tCA %u\tC %u\n",n_P1, n_C11, n_OP11, n_OP21, n_CA1, n_C1); for (pair2=1; pair2<=n_pairs2; pair2++) { //printf("%u/%u\n", pair2, n_pairs2); printf("\nCYCLE %c:%c vs %c:%c\n", pairs1[pair1][1], pairs1[pair1][2], pairs2[pair2][1], pairs2[pair2][2]); struct atom *atoms_dna2 = NULL, *dna2_chain1, *dna2_chain2; unsigned int m2, dna2_chain1_n=0, dna2_chain2_n=0; SelectChain(all_atoms_dna2, all_m2, &dna2_chain1, &dna2_chain1_n, pairs2[pair2][1]); SelectChain(all_atoms_dna2, all_m2, &dna2_chain2, &dna2_chain2_n, pairs2[pair2][2]); atomlistmerge(&atoms_dna2, &m2, dna2_chain1, dna2_chain1_n, dna2_chain2, dna2_chain2_n); unsigned int *list_P2, *list_C12, *list_OP12, *list_OP22, *list_CA2, *list_C2; unsigned int n_P2, n_C12, n_OP12, n_OP22, n_CA2, n_C2; getAtomsNumbers(atoms_dna2, m2, &list_P2, &n_P2, "P"); getAtomsNumbers(atoms_dna2, m2, &list_C12, &n_C12, "C1'"); getAtomsNumbers(atoms_dna2, m2, &list_OP12, &n_OP12, "OP1"); getAtomsNumbers(atoms_dna2, m2, &list_OP22, &n_OP22, "OP2"); getAtomsNumbers(atoms_prot2, n2, &list_CA2, &n_CA2, "CA"); getAtomsNumbers(atoms_prot2, n2, &list_C2, &n_C2, "C"); correctC1_P(atoms_dna2, &list_C12, &n_C12, list_P2, &n_P2); atoms_prot_CA2 = (struct atom *)malloc( sizeof(struct atom)*(n_CA2+1) ); for (i=1; i<=n_CA2; i++) { atomcpy(&atoms_prot_CA2[i], atoms_prot2[list_CA2[i]]); } atoms_prot_C2 = (struct atom *)malloc( sizeof(struct atom)*(n_C2+1) ); for (i=1; i<=n_C2; i++) { atomcpy(&atoms_prot_C2[i], atoms_prot2[list_C2[i]]); } printf("Done atoms:\tP %u\tC1 %u\tOP1 %u\tOP2 %u\tCA %u\tC %u\n",n_P2, n_C12, n_OP12, n_OP22, n_CA2, n_C2); /* Done making lists */ /* Create array of measures for all pairs of dna P atoms (list_measure). dim(list_measure) = n_P2 x n_P1 */ double **list_measure; unsigned int n_hit; unsigned int **list_hit; list_measure = (double **)malloc( (n_P2+1)*sizeof(double *)*(n_P1+1) ); for (i=1; i<=n_P1; i++) list_measure[i] = (double *)malloc( sizeof(double)*(n_P2+1) ); //for (i=1; i<=n_P1; i++) for (j=1; j<=n_P2;j++) list_measure[i][j] = (unsigned int *)malloc( sizeof(unsigned int) ); // Enable if measure function returns unsigned int for (i=1; i<=n_P1; i++){ for (j=1; j<=n_P2; j++){ ChangeSystem(atoms_prot_CA1, n_CA1, &atoms_prot_i1, atoms_dna1[list_P1[i]], atoms_dna1[list_C11[i+1]], atoms_dna1[list_OP11[i]], atoms_dna1[list_OP21[i]], 'E'); // pdb.c function. Change the coordinate system of protein with given nucleotide ChangeSystem(atoms_prot_C1, n_C1, &C_atoms_prot_i1, atoms_dna1[list_P1[i]], atoms_dna1[list_C11[i+1]], atoms_dna1[list_OP11[i]], atoms_dna1[list_OP21[i]], 'E'); ChangeSystem(atoms_prot_CA2, n_CA2, &atoms_prot_j2, atoms_dna2[list_P2[j]], atoms_dna2[list_C12[j+1]], atoms_dna2[list_OP12[j]], atoms_dna2[list_OP22[j]], 'F'); ChangeSystem(atoms_prot_C2, n_C2, &C_atoms_prot_j2, atoms_dna2[list_P2[j]], atoms_dna2[list_C12[j+1]], atoms_dna2[list_OP12[j]], atoms_dna2[list_OP22[j]], 'F'); BidirectionalHit(atoms_prot_i1, C_atoms_prot_i1, n_CA1, atoms_prot_j2, C_atoms_prot_j2, n_CA2, &list_hit, &n_hit); // pdb.c function. Measure2_p(&(list_measure[i][j]), list_hit, n_hit, atoms_prot_i1, atoms_prot_j2); // pdb.c function. // printf("Measure: %f i: %u j: %u n_P1: %u n_P2: %u \n",(list_measure[i][j]), i,j, n_P1, n_P2); // Enable in test mode } } /* Done creation of array of measures */ /* Start working with diagonals */ unsigned int i_max, j_max, i_start, j_start, i_max_measure, j_max_measure; unsigned int n_first_chain, m_first_chain; unsigned int compl1, compl2; double S_max; struct atom *atoms_dna_P1 = NULL; struct atom *atoms_dna_P2 = NULL; // print measure-table /*printf(" "); for (j=1; j<=n_P2; j++) printf("%4d", j); puts(""); for (i=n_P1; i>=1; i--){ printf("%2d", i); for (j=1; j<=n_P2; j++){ printf("%4.0f", list_measure[i][j]>0 ? list_measure[i][j] : 0); } puts(""); } printf(" "); for (j=1; j<=n_P2; j++) printf("%4d", j); puts(""); */ i_max_measure=0; j_max_measure=0; atoms_dna_P1 = (struct atom *)malloc( sizeof(struct atom)*(n_P1+1) ); for (i=1; i<=n_P1; i++) { atomcpy(&atoms_dna_P1[i], atoms_dna1[list_P1[i]]); } atoms_dna_P2 = (struct atom *)malloc( sizeof(struct atom)*(n_P2+1) ); for (i=1; i<=n_P2; i++) { atomcpy(&atoms_dna_P2[i], atoms_dna2[list_P2[i]]); } //find_compl(atoms_dna1, list_P1, list_C11, list_OP11, list_OP21, atoms_dna_P1, n_P1, &compl1, &n_first_chain, max_score); run_find_compl(atoms_dna_P1, n_P1, &compl1, &n_first_chain, compl_pairs1[pair1]); //find_compl(atoms_dna2, list_P2, list_C12, list_OP12, list_OP22, atoms_dna_P2, n_P2, &compl2, &m_first_chain, max_score); run_find_compl(atoms_dna_P2, n_P2, &compl2, &m_first_chain, compl_pairs2[pair2]); BestDiag(list_measure, n_P1, n_P2, &S_max, &i_max, &j_max, &i_start, &j_start, &i_max_measure, &j_max_measure, atoms_dna1, list_P1, atoms_dna2, list_P2, compl1, compl2, n_first_chain, m_first_chain); // pdb.c function /* Done diagonal search */ if (S_max > best_S_max) { best_S_max = S_max; atomlistcpy(&best_dna1_chain1, dna1_chain1, dna1_chain1_n); best_dna1_chain1_n = dna1_chain1_n; atomlistcpy(&best_dna1_chain2, dna1_chain2, dna1_chain2_n); best_dna1_chain2_n = dna1_chain2_n; atomlistcpy(&best_dna2_chain1, dna2_chain1, dna2_chain1_n); best_dna2_chain1_n = dna2_chain1_n; atomlistcpy(&best_dna2_chain2, dna2_chain2, dna2_chain2_n); best_dna2_chain2_n = dna2_chain2_n; best_n_P1 = n_P1; best_n_P2 = n_P2; atomlistcpy(&best_atoms_dna1, atoms_dna1, m1); best_list_P1 = (unsigned int *)malloc(sizeof(unsigned int)*(n_P1+1)); best_list_C11 = (unsigned int *)malloc(sizeof(unsigned int)*(n_C11+1)); best_list_OP11 = (unsigned int *)malloc(sizeof(unsigned int)*(n_OP11+1)); best_list_OP21 = (unsigned int *)malloc(sizeof(unsigned int)*(n_OP21+1)); memcpy(best_list_P1, list_P1, sizeof(unsigned int)*(n_P1+1)); memcpy(best_list_C11, list_C11, sizeof(unsigned int)*(n_C11+1)); memcpy(best_list_OP11, list_OP11, sizeof(unsigned int)*(n_OP11+1)); memcpy(best_list_OP21, list_OP21, sizeof(unsigned int)*(n_OP21+1)); atomlistcpy(&best_atoms_dna2, atoms_dna2, m2); best_list_P2 = (unsigned int *)malloc(sizeof(unsigned int)*(n_P2+1)); best_list_C12 = (unsigned int *)malloc(sizeof(unsigned int)*(n_C12+1)); best_list_OP12 = (unsigned int *)malloc(sizeof(unsigned int)*(n_OP12+1)); best_list_OP22 = (unsigned int *)malloc(sizeof(unsigned int)*(n_OP22+1)); memcpy(best_list_P2, list_P2, sizeof(unsigned int)*(n_P2+1)); memcpy(best_list_C12, list_C12, sizeof(unsigned int)*(n_C12+1)); memcpy(best_list_OP12, list_OP12, sizeof(unsigned int)*(n_OP12+1)); memcpy(best_list_OP22, list_OP22, sizeof(unsigned int)*(n_OP22+1)); best_i_max_measure = i_max_measure; best_j_max_measure = j_max_measure; best_compl1 = compl1; best_compl2 = compl2; best_n_first_chain = n_first_chain; best_m_first_chain = m_first_chain; best_pair1 = pair1; best_pair2 = pair2; } //free array's memory after cycle /*free(list_P2); free(list_C12); free(list_OP12); free(list_OP22); free(list_CA2); free(list_C2); free(atoms_prot_CA2); free(atoms_prot_C2); for (i=1; i<=n_P1; i++) free(list_measure[i]); free(list_measure); free(atoms_dna_P1); free(atoms_dna_P2); free(atoms_dna2); free(dna2_chain1); free(dna2_chain2); free(atoms_prot_i1); free(C_atoms_prot_i1); free(atoms_prot_j2); free(C_atoms_prot_j2);*/ } /*free(list_P1); free(list_C11); free(list_OP11); free(list_OP21); free(list_CA1); free(list_C1); free(atoms_prot_CA1); free(atoms_prot_C1); free(atoms_dna1); free(dna1_chain1); free(dna1_chain2);*/ } /*** END OF MAIN CYCLE ***/ /****reading DNA sequences ***/ unsigned int dna_n11, dna_n12, dna_n21, dna_n22; //sequence length char *dna_seq11, *dna_seq12, *dna_seq21, *dna_seq22; char *dna_num_seq11, *dna_num_seq12, *dna_num_seq21, *dna_num_seq22; int dna1_chain1_start, dna1_chain2_start, dna2_chain1_start, dna2_chain2_start; //SelectChain(atoms_dna1, m1, &dna1_chain1, &dna1_chain1_n, dna_chains1[1]); Seq(best_dna1_chain1, best_dna1_chain1_n, &dna_seq11, &dna_num_seq11, &dna_n11, max_score); sscanf(best_dna1_chain1[1].ResNumber, "%d", &dna1_chain1_start); Seq(best_dna1_chain2, best_dna1_chain2_n, &dna_seq12, &dna_num_seq12, &dna_n12, max_score); sscanf(best_dna1_chain2[1].ResNumber, "%d", &dna1_chain2_start); Seq(best_dna2_chain1, best_dna2_chain1_n, &dna_seq21, &dna_num_seq21, &dna_n21, max_score); sscanf(best_dna2_chain1[1].ResNumber, "%d", &dna2_chain1_start); Seq(best_dna2_chain2, best_dna2_chain2_n, &dna_seq22, &dna_num_seq22, &dna_n22, max_score); sscanf(best_dna2_chain2[1].ResNumber, "%d", &dna2_chain2_start); //printf("%c %c %c %c %c %c\n%lg\n%s\n%s", chain1, chain2, dna_chains1[1], dna_chains1[2], dna_chains2[1], dna_chains2[2], S_max, dna_string1, dna_string2); /*** For server work - DNA alignment making ***/ if (best_S_max == 0) fprintf(max_score, "Warning! The score is zero! It seems you have specified wrong parameters.\n"); unsigned int i_max_measure_compl, j_max_measure_compl; unsigned int is_reverse1, is_reverse2; //printf("n_first_chain=%u i_max_measure=%u best_compl1=%u\n", best_n_first_chain, best_i_max_measure, best_compl1); is_reverse1 = ((best_i_max_measure > best_n_first_chain) ? 1 : 0); is_reverse2 = ((best_j_max_measure > best_m_first_chain) ? 1 : 0); i_max_measure_compl = ((best_i_max_measure > best_n_first_chain) ? best_compl1-best_i_max_measure+1 : best_compl1-best_i_max_measure+1); j_max_measure_compl = ((best_j_max_measure > best_m_first_chain) ? best_compl2-best_j_max_measure+1 : best_compl2-best_j_max_measure+1); //printf("i_max_measure=%u i_max_measure_compl=%u\n", best_i_max_measure, i_max_measure_compl); //printf("i_max_measure=%s\n", best_atoms_dna1[best_list_P1[best_i_max_measure]].ResNumber); //printf("i_max_measure_compl=%s\n", best_atoms_dna1[best_list_P1[i_max_measure_compl]].ResNumber); //puts("OK1"); if (i_max_measure_compl > best_n_P1) { //printf("i_compl=%u n11=%u n12=%u\n", i_max_measure_compl, dna_n11, dna_n12); j_max_measure_compl = j_max_measure_compl-(i_max_measure_compl-best_n_P1); i_max_measure_compl = best_n_P1; //printf("i_compl=%u n11=%u n12=%u\n", i_max_measure_compl, dna_n11, dna_n12); } if (j_max_measure_compl > best_n_P2) { //printf("j_compl=%u n21=%u n22=%u\n", j_max_measure_compl, dna_n21, dna_n22); i_max_measure_compl = i_max_measure_compl-(j_max_measure_compl-best_n_P2); j_max_measure_compl = best_n_P2; //printf("j_compl=%u n21=%u n22=%u\n", j_max_measure_compl, dna_n21, dna_n22); } //puts("OK2"); //if max_compl = 0 or less if (i_max_measure_compl < 1) { i_max_measure_compl = 1; j_max_measure_compl = j_max_measure_compl + 1 - i_max_measure_compl; } if (j_max_measure_compl < 1) { j_max_measure_compl = 1; i_max_measure_compl = i_max_measure_compl + 1 - j_max_measure_compl; } //puts("OK3"); int i_max_measure_compl_num, j_max_measure_compl_num; char *i_max_measure_compl_str, *j_max_measure_compl_str; i_max_measure_compl_str = (char *)malloc( sizeof(char)*7 ); j_max_measure_compl_str = (char *)malloc( sizeof(char)*7 ); sscanf(best_atoms_dna1[best_list_P1[i_max_measure_compl]].ResNumber, "%d", &i_max_measure_compl_num); sscanf(best_atoms_dna2[best_list_P2[j_max_measure_compl]].ResNumber, "%d", &j_max_measure_compl_num); if (i_max_measure_compl==best_i_max_measure) { sscanf(best_atoms_dna1[best_list_P1[i_max_measure_compl+1]].ResNumber, "%d", &i_max_measure_compl_num); i_max_measure_compl_num = i_max_measure_compl_num - 1; //puts("Here1"); } if (j_max_measure_compl==best_j_max_measure) { sscanf(best_atoms_dna2[best_list_P2[j_max_measure_compl+1]].ResNumber, "%d", &j_max_measure_compl_num); j_max_measure_compl_num = j_max_measure_compl_num - 1; //puts("Here2"); } //printf("%d\n", j_max_measure_compl_num); //puts("OK4"); int start, i_start; start = (is_reverse1 == 1) ? dna1_chain1_start : dna1_chain2_start; i_start = (is_reverse1 == 1) ? 1 : dna_n11+1; if (i_max_measure_compl_num < start && i_max_measure_compl < i_start) { //printf("ires_compl=%d start=%d\n", i_max_measure_compl_num, start); j_max_measure_compl_num = j_max_measure_compl_num + start - i_max_measure_compl_num; i_max_measure_compl_num = start; //printf("ires_compl=%d start=%d\n", i_max_measure_compl_num, start); } start = (is_reverse2 == 1) ? dna2_chain1_start : dna2_chain2_start; i_start = (is_reverse2 == 1) ? 1 : dna_n21+1; if (j_max_measure_compl_num < start && j_max_measure_compl < i_start) { //printf("jres_compl=%d start=%d\n", j_max_measure_compl_num, start); i_max_measure_compl = i_max_measure_compl_num + start - j_max_measure_compl_num; j_max_measure_compl = start; //printf("jres_compl=%d start=%d\n", j_max_measure_compl_num, start); } //printf("%d\n", j_max_measure_compl_num); sprintf(i_max_measure_compl_str, "%d", i_max_measure_compl_num); sprintf(j_max_measure_compl_str, "%d", j_max_measure_compl_num); //printf("%d\n", j_max_measure_compl_num); //puts("OK5"); fprintf(max_score, "%c %c %c %c %c %c %s %s %s %s %u %u\n%lg\n%s %s\n%s %s\n%s %s\n%s %s", chain1, chain2, pairs1[best_pair1][1], pairs1[best_pair1][2], pairs2[best_pair2][1], pairs2[best_pair2][2], best_atoms_dna1[best_list_P1[best_i_max_measure]].ResNumber, best_atoms_dna2[best_list_P2[best_j_max_measure]].ResNumber, i_max_measure_compl_str, j_max_measure_compl_str, is_reverse1, is_reverse2, best_S_max, dna_seq11, dna_num_seq11, dna_seq12, dna_num_seq12, dna_seq21, dna_num_seq21, dna_seq22, dna_num_seq22); fclose(max_score); struct atom *atoms_dna_i1 = NULL; struct atom *atoms_dna_i2 = NULL; struct atom *atoms_dna_j1 = NULL; struct atom *atoms_dna_j2 = NULL; /* Change the system to i and j coordinates, write the alignment to file */ ChangeSystem(atoms_prot1, n1, &atoms_prot_i1, best_atoms_dna1[best_list_P1[best_i_max_measure]], best_atoms_dna1[best_list_C11[best_i_max_measure+1]], best_atoms_dna1[best_list_OP11[best_i_max_measure]], best_atoms_dna1[best_list_OP21[best_i_max_measure]], 'E'); // Note that names of chains will be changed to 'E' and 'F' by default! Modify if required. ChangeSystem(atoms_prot2, n2, &atoms_prot_j2, best_atoms_dna2[best_list_P2[best_j_max_measure]], best_atoms_dna2[best_list_C12[best_j_max_measure+1]], best_atoms_dna2[best_list_OP12[best_j_max_measure]], best_atoms_dna2[best_list_OP22[best_j_max_measure]], 'F'); ChangeSystem(best_dna1_chain1, best_dna1_chain1_n, &atoms_dna_i1, best_atoms_dna1[best_list_P1[best_i_max_measure]], best_atoms_dna1[best_list_C11[best_i_max_measure+1]], best_atoms_dna1[best_list_OP11[best_i_max_measure]], best_atoms_dna1[best_list_OP21[best_i_max_measure]], 'A'); ChangeSystem(best_dna1_chain2, best_dna1_chain2_n, &atoms_dna_i2, best_atoms_dna1[best_list_P1[best_i_max_measure]], best_atoms_dna1[best_list_C11[best_i_max_measure+1]], best_atoms_dna1[best_list_OP11[best_i_max_measure]], best_atoms_dna1[best_list_OP21[best_i_max_measure]], 'B'); ChangeSystem(best_dna2_chain1, best_dna2_chain1_n, &atoms_dna_j1, best_atoms_dna2[best_list_P2[best_j_max_measure]], best_atoms_dna2[best_list_C12[best_j_max_measure+1]], best_atoms_dna2[best_list_OP12[best_j_max_measure]], best_atoms_dna2[best_list_OP22[best_j_max_measure]], 'C'); ChangeSystem(best_dna2_chain2, best_dna2_chain2_n, &atoms_dna_j2, best_atoms_dna2[best_list_P2[best_j_max_measure]], best_atoms_dna2[best_list_C12[best_j_max_measure+1]], best_atoms_dna2[best_list_OP12[best_j_max_measure]], best_atoms_dna2[best_list_OP22[best_j_max_measure]], 'D'); //puts("\nFix 'nan' in pdb with this data:"); createPDB(outfile, outfile); // pdb.c function writetoPDB(outfile, atoms_dna_i1, best_dna1_chain1_n); writetoPDB(outfile, atoms_dna_i2, best_dna1_chain2_n); writetoPDB(outfile, atoms_prot_i1, n1); // pdb.c function. Write protein atoms to outfile writetoPDB(outfile, atoms_prot_j2, n2); writetoPDB(outfile, atoms_dna_j1, best_dna2_chain1_n); writetoPDB(outfile, atoms_dna_j2, best_dna2_chain2_n); endPDB(outfile); return 0; }
static void recursiveReplicate(const EncryptedArray& ea, const Ctxt& ctxt, long n, long k, long pos, long limit, RepAux& repAux, ReplicateHandler *handler) { if (pos >= limit) return; if (replicateVerboseFlag) { // DEBUG code cerr << "check: " << k; CheckCtxt(ctxt, ""); } long nSlots = ea.size(); if (k == 0) { if ( (1L << n) >= nSlots) { handler->handle(ctxt); return; } // need to replicate to fill positions [ (1L << n) .. nSlots ) if (repAux.tab(0).null()) { // need to generate mask ZZX mask; SelectRange(ea, mask, 0, nSlots - (1L << n)); repAux.tab(0).set_ptr(new DoubleCRT(mask, ea.getContext())); } Ctxt ctxt_tmp = ctxt; ctxt_tmp.multByConstant(*repAux.tab(0)); ea.rotate(ctxt_tmp, 1L << n); ctxt_tmp += ctxt; handler->handle(ctxt_tmp); return; } k--; Ctxt ctxt_masked = ctxt; { // artificial scope to miminize storage in // the recursion { // another artificial scope // mask should be at index k+1 if (repAux.tab(k+1).null()) { // need to generate mask vector< long > maskArray; maskArray.resize(nSlots); for (long i = 0; i < (1L << n); i++) maskArray[i] = 1- bit(i, k); // the reverse of bit k of i for (long i = (1L << n); i < nSlots; i++) maskArray[i] = 0; ZZX mask; ea.encode(mask, maskArray); repAux.tab(k+1).set_ptr(new DoubleCRT(mask, ea.getContext())); } ctxt_masked.multByConstant(*repAux.tab(k+1)); } Ctxt ctxt_left = ctxt_masked; ea.rotate(ctxt_left, 1L << k); ctxt_left += ctxt_masked; recursiveReplicate(ea, ctxt_left, n, k, pos, limit, repAux, handler); } pos += (1L << k); if (pos >= limit) return; Ctxt ctxt_right = ctxt; ctxt_right -= ctxt_masked; ctxt_masked = ctxt_right; // reuse ctxt_masked as a temp ea.rotate(ctxt_masked, -(1L << k)); ctxt_right += ctxt_masked; recursiveReplicate(ea, ctxt_right, n, k, pos, limit, repAux, handler); }