void loadAllNames() { int i,len; tc_matrix params, N; tc_items A = tc_createItemsArray(0); if (selectedItemsOnly) A = tc_selectedItems(); if (A.length < 1 || !tc_getItem(A,0)) A = tc_allItems(); tc_deleteStringsArray(allNames); if (tc_getItem(A,0)) { params = tc_getParameters(A); N = tc_getStoichiometry(A); len = N.rows; allNames = tc_createStringsArray(len+params.rows); for (i=0; i < params.rows; ++i) tc_setString(allNames,i,tc_getRowName(params,i)); for (i=0; i < len; ++i) tc_setString(allNames,i+params.rows,tc_getRowName(N,i)); params.rownames = tc_createStringsArray(0); tc_deleteMatrix(params); tc_deleteMatrix(N); tc_deleteItemsArray(A); } }
*/ TCAPIEXPORT tc_strings tc_getTextDataNames(long o) { if (_tc_getTextDataNames) return _tc_getTextDataNames(o); return tc_createStringsArray(0); }
*/ TCAPIEXPORT tc_strings tc_getUniqueNames(tc_items items) { if (_tc_getUniqueNames) return _tc_getUniqueNames(items); return tc_createStringsArray(0); }
*/ TCAPIEXPORT tc_strings tc_getRates(tc_items A) { if (_tc_getRates) return _tc_getRates(A); return tc_createStringsArray(0); }
TCAPIEXPORT tc_strings tc_listOfPossibleModels(long item) { if (_tc_listOfPossibleModels) return _tc_listOfPossibleModels(item); return tc_createStringsArray(0); }
TCAPIEXPORT tc_matrix tc_createMatrix(int rows, int cols) { int i; tc_matrix M; M.rows = rows; M.cols = cols; M.colnames = tc_createStringsArray(cols); M.rownames = tc_createStringsArray(rows); if (rows > 0 && cols > 0) { M.values = (double*)malloc( rows * cols * sizeof(double) ); for (i=0; i < (rows*cols); ++i) M.values[i] = 0.0; } else M.values = 0; return M; }
TCAPIEXPORT tc_table tc_createTable(int rows, int cols) { int i; tc_table M; M.rows = rows; M.cols = cols; M.colnames = tc_createStringsArray(cols); M.rownames = tc_createStringsArray(rows); if (rows > 0 && cols > 0) { M.strings = (char**)malloc( rows * cols * sizeof(char*) ); for (i=0; i < (rows*cols); ++i) M.strings[i] = 0; } else M.strings = 0; return M; }
TCAPIEXPORT void tc_main() { allNames = tc_createStringsArray(0); strcpy(selected_var,"\0"); //add function to menu. args : function, name, description, category, icon file, target part/connection family, in functions list?, in context menu? tc_addFunction(&setup, "Values at time=T0", "uses repeated simulation to compute state of system at the given time", "Parameter scan", "steadystate.png", "", 1, 0, 0); tc_callback(&callback); tc_callWhenExiting(&unload); }
void run() { tc_items selected = tc_selectedItems(); long p; tc_items C; int i, j, k, N = 0; tc_items js, tfs, parts; tc_strings names, jnames; tc_matrix m; p = tc_getItem(selected,0); if (p == 0) return; //if (! tc_isA(p,"Regulator")) return; C = tc_getConnections(p); //count the number of repressors/activators for (i=0; i < C.length; ++i) { if (tc_isA(tc_getItem(C,i),"Binding")) { ++N; } } js = tc_createItemsArray(N); //get kon,koff,and trans.reg. connections j = 0; for (i=0; i < C.length; ++i) { if (tc_isA(tc_getItem(C,i),"Binding")) { tc_setItem(js,j, tc_getItem(C,i)); ++j; } } //get the repressors/activators names tfs = tc_createItemsArray(N+1); tc_setItem(tfs,0,p); k = 1; for (i=0; i < C.length; ++i) { if (tc_isA(tc_getItem(C,i),"Binding")) { parts = tc_getConnectedNodes(tc_getItem(C,i)); for (j=0; i < parts.length; ++j) { if (tc_getItem(parts,j) != p) { tc_setItem( tfs, k, tc_getItem(parts,j)); //save tfs ++k; } } tc_deleteItemsArray(parts); } } names = tc_getUniqueNames(tfs); //get names of proteins jnames = tc_getUniqueNames(js); //get names of reactions //main function that generates the full stoichiometry and rates m = fullBindingKinetics(N,jnames.strings,names.strings); //output that matrix to screen and item tc_printTable(m); tc_setRates(js,m.colnames); if (m.colnames.strings) free(m.colnames.strings); m.colnames = tc_createStringsArray(0); tc_setStoichiometry(js,m); tc_deleteItemsArray(js); tc_deleteItemsArray(tfs); tc_deleteMatrix(m); tc_deleteStringsArray(names); tc_deleteStringsArray(jnames); tc_deleteItemsArray(selected); return; }
void run(tc_matrix input) { double start = 0.0, end = 50.0; double dt = 0.1, time = 100.0; int doStochastic = 0; int selection = 0, index = 0, sz = 0, rateplot = 0, slider = 1; tc_items A, B; const char * param; FILE * out; tc_matrix params, initVals, allParams, N; char * runfuncInput = "tc_matrix input"; char * runfunc = ""; int i; if (input.cols > 0) { if (input.rows > 0) selectedItemsOnly = selection = (int)tc_getMatrixValue(input,0,0); if (input.rows > 1) doStochastic = (int)(tc_getMatrixValue(input,1,0) > 0); if (input.rows > 2) index = tc_getMatrixValue(input,2,0); if (input.rows > 3) start = tc_getMatrixValue(input,3,0); if (input.rows > 4) end = tc_getMatrixValue(input,4,0); if (input.rows > 5) dt = tc_getMatrixValue(input,5,0); if (input.rows > 6) time = tc_getMatrixValue(input,6,0); if (input.rows > 7) rateplot = tc_getMatrixValue(input,7,0); if (input.rows > 8) slider = tc_getMatrixValue(input,8,0); } if (slider == 0) slider = 1; else slider = 0; if (selection > 0) { A = tc_selectedItems(); if (tc_getItem(A,0) == 0) { tc_deleteItemsArray(A); A = tc_allItems(); } } else { A = tc_allItems(); } sz = (int)((end - start) / dt); if (tc_getItem(A,0) != 0) { tc_writeModel( "timet", A ); } else { tc_deleteItemsArray(A); return; } if (index < 0) { tc_print("steady state: no variable selected\0"); tc_deleteItemsArray(A); return; } param = tc_getString(allNames,index); //the parameter to vary strcpy(selected_var,param); if (slider) { params = tc_getParameters(A); N = tc_getStoichiometry(A); B = tc_findItems(N.rownames); tc_deleteMatrix(N); initVals = tc_getInitialValues(B); allParams = tc_createMatrix(initVals.rows+params.rows,2); for (i=0; i < params.rows; ++i) { tc_setRowName(allParams,i, tc_getRowName(params,i)); tc_setMatrixValue(allParams,i,0,tc_getMatrixValue(params,i,0)/10.0); tc_setMatrixValue(allParams,i,1, 2*tc_getMatrixValue(params,i,0) - tc_getMatrixValue(allParams,i,0)); } for (i=0; i < initVals.rows; ++i) { tc_setRowName(allParams,i+params.rows, tc_getRowName(initVals,i)); tc_setMatrixValue(allParams,i+params.rows,0,tc_getMatrixValue(initVals,i,0)/10.0); tc_setMatrixValue(allParams,i+params.rows,1, 2*tc_getMatrixValue(initVals,i,0) - tc_getMatrixValue(allParams,i+params.rows,0)); } tc_deleteMatrix(initVals); tc_deleteMatrix(params); tc_deleteItemsArray(B); runfunc = runfuncInput; } tc_deleteItemsArray(A); out = fopen("timet.c","a"); fprintf( out , "\ #include \"TC_api.h\"\n#include \"cvodesim.h\"\n#include \"ssa.h\"\n\ TCAPIEXPORT void run(%s) \n\ {\n initMTrand();\n tc_matrix dat;\n int i,j;\n", runfunc ); fprintf( out, "\ dat.rows = (int)((%lf-%lf)/%lf);\n\ double * y, * y0, *y1;\n\ TCmodel * model = (TCmodel*)malloc(sizeof(TCmodel));\n\ (*model) = TC_initial_model;\n\ if (%i) \n\ {\n\ dat.cols = 1+TCreactions;\n\ dat.colnames = tc_createStringsArray(TCreactions);\n\ for(i=0; i<TCreactions; ++i) dat.colnames.strings[1+i] = TCreactionnames[i];\n\ }\n\ else\n\ {\n\
fprintf( out, "\ dat.rows = (int)((%lf-%lf)/%lf);\n\ double * y, * y0, *y1;\n\ TCmodel * model = (TCmodel*)malloc(sizeof(TCmodel));\n\ (*model) = TC_initial_model;\n\ if (%i) \n\ {\n\ dat.cols = 1+TCreactions;\n\ dat.colnames = tc_createStringsArray(TCreactions);\n\ for(i=0; i<TCreactions; ++i) dat.colnames.strings[1+i] = TCreactionnames[i];\n\ }\n\ else\n\ {\n\ dat.cols = 1+TCvars;\n\ dat.colnames = tc_createStringsArray(1+TCvars);\n\ for(i=0; i<TCvars; ++i) dat.colnames.strings[1+i] = TCvarnames[i];\n\ }\n\ dat.values = malloc(dat.cols * dat.rows * sizeof(double));\n\ dat.rownames = tc_createStringsArray(0);\n\ dat.colnames.strings[0] = \"%s\";\n",end,start,dt,rateplot,param); fprintf( out, "\n\ for (i=0; i < dat.rows; ++i)\n\ {\n\ (*model) = TC_initial_model;\n"); if (slider) { for (i=0; i < allParams.rows; ++i) fprintf(out, " model->%s = tc_getMatrixValue(input,%i,0);\n",tc_getRowName(allParams,i),i);