void PathFactoryEcoNet::write_output(FluxHistogram& flux_histogram, FluxSet& flux_set, UnweightedGraph& graph, const std::string& coefficients_file, const std::string& output_directory) { vector<vector<int> > stoichiometric_matrix; std::string stoichiometric_matrix_file = output_directory + "/stoichiometric.matrix"; load_stoichiometric_matrix_from_file(stoichiometric_matrix_file.c_str(), stoichiometric_matrix); vector<vector<int> > edge_label_graph; GraphUtil::init_graph_to_zeroes<int>(edge_label_graph, graph.size()); Edge edge; for (unsigned int i = 0; i < stoichiometric_matrix[0].size(); ++i) { find_edge_for_stoichiometric_column(edge, stoichiometric_matrix, i); edge_label_graph[edge.u][edge.v] = i; } vector<vector<unsigned char> > flow_matrix; GraphUtil::init_graph_to_zeroes<unsigned char>(flow_matrix, stoichiometric_matrix[0].size(), flux_set.length()); //each flux is represented by a column in the flow matrix. foreach column in the flow matrix //set 1's in the rows that correspond to edges that are used in the flow. flux 1 -> 5 -> 3 //has edges // u,v = 1,5 // u,v = 5,3 // u,v = 3,1 (if its an internal cycle and not a chain) // //any edge such as 1,5 has a unique id stored in the edge_label_graph at row = u, col = v //walk through each flux and set 1's in the flux's corresponding column in the flow matrix. //look up the row index for active edges in the edge_label_graph[u][v]. for (int i = 0; i < flux_set.length(); ++i) { for (int j = 0; j < flux_set[i].length(); ++j) { edge.u = flux_set[i][j]; edge.v = flux_set[i][(j + 1) % flux_set[i].length()]; flow_matrix[edge_label_graph[edge.u][edge.v]][i] = 1; } } unsigned int flux_histogram_pointers[flux_set.length()]; for (unsigned int i = 0; i < flux_set.length(); ++i) { flux_histogram_pointers[i] = i; } sort_flux_histogram_pointers(&flux_histogram_pointers[0], flux_histogram, 0, flux_set.length() - 1); order_output_by_flux_histogram_pointers(&flux_histogram_pointers[0], flux_histogram, flow_matrix); std::string flow_matrix_file = output_directory + "/flow.matrix"; ofstream flow_matrix_filestream(flow_matrix_file.c_str()); write_graph(flow_matrix, flow_matrix_filestream); flow_matrix_filestream.close(); ofstream flux_histogram_file(coefficients_file.c_str()); for (unsigned int i = 0; i < flux_set.length(); ++i) { flux_histogram_file << flux_histogram[i] << std::endl; } flux_histogram_file.close(); }
int solve_by_length(t_case *root, int width) { int ret; if ((ret = launch_solve_by_length(root)) == 1) return (1); else if (ret == 2) return (my_put_error(NO_PATH), 0); return (write_graph(root, width)); }
static void write_subg(Agraph_t * g, GVJ_t * job, state_t* sp) { Agraph_t* sg; write_graph (g, job, FALSE, sp); for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) { gvputs(job, ",\n"); write_subg(sg, job, sp); } }
void dg_put_str (int x,int y,char * s,int cl_fg,int cl_bg) { int i; for(i=0;*s;++i,++s,x+=CHAR_WIDTH) { write_graph(x,y, CHAR_WIDTH,CHAR_HEIGHT, charMap_ascii[*s], cl_bg,cl_fg); } }
void CopyArrayOperator::operator() (LoopTreeLocalityAnal& tc, LoopTreeNode* root) { DepCompAstRefGraphCreate refDep; refDep.Build(tc, root); if (DebugCrossGraph()) write_graph(refDep, std::cerr, "reuse"); DepCompCopyArrayCollect collect( root); DepCompCopyArrayToBuffer::CollectCopyArray(collect, refDep); ModifyCopyArrayCollect(collect, refDep); DepCompCopyArrayToBuffer::ApplyCopyArray(collect,refDep); };
void ValuePropagate:: build(AstInterface& fa, const AstNodePtr& h, ReachingDefinitionAnalysis& r, AliasAnalysisInterface& alias, FunctionSideEffectInterface* f) { if (DebugValuePropogate()) std::cerr << "building def-use chain\n"; DefUseChain<ValuePropagateNode>::build(fa, r, alias, f); if (DebugValuePropogate()) write_graph(*this, std::cout, "def-use"); if (DebugValuePropogate()) { std::cerr << "finshed building def-use chain\n"; std::cerr << "propagating values on def-use chain\n"; } UpdateValuePropagateNode update(fa, h, valmap, astmap, nodemap); PropagateDefUseChainUpdate( this, update); if (DebugValuePropogate()) std::cerr << "\nfinished propagating values on def-use chain\n" << GraphToString(*this) << std::endl; }
void get_syscall_infos(struct user *usr, t_graph *graph, t_data *data) { t_sysinfo syscall; int status; if ((data->peektext & 0xffff) != 0x50f || graph->size <= 0 || usr->regs.rax > NB_SYSCALL) return ; syscall = g_syscalls[usr->regs.rax]; if (ptrace(PTRACE_SINGLESTEP, data->pid, NULL, NULL) == -1) { graph_end(data->fd); exit(1); } wait4(data->pid, &status, 0, NULL); if (is_dead(data->pid, status)) { graph_end(data->fd); exit(1); } write_graph(data->fd, graph->head->name, syscall.call, SYSCALL); }
main( int argc, char *argv[] ) { int c; int pull = 1; int subdivide = 1; int write_all_vertices = 0; while ((c = getopt(argc, argv, "aops")) != EOF) { switch (c) { case 'a': write_all_vertices = !write_all_vertices; break; case 'p': pull = !pull; break; case 'o': fprintf(stdout,"%d\n",getpid()); fflush(stdout); break; case 's': subdivide = !subdivide; break; default: break; } } if (read_graph() != 0) return 1; if (subdivide) subdivide_faces(); main_loop(pull); write_graph(write_all_vertices); return 0; }
static void json_end_graph(GVJ_t *job) { graph_t *g = job->obj->u.g; state_t sp; Agiodisc_t* io_save; static Agiodisc_t io; if (io.afread == NULL) { io.afread = AgIoDisc.afread; io.putstr = (putstrfn)gvputs; io.flush = (flushfn)gvflush; } io_save = g->clos->disc.io; g->clos->disc.io = &io; set_attrwf(g, TRUE, FALSE); sp.Level = 0; sp.isLatin = (GD_charset(g) == CHAR_LATIN1); sp.doXDot = ((job->render.id == FORMAT_JSON) || (job->render.id == FORMAT_XDOT_JSON)); sp.Attrs_not_written_flag = 0; write_graph(g, job, TRUE, &sp); /* agwrite(g, (FILE*)job); */ }
int main(void) { char infile[20], outfile[20]; fout = fopen("result_adjmatrix.out", "w"); read_graph("data_adjmatrix.in"); fprintf(fout,"\n\n그래프 인접행렬 출력\n"); write_graph(); fprintf(fout,"BFS\n"); for (int i = 0; i < n; i++) { BFS(i); fprintf(fout,"\n"); } fprintf(fout,"DFS\n"); for (int i = 0; i < n; i++) { DFS(i); fprintf(fout,"\n"); } return 0; }
int main(int argc, char *argv[]){ int n=0; int r=0; int p=0; char *ofile=NULL; int opt; while((opt=getopt(argc, argv, "n:r:p:o:"))!=-1){ switch(opt){ case 'n': n=atoi(optarg); if(n==0){ printf("'%s' is an invalid parameter for -n!\n",optarg); usage(); } break; case 'r': r=atoi(optarg); if(r==0){ printf("'%s' is an invalid parameter for -r!\n",optarg); usage(); } break; case 'p': p=atoi(optarg); if(p==0){ printf("'%s' is an invalid parameter for -p!\n",optarg); usage(); } break; case 'o': ofile=strdup(optarg); break; case '?': case ':': default : usage(); break; } } if(optind!=argc){ printf("Unknow argument '%s'\n",argv[optind]); usage(); } else if(strcmp(argv[optind-1], "--")==0){ printf("Unknow argument '%s'\n",argv[optind-1]); usage(); } if(n==0){ n=100; } if(r==0){ r=100; } if(p==0){ p=150; } if(ofile==NULL){ ofile=strdup("default-make-graph-file.dat"); } int **A=(int**)malloc(n*sizeof(int*)); if(A==NULL){ printf("Error: Malloc failed!\n"); fflush(stdout); exit(1); } int *tmp=(int*)malloc(n*n*sizeof(int)); if(tmp==NULL){ printf("Error: Malloc failed!\n"); fflush(stdout); exit(1); } int i; for(i=0;i<n;i++){ A[i]=tmp+i*n; } srand(time(NULL)); int j; int u; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(i==j){ A[i][j]=0; } else { u=rand()%(p+1); if(u<=r){ A[i][j]=u; } else { A[i][j]=-1; } } } } write_graph(ofile,n,A); free(ofile); free(tmp); free(A); return 0; }
main(int argc, char **argv) { int i, j, k, l, m, n; int dist[20]; int reads; int num_vertex, num_class, num_edge; int *len_seq, num_seq, num_remain; int **num_pa; char **src_seq, **src_name; char temp[100]; ALIGN **eq_class, *align; EDGE **edge, *edge1, *edge2, *bal_edge1, *bal_edge2; PATH *path; int num_path; NODES **vertex, *begin, *node, *node_next, **start_node; LIST **list; READINTERVAL *readinterval; POSITION *position; FILE *fp, *fp1; readpar(); random1(&idum); initenv(argc, argv); printf("%d %d %d\n", sizeof(POSITION), sizeof(NODES), sizeof(LIST)); /* Input the length of the genome (required) */ len_seq = (int *) ckalloc(2 * MAX_NUM * sizeof(int)); src_name = alloc_name(MAX_NUM, 100); fp = ckopen(lenfile, "r"); num_seq = readlen(fp, len_seq, src_name); fclose(fp); src_seq = (char **) ckalloc(2 * num_seq * sizeof(char *)); l = 0; printf("Genome length: "); for(i = 0; i < num_seq; i ++) { l += len_seq[i]; printf("%d ", len_seq[i]); } printf("\n"); printf("Total length: %d\n", l); /* Make reverse complements of input sequences rev(i) --> i + num_seq */ for(i = 0; i < num_seq; i ++) { len_seq[i + num_seq] = len_seq[i]; src_seq[i] = (char *) ckalloc(len_seq[i] * sizeof(char)); src_seq[i + num_seq] = (char *) ckalloc(len_seq[i] * sizeof(char)); for(j = 0; j < len_seq[i]; j ++) { src_seq[num_seq + i][j] = rev(src_seq[i][len_seq[i] - j - 1]); } } /* Input equivalent readintervales between reads -- see the format of the equivalent readinterval files */ printf("Read equivalent readintervales...\n"); eq_class = (ALIGN **) ckalloc(2 * num_seq * sizeof(ALIGN *)); fp = ckopen(inpfile, "r"); num_class = readclass(eq_class, num_seq, fp); fclose(fp); printf("# equivalent readintervales input: %d\n", num_class); /* for(i = 0; i < 2 * num_seq; i ++) { align = eq_class[i]; while(align) { printf("See: \n"); output_align(align, src_name, src_seq, len_seq, num_seq); getchar(); align = align -> next; } } */ /* Initialize the nodes: each position in each read is assigned as a new node. An array of "list" is set up for each read */ list = (LIST **) ckalloc(2 * num_seq * sizeof(LIST *)); for(i = 0; i < 2 * num_seq; i ++) { list[i] = (LIST *) ckalloc(len_seq[i] * sizeof(LIST)); } printf("intitialize nodes...\n"); initialize(list, len_seq, num_seq); printf("done.\n"); n = countnode(list, len_seq, 2 * num_seq); printf("# of nodes before merge: %d\n", n); /* Glue together two nodes if their corresponding positions are defined as equivalent in a pairwise alignment */ printf("Merge...\n"); merge(num_seq, len_seq, eq_class, num_class, list); printf("done.\n"); for(i = 0; i < num_seq; i ++) { while(eq_class[i]) { eq_class[i] = free_align(eq_class[i]); } } free((void **) eq_class); /* Compute the width of each node */ for(i = 0; i < 2 * num_seq; i ++) { for(j = 0; j < len_seq[i]; j ++) { if(!list[i][j].node -> visit) { list[i][j].node -> num_path = countthickness(list[i][j].node); list[i][j].node -> visit = 1; } } } cleannode(list, len_seq, 2 * num_seq); n = countnode(list, len_seq, 2 * num_seq); printf("# of nodes after merge: %d\n", n); /* Add edges to the graph */ edge = (EDGE **) ckalloc(n * sizeof(EDGE *)); num_edge = graph(num_seq, len_seq, list, edge); printf("# edges: %d\n", num_edge); start_node = (NODES **) ckalloc(num_seq * sizeof(NODES *)); for(i = 0; i < num_seq; i ++) { if(len_seq[i] > 0) { start_node[i] = list[i][0].node; } else { start_node[i] = (NODES *) NULL; } } for(i = 0; i < 2 * num_seq; i ++) { free((void *) list[i]); } free((void **) list); vertex = (NODES **) ckalloc(2 * num_edge * sizeof(NODES *)); num_vertex = count_vertex(edge, num_edge, vertex); free((void **) edge); num_pa = (int **) ckalloc(MAX_BRA * sizeof(int *)); for(i = 0; i < MAX_BRA; i ++) { num_pa[i] = (int *) ckalloc(MAX_BRA * sizeof(int)); } num_edge = count_edge_simp(vertex, num_vertex, num_pa); printf("%d vertices %d edges (%d source %d sinks) remained.\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0]); /* Assign the complementary edges of each edge */ for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { edge1 = vertex[i] -> nextedge[j]; edge1 -> bal_edge = find_bal_edge(edge1, len_seq, num_seq, i); } } /* Remove bulges in the graph */ printf("Shave...\n"); num_vertex = shave_graph(vertex, num_vertex); printf("done.\n"); /* Remove cycles shorter than some threshold in the graph */ /* printf("Shaving graph...\n"); num_vertex = rem_cycle(vertex, num_vertex); printf("done.\n%d vertices remained.\n", num_vertex); */ /* remove short edges */ /* printf("Remove shortedges...\n"); num_vertex = rem_short_edge(vertex, num_vertex, len_seq); printf("done.\n%d vertices remained.\n", num_vertex); fflush(stdout); */ num_edge = count_edge_simp(vertex, num_vertex, num_pa); printf("%d vertices %d edges (%d source %d sinks) remained.\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0]); fflush(stdout); /* Allocate the spaces for paths */ printf("Allocating paths...\n"); for(i = 0; i < num_vertex; i ++) { vertex[i] -> num_path = 0; } /* Build sequence paths */ printf("Define paths...\n"); m = 0; for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { m += vertex[i] -> nextedge[j] -> multip; } } path = (PATH *) ckalloc(2 * num_seq * sizeof(PATH)); for(i = 0; i < 2 * num_seq; i ++) { path[i].edge = (EDGE **) ckalloc(m * sizeof(EDGE *)); } num_path = readpath(start_node, path, num_seq); free((void **) start_node); num_edge = count_edge_simp(vertex, num_vertex, num_pa); m = l = 0; for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { l += vertex[i] -> nextedge[j] -> length; if(vertex[i] -> nextedge[j] -> length > m) { m = vertex[i] -> nextedge[j] -> length; } } } printf("%d vertics %d edges (%d source %d sinks) remained: total length %d (maximal %d).\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0], l, m); fflush(stdout); /* Make consensus of edges */ initial_edge(vertex, num_vertex, src_seq, num_seq); printf("edge initialed\n"); /* Output sequence path */ n = 0; for(i = 0; i < num_vertex; i ++) { vertex[i] -> visit = i; for(j = 0; j < vertex[i] -> num_nextedge; j ++) { vertex[i] -> nextedge[j] -> start_cover = n; n ++; } } for(m = 0; m < num_seq; m ++) { printf("len_path %d\n", path[m].len_path); printf("Sequence%d: ", m + 1); for(i = 0; i < path[m].len_path; i ++) { printf("%d -- %d(%d,%d) --> ", path[m].edge[i] -> begin -> visit, path[m].edge[i] -> start_cover, path[m].edge[i] -> multip, path[m].edge[i] -> length); if(i % 5 == 4) { printf("\n"); } } if(path[m].len_path > 0) { printf("%d\n", path[m].edge[i - 1] -> end -> visit); } else { printf("\n"); } fflush(stdout); } /* Output graph & contigs */ sprintf(temp, "%s.edge", seqfile); fp = ckopen(temp, "w"); sprintf(temp, "%s.graph", seqfile); fp1 = ckopen(temp, "w"); write_graph(vertex, num_vertex, fp, fp1); fclose(fp); fclose(fp1); /* Output read intervals in each edge */ sprintf(temp, "%s.intv", seqfile); fp = ckopen(temp, "w"); write_interval(vertex, num_vertex, fp); fclose(fp); /* Output graphviz format graph */ sprintf(temp, "%s", outfile); fp = ckopen(temp, "w"); output_graph(vertex, num_vertex, fp); fclose(fp); for(i = 0; i < MAX_BRA; i ++) { free((void *) num_pa[i]); } free((void **) num_pa); for(i = 0; i < 2 * num_seq; i ++) { if(path[i].len_path > 0) { free((void **) path[i].edge); } } free((void *) path); free_graph(vertex, num_vertex); for(i = 0; i < 2 * num_seq; i ++) { free((void *) src_seq[i]); } free((void **) src_seq); free_name(src_name, MAX_NUM); free((void *) len_seq); }