bool CDictionary::IsExist(char *sWord, int nHandle) { char sWordFind[WORD_MAXLENGTH-2]; int nPos; if(!PreProcessing(sWord, &nPos,sWordFind)) return false; return(FindInOriginalTable(nPos,sWordFind,nHandle)||FindInModifyTable(nPos,sWordFind,nHandle)); }
bool CDictionary::DelItem(char *sWord,int nHandle) { char sWordDel[WORD_MAXLENGTH-2]; int nPos,nFoundPos,nTemp; PWORD_CHAIN pPre,pTemp,pCur; if(!PreProcessing(sWord, &nPos,sWordDel)) return false; if (nPos < 0) return false; if(FindInOriginalTable(nPos,sWordDel,nHandle,&nFoundPos)) { if(!m_pModifyTable)//Not prepare the buffer { m_pModifyTable=new MODIFY_TABLE[CC_NUM]; memset(m_pModifyTable,0,CC_NUM*sizeof(MODIFY_TABLE)); } m_IndexTable[nPos].pWordItemHead[nFoundPos].nFrequency=-1; m_pModifyTable[nPos].nDelete+=1; if(nHandle==-1)//Remove all items which word is sWordDel,ignoring the handle { /* nTemp=nFoundPos-1;//Check its previous position while(nTemp>0&&strcmp(m_IndexTable[nPos].pWordItemHead[nFoundPos].sWord,sWordDel)==0) { m_IndexTable[nPos].pWordItemHead[nTemp].nFrequency=-1; m_pModifyTable[nPos].nDelete+=1; nTemp-=1; } */ nTemp=nFoundPos+1;//Check its previous position while(nTemp<m_IndexTable[nPos].nCount&&strcmp(m_IndexTable[nPos].pWordItemHead[nFoundPos].sWord,sWordDel)==0) { m_IndexTable[nPos].pWordItemHead[nTemp].nFrequency=-1; m_pModifyTable[nPos].nDelete+=1; nTemp+=1; } } return true; } //Operation in the modify table and its items if(FindInModifyTable(nPos,sWordDel,nHandle,&pPre)) { pCur=m_pModifyTable[nPos].pWordItemHead; if(pPre!=NULL) pCur=pPre->next; while(pCur!=NULL && _stricmp(pCur->data.sWord,sWordDel)==0&&(pCur->data.nHandle==nHandle||nHandle<0)) { pTemp=pCur; if(pPre!=NULL)//pCur is the first item pPre->next=pCur->next; else m_pModifyTable[nPos].pWordItemHead=pCur->next; pCur=pCur->next; delete pTemp->data.sWord;//Delete the word delete pTemp; } return true; } return false; }
bool CDictionary::GetHandle(char *sWord,int *pnCount,int *pnHandle,int *pnFrequency) { char sWordGet[WORD_MAXLENGTH-2]; int nPos,nFoundPos,nTemp; PWORD_CHAIN pPre,pCur; *pnCount=0; if(!PreProcessing(sWord, &nPos,sWordGet)) return false; if (nPos < 0) return false; if(FindInOriginalTable(nPos,sWordGet,-1,&nFoundPos)) { pnHandle[*pnCount]=m_IndexTable[nPos].pWordItemHead[nFoundPos].nHandle; pnFrequency[*pnCount]=m_IndexTable[nPos].pWordItemHead[nFoundPos].nFrequency; *pnCount+=1; /* nTemp=nFoundPos-1;//Check its previous position while(nTemp>0&&strcmp(m_IndexTable[nPos].pWordItemHead[nTemp].sWord,sWordGet)==0) { pnHandle[*pnCount]=m_IndexTable[nPos].pWordItemHead[nTemp].nHandle; pnFrequency[*pnCount]=m_IndexTable[nPos].pWordItemHead[nTemp].nFrequency; *pnCount+=1; nTemp-=1; } */ nTemp=nFoundPos+1;//Check its previous position while(nTemp<m_IndexTable[nPos].nCount&&strcmp(m_IndexTable[nPos].pWordItemHead[nTemp].sWord,sWordGet)==0) { pnHandle[*pnCount]=m_IndexTable[nPos].pWordItemHead[nTemp].nHandle; pnFrequency[*pnCount]=m_IndexTable[nPos].pWordItemHead[nTemp].nFrequency; *pnCount+=1; nTemp+=1; } return true; } //Operation in the index table and its items if(FindInModifyTable(nPos,sWordGet,-1,&pPre)) { pCur=m_pModifyTable[nPos].pWordItemHead; if(pPre!=NULL) pCur=pPre->next; while(pCur!=NULL && _stricmp(pCur->data.sWord,sWordGet)==0) { pnHandle[*pnCount]=pCur->data.nHandle; pnFrequency[*pnCount]=pCur->data.nFrequency; *pnCount+=1; pCur=pCur->next; } return true; } return false; }
int CDictionary::GetFrequency(char *sWord, int nHandle) { char sWordFind[WORD_MAXLENGTH-2]; int nPos,nIndex; PWORD_CHAIN pFound; if(!PreProcessing(sWord, &nPos,sWordFind)) return 0; if(FindInOriginalTable(nPos,sWordFind,nHandle,&nIndex)) { return m_IndexTable[nPos].pWordItemHead[nIndex].nFrequency; } if(FindInModifyTable(nPos,sWordFind,nHandle,&pFound)) { return pFound->data.nFrequency; } return 0; }
/********************************************************************* * * Func Name : GetMaxMatch * * Description: Get the max match to the word * * * Parameters : nHandle: the only handle which will be attached to the word * Returns : success or fail * Author : Kevin Zhang * History : * 1.create 2002-1-21 *********************************************************************/ bool CDictionary::GetMaxMatch(char *sWord, char *sWordRet,int *npHandleRet) { char sWordGet[WORD_MAXLENGTH-2],sFirstChar[3]; int nPos,nFoundPos,nTemp; PWORD_CHAIN pCur; *npHandleRet=-1; if(!PreProcessing(sWord, &nPos,sWordGet)) return false; if (nPos < 0) return false; sWordRet[0]=0; strncpy(sFirstChar,sWord,strlen(sWord)-strlen(sWordGet));//Get the first char sFirstChar[strlen(sWord)-strlen(sWordGet)]=0;//Set the end flag FindInOriginalTable(nPos,sWordGet,-1,&nFoundPos); nTemp=nFoundPos;//Check its previous position if(nFoundPos==-1) nTemp=0; while(nTemp<m_IndexTable[nPos].nCount&&CC_Find(m_IndexTable[nPos].pWordItemHead[nTemp].sWord,sWordGet)!=m_IndexTable[nPos].pWordItemHead[nTemp].sWord) {//Get the next nTemp+=1; } if(nTemp<m_IndexTable[nPos].nCount&&CC_Find(m_IndexTable[nPos].pWordItemHead[nTemp].sWord,sWordGet)==m_IndexTable[nPos].pWordItemHead[nTemp].sWord) { strcpy(sWordRet,sFirstChar); strcat(sWordRet,m_IndexTable[nPos].pWordItemHead[nTemp].sWord); *npHandleRet=m_IndexTable[nPos].pWordItemHead[nTemp].nHandle; return true; }//Cannot get the item and retrieve the modified data if exists //Operation in the index table and its items if(m_pModifyTable&&m_pModifyTable[nPos].pWordItemHead)//Exists pCur=m_pModifyTable[nPos].pWordItemHead; else pCur=NULL; while(pCur!=NULL&&strcmp(pCur->data.sWord,sWordGet)<=0&&CC_Find(pCur->data.sWord,sWordGet)!=pCur->data.sWord)// { pCur=pCur->next; } if(pCur!=NULL&&CC_Find(pCur->data.sWord,sWordGet)!=pCur->data.sWord) {//Get it strcpy(sWordRet,sFirstChar); strcat(sWordRet,pCur->data.sWord); *npHandleRet=pCur->data.nHandle; return true; } return false; }
bool CDictionary::AddItem(char *sWord, int nHandle,int nFrequency) { char sWordAdd[WORD_MAXLENGTH-2]; int nPos,nFoundPos; PWORD_CHAIN pRet,pTemp,pNext; int i=0; if(!PreProcessing(sWord, &nPos,sWordAdd,true)) return false; if(FindInOriginalTable(nPos,sWordAdd,nHandle,&nFoundPos)) {//The word exists in the original table, so add the frequency //Operation in the index table and its items if(m_IndexTable[nPos].pWordItemHead[nFoundPos].nFrequency==-1) {//The word item has been removed m_IndexTable[nPos].pWordItemHead[nFoundPos].nFrequency=nFrequency; if(!m_pModifyTable)//Not prepare the buffer { m_pModifyTable=new MODIFY_TABLE[CC_NUM]; memset(m_pModifyTable,0,CC_NUM*sizeof(MODIFY_TABLE)); } m_pModifyTable[nPos].nDelete-=1; } else m_IndexTable[nPos].pWordItemHead[nFoundPos].nFrequency+=nFrequency; return true; } //The items not exists in the index table. //As following, we have to find the item whether exists in the modify data region //If exists, change the frequency .or else add a item if(!m_pModifyTable)//Not prepare the buffer { m_pModifyTable=new MODIFY_TABLE[CC_NUM]; memset(m_pModifyTable,0,CC_NUM*sizeof(MODIFY_TABLE)); } if(FindInModifyTable(nPos,sWordAdd,nHandle,&pRet)) { if(pRet!=NULL) pRet=pRet->next; else pRet=m_pModifyTable[nPos].pWordItemHead; pRet->data.nFrequency+=nFrequency; return true; } //find the proper position to add the word to the modify data table and link pTemp=new WORD_CHAIN;//Allocate the word chain node if(pTemp==NULL)//Allocate memory failure return false; memset(pTemp,0,sizeof(WORD_CHAIN));//init it with 0 pTemp->data.nHandle=nHandle;//store the handle pTemp->data.nWordLen=strlen(sWordAdd); pTemp->data.sWord=new char[1+pTemp->data.nWordLen]; strcpy(pTemp->data.sWord,sWordAdd); pTemp->data.nFrequency=nFrequency; pTemp->next=NULL; if(pRet!=NULL) { pNext=pRet->next;//Get the next item before the current item pRet->next=pTemp;//link the node to the chain } else { pNext=m_pModifyTable[nPos].pWordItemHead; m_pModifyTable[nPos].pWordItemHead=pTemp;//Set the pAdd as the head node } pTemp->next=pNext;//Very important!!!! or else it will lose some node //Modify in 2001-10-29 m_pModifyTable[nPos].nCount++;//the number increase by one return true; }
int main(int argc, char* argv[]) { char lib1FileName[1000], lib2FileName[1000], chromFileName[1000],configFileName[2000], projectName[1000]; CONFIG_STRUCT config; CHROM_INFO chroms[MAX_CHROM_NUM]; int chromNum; double noiseRate, l1Ratio, l2Ratio; int maxL1Count, maxL2Count; int i; if (argc!=6) { printf("Usage: <library 1 tag file name> <library 2 tag file name> <chromosome length file name> <config file name> <project name>\n"); return 0; } strcpy(lib1FileName, argv[1]); strcpy(lib2FileName, argv[2]); strcpy(chromFileName, argv[3]); strcpy(configFileName, argv[4]); strcpy(projectName, argv[5]); chromNum = GetChromInfo(chromFileName, chroms); if (chromNum<=0) { return 0; } printf("chromosome length information read. chromNum = %d!\n", chromNum); for (i=0;i<chromNum;i++) { chroms[i].l1PosTagNum = 0; chroms[i].l2PosTagNum = 0; chroms[i].l1NegTagNum = 0; chroms[i].l2NegTagNum = 0; chroms[i].l1PeakNum = 0; chroms[i].l2PeakNum = 0; } if (ReadConfigFile(configFileName, &config)<0) { printf("config file not complet. Default setting used.\n"); } printf("config file read.\n"); printf("fragmentSize = %d\n", config.fragmentSize); printf("isStrandSensitiveMode = %d\n", config.isStrandSensitiveMode); printf("slidingWinSize = %d\n", config.slidingWinSize); printf("movingStep = %d\n", config.movingStep); printf("outputNum = %d\n", config.outputNum); printf("minCount = %d\n", config.minCount); printf("minScore = %f\n", config.minScore); printf("bootstrapPass = %d\n", config.bootstrapPass); printf("randSeed = %d\n", config.randomSeed); printf("reading tag files......\n"); if (!GetTags(lib1FileName, lib2FileName, chroms, chromNum)) { printf("tag file error!\n"); return 0; } printf("tag file read.\n"); printf("pre-processing......\n"); if (PreProcessing(chroms, chromNum)<0) { printf("Preprocessing failed!\n CCAT aborted!\n"); return -1; } printf("pre-processing finished.\n"); printf("estimating noise rate......\n"); srand(config.randomSeed); noiseRate = ComputeNoiseRate(chroms,chromNum, &l1Ratio,&l2Ratio, config); printf("noise rate = %f\n", noiseRate); printf("peak-finding......\n"); if (PeakFinding(chroms,chromNum,l1Ratio,l2Ratio, &maxL1Count, &maxL2Count, config)<=0) { return -1; } printf("peak-finding finished.\n"); printf("Significance Analysis......\n"); if (SignificanceAnalysis(chroms, chromNum, l1Ratio, l2Ratio, maxL1Count, maxL2Count, config)<0) { printf("DPS paramter esitmation failed!\n"); return -1; } printf("Significance analysis finished.\n"); printf("saving results.......\n"); OutputFiles(chroms, chromNum, projectName, config); printf("results saved.\n"); FreeChromMem(chroms,chromNum); printf("CCAT process completed!\n"); return 0; }
void KernelBand<NLSSystemObject>::NumericalJacobian(const Eigen::VectorXd& x, const Eigen::VectorXd& f, Eigen::VectorXd& x_dimensions, const bool max_constraints, const Eigen::VectorXd& xMax) { if (pre_processing_ == false) PreProcessing(); const double tstart = OpenSMOKE::OpenSMOKEGetCpuTime(); const double ZERO_DER = 1.e-8; const double ETA2 = std::sqrt(OpenSMOKE::OPENSMOKE_MACH_EPS_DOUBLE); // Save the original vector x_plus_ = x; // Loop for (int group = 1; group <= ngroups_; group++) { if (max_constraints == false) { for (int j = group - 1; j < static_cast<int>(this->ne_); j += width_) { const double xh = std::fabs(x(j)); const double xdh = std::fabs(x_dimensions(j)); hJ_(j) = ETA2*std::max(xh, xdh); hJ_(j) = std::max(hJ_(j), ZERO_DER); hJ_(j) = std::min(hJ_(j), 0.001 + 0.001*std::fabs(xh)); x_plus_(j) += hJ_(j); } } else { for (int j = group - 1; j < static_cast<int>(this->ne_); j += width_) { const double xh = std::fabs(x(j)); const double xdh = std::fabs(x_dimensions(j)); hJ_(j) = ETA2*std::max(xh, xdh); hJ_(j) = std::max(hJ_(j), ZERO_DER); hJ_(j) = std::min(hJ_(j), 0.001 + 0.001*std::fabs(xh)); if (xh + hJ_(j) > xMax(j)) hJ_(j) = -hJ_(j); x_plus_(j) += hJ_(j); } } this->Equations(x_plus_, f_plus_); for (int j = group - 1; j < static_cast<int>(this->ne_); j += width_) { x_plus_(j) = x(j); double* col_j = BAND_COL(J_, j); int i1 = std::max(0, j - J_->nUpper()); int i2 = std::min(j + J_->nLower(), static_cast<int>(this->ne_ - 1)); for (int i = i1; i <= i2; i++) BAND_COL_ELEM(col_j, i, j) = (f_plus_(i) - f(i)) / hJ_(j); } } const double tend = OpenSMOKE::OpenSMOKEGetCpuTime(); numberOfSystemCallsForJacobian_ += this->ngroups_; numberOfJacobianFullAssembling_++; cpuTimeSingleJacobianFullAssembling_ = tend - tstart; cpuTimeJacobianFullAssembling_ += cpuTimeSingleJacobianFullAssembling_; }