set<string> Neighbors(string pattern, int d) { set<string> neighborhood; if (d == 0) { neighborhood.insert(pattern); } else if (pattern.size() == 1) { string result[4] = { "A", "C", "G", "T" }; neighborhood.insert(result, result+4); } else { string suf_pattern = suffix(pattern); set<string> suf_neighbors = Neighbors(suf_pattern, d); for (auto it=suf_neighbors.begin(); it!=suf_neighbors.end(); it++) { if (HammingDistance(suf_pattern, *it) < d) { for (int j=0; j<4; j++) neighborhood.insert(int2nucl(j) + *it); } else { neighborhood.insert(pattern[0] + *it); } } } return neighborhood; }
/* remove_redundant_vertice() should not be used */ void remove_redundant_vertice() { int total_pt=0,ni; int k,owmany,cur_pt; int neighbor_ary[NEIGHBOR_NUM]; for(cur_pt=0; cur_pt<Vert_ind; cur_pt++) { if(Processed[cur_pt]<Processed_mark) { /* not processed yet */ total_pt++; Processed[cur_pt]=cur_pt; /* point to itself */ owmany=Neighbors((double *)(&(Vert_ary[cur_pt])), neighbor_ary); if(owmany>0) { for(k=0; k<owmany; k++) { ni=neighbor_ary[k]; Processed[ni]=cur_pt; /* this vertice is merged */ } } /********************************* */ if(owmany!=1 && !SILENT) fprintf(stderr,"Error, cur_pt=%d, owmany=%d, [%f %f]\n", cur_pt,owmany,Vert_ary[cur_pt][0],Vert_ary[cur_pt][1]); } } /* fprintf(stderr,"Merge %d vertices into %d vertices\n",Vert_ind,total_pt); */ Total_vertice_num=total_pt; }
/*F current = RemoveAttachment(currentstructure,currentattach); ** ** DESCRIPTION ** currentstructure: The current structure to remove from ** currentattach: The attach atom ** current: The current structure with atom removed and new attach assigned ** ** REMARKS ** ** This removes the attach atom and assigns the attachment point ** 1. Removes element from attachment list in current structure ** 2. Removes the element from the Graph (not in the current structure) ** 3. Creates AttachmentRemoved structure ** ** REFERENCES ** ** SEE ALSO ** ** HEADERFILE ** */ static AttachmentRemoved *RemoveAttachment(CurrentStructure *currentstructure, INT currentattach) { INT minusone,i; DataSubSet *attachments; INT *npoints,*points; Graph *graph; DataSubSet *complete,*reducedlist; AttachmentRemoved *removed; Neighbor *neighbors; INT attachpoint; minusone = currentstructure->Attachments->NumberOfPoints - 1; attachments = AllocateDataSubSet; CreateDataSubSet(attachments,currentstructure->ID,currentstructure->Name, minusone,minusone,0); npoints = attachments->Points; points = currentstructure->Attachments->Points; attachpoint = *(points + currentattach); for(i=0;i<currentstructure->Attachments->NumberOfPoints;i++) { if(i != currentattach) { *npoints = *points; npoints++; } points++; } FreeDataSubSet(currentstructure->Attachments); Free(currentstructure->Attachments); currentstructure->Attachments = attachments; graph = currentstructure->Structure; complete = CreateCompleteDataSubSet(graph->ID,graph->Name,graph->NumberOfNodes); neighbors = Neighbors(attachpoint,graph,complete); if(neighbors->NumberOfNeighbors != 1) { printf("Number of Neighbors of connection not valid: %d\n",neighbors->NumberOfNeighbors); } removed = AllocateAttachmentRemoved; CreateAttachmentRemoved(removed,currentstructure->ID,currentstructure->Name, 0,*(neighbors->List)); reducedlist = RemoveI(attachpoint,complete); removed->Structure = IsolateGraphWithDataSubSet(graph,reducedlist); FreeDataSubSet(complete); Free(complete); FreeNeighbor(neighbors); Free(neighbors); return removed; }
int tri_region_growing(char *slice_group[2], int start_index, short *vert_group_ary) { int group,cnt=0,vert; int i,j,owmany; int neighbor_ary[NEIGHBOR_NUM]; int pichist[MAX_TRI_NUM],index=0; /* use region growing to walk */ /* store the 3 vertice of this triangles into stack */ pichist[index++]=start_index++; while(index>=0) { int j3; cnt++; j=pichist[--index]; j3=(j/3)*3; Processed[j]=Processed_mark; for(vert=j3; vert<j3+3; vert++) { /* pick the other two vertices */ if(Processed[vert]<Processed_mark) { /* the other vert. */ group=vert_group_ary[j]; if(group>=0) { if(group<GROUP_OFFSET) slice_group[0][group]=1; else slice_group[1][group-GROUP_OFFSET]=1; } pichist[index++]=vert; Processed[vert]=Processed_mark; /* also put in its corres. vertice */ owmany=Neighbors((double *)(&(Vert_ary[vert])), neighbor_ary); for(i=0; i<owmany; i++) { j=neighbor_ary[i]; pichist[index++]=j; Processed[j]=Processed_mark; } } } } return -1; /* no correspondence */ }