www.pudn.com > Genecircus20070919.rar > mainframe.cpp
// mainframe.cpp: implementation of the mainframe class.
//
//////////////////////////////////////////////////////////////////////
#include "mainframe.h"
//#include "wx_pch.h"
#define M_SQRT2 1.41421356237309504880
#define maxX 1280.0
#define maxY 800.0
#define szNumber "[0-9]*"
const boost::regex reNumber(szNumber,boost::regbase::normal|boost::regbase::icase);
#define szNumber1 "[0-9]*[.][0-9]*"
const boost::regex reNumber1(szNumber1,boost::regbase::normal|boost::regbase::icase);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void thread_all(BlackBoard * app,int number,int num)
{ bool if_break = false;
do{
for(int t = app->addr.size()-1; t > 0 ;t--){
if(app->add_received.size() != 0){
vector::iterator result = find(app->add_received.begin(),app->add_received.end(),app->addr[t].addr);
if(result == app->add_received.end() && app->addr[t].addr != app->grid.add[0]){
ACE_INET_Addr server_addr1;
ACE_SOCK_Acceptor server_acceptor1;
ACE_SOCK_Stream server_peer1;
ACE_SOCK_Connector connector;ACE_Time_Value time_out(5);
if(server_addr1.set(15679,app->addr[t].addr.c_str()) != -1){
if(connector.connect(server_peer1,server_addr1,&time_out) == -1){//如果对方已死机
ACE_INET_Addr server_addr2;
ACE_SOCK_Acceptor server_acceptor2;
ACE_SOCK_Stream server_peer2;
ACE_SOCK_Connector connector2;ACE_Time_Value time_out2(1);
if(server_addr2.set(15679,app->add_received[0].c_str()) != -1){
if(connector2.connect(server_peer2,server_addr2,&time_out2) != -1){
wxFile file;
if(file.Open((wxChar *)"temp.sim",wxFile::read_write)){
int nSize = file.Length();
char * temp = new char[nSize];
if(file.Read(temp,nSize)>= nSize){
string temp_data = (wxString)temp;
temp_data = temp_data + ":::::" + boost::lexical_cast((int)(number/num)) + ":::::";
temp_data = temp_data + "=STIME=" + boost::lexical_cast((double)(app->simulate_time)) + "=EMITS=";
ssize_t n;
iovec iov[3];
iov[0].iov_base =(char*) temp_data.c_str();
iov[0].iov_len = temp_data.length();
iov[1].iov_base = ";";//(char*)msg.c_str();
iov[1].iov_len = 1;
iov[2].iov_base = " HTTP/1.0\r\r\n\r\n";
iov[2].iov_len = 13;
for(;(n = server_peer2.sendv_n(iov,3)) < iov[0].iov_len + iov[1].iov_len +13;){
}
server_peer2.close();
}
delete [] temp;
file.Close();
}
app->add_received.erase(app->add_received.begin());
}
}
if(app->addr.size()-2 >= t){
for(int i = t;t <= app->addr.size()-2;t++)
app->addr[t] = app->addr[t+1];
app->addr.pop_back();
}
else{
app->addr.pop_back();
}
if(app->addr.size() == 1)
if_break = true;
}
else{
if(connector.complete(server_peer1,0,&time_out) != -1){
string order = "THANK";
ssize_t n;
for(;(n = server_peer1.send_n(order.c_str(),order.length())) < 0;){
}
server_peer1.close();
}
}
}
}
}
}
}while(app->add_received.size()+1 < app->addr.size() && if_break == false);
}
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_BUTTON(ID_BUTTON, MainFrame::OnButtonClick)
EVT_BUTTON(wxID_ANY_SHOWEDGE, MainFrame::OnShowEdge)
EVT_BUTTON(wxID_ANY_OK,MainFrame::OnButtonClickOK)
EVT_BUTTON(wxID_A_SHUFFLE,MainFrame::OnButtonClickShuffle)
EVT_BUTTON(wxID_ANY_NETWORK,MainFrame::OnButtonGetNetwork)
EVT_BUTTON(wxID_A_GENEMI_RESULT,MainFrame::OnButtonClickResetpvalue)
EVT_BUTTON(wxID_LOAD_NETWORK,MainFrame::OnButtonLoadnetwork)
EVT_BUTTON(wxID_A_GENE_SHOW,MainFrame::OnButtonShowControl)
EVT_BUTTON(wxID_A_MONTE,MainFrame::OnButtonMonteCarlo)
EVT_BUTTON(wxID_SIM_GENE,MainFrame::OnDrawGene)
EVT_BUTTON(wxID_SIM_OTHERTF,MainFrame::OnDrawOtherTf)
EVT_BUTTON(wxID_SIM_INTER,MainFrame::OnSaveModle)
EVT_BUTTON(wxID_SIM_CORE,MainFrame::OnLoadModle)
EVT_BUTTON(wxID_SIM_CONTROL,MainFrame::OnDrawControl)
EVT_BUTTON(wxID_SIM_PRO,MainFrame::OnDrawLine)
EVT_BUTTON(wxID_SIM_EFFECT,MainFrame::OnDraweffect)
EVT_BUTTON(wxID_ANY_BEGIN,MainFrame::OnBeginsim)
EVT_BUTTON(wxID_ANY_BEGIN_CELL,MainFrame::OnBeginsimcellcount)
EVT_BUTTON(wxID_ANY_NEW,MainFrame::OnNewModel)//
EVT_BUTTON(wxID_ANY_CORE,MainFrame::OnDrawCore)
EVT_SLIDER(ID_SLIDER, MainFrame::OnSlider)
EVT_PAINT(MainFrame::OnPaint)
EVT_CHECKBOX(wxID_IF_SHUFFLE_DIRECT, MainFrame::OnCheck_Shuffle_Direct)
EVT_CHECKBOX(wxID_IF_SHUFFLE_RESULT_LAW, MainFrame::OnCheck_Shuffle_result_law)
END_EVENT_TABLE()
MainFrame::MainFrame(wxWindow* parent, const wxString& title) : wxFrame(parent, wxID_ANY, title,wxPoint(0,0),wxSize(1024+240,738),wxDEFAULT_FRAME_STYLE)
{
wxScreenDC dc;
//PrepareDC(dc);
wxCoord w,h;
dc.GetSize(&w,&h);
double scaleX=(double)(w/maxX);
double scaleY=(double)(h/maxY);
notebook = new wxNotebook(this,ID_NOTEBOOK,wxPoint(0,10));
vBoxSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(vBoxSizer);//看来,这个vBoxSizer函数调用Add函数的次序与界面的次序有关
//vBoxSizer->Add(textCtrl,0,wxALIGN_LEFT);//wxALL|wxEXPAND,
//vBoxSizer->Add(button, 0, wxALIGN_LEFT|wxALL|wxALIGN_BOTTOM, 5);
vBoxSizer->Add(notebook,1,wxBOTTOM|wxEXPAND);//加入分页框wxALIGN_LEFT|
wxPanel* window1 = new wxPanel(notebook, wxID_ANY);
wxPanel* window2 = new wxPanel(notebook, wxID_ANY);
wxPanel* window3 = new wxPanel(notebook, wxID_ANY);
//textCtrl = new wxTextCtrl((window1, ID_TEXTCTRL, _T("C:\\D_ARACNe\\aml15.txt"), wxDefaultPosition, wxSize(1044*scaleX,20));//,wxTE_MULTILINE);
//button = new wxButton(window1, ID_BUTTON, _("Open the file"), wxPoint(1044*scaleX, 300),wxSize(150*scaleX,16),0);//wxSize(10,10)
//notebook->AddPage(window1, wxT("From data to network"), false, 2);
notebook->AddPage(window3, wxT(" Simulate"), false, 1);
//notebook->AddPage(window2, wxT("Option"), false, 3);//装载控制元件的分页
Scrollforframe = new myCanvas(window1, wxID_ANY_DRAW, wxPoint(10, 15), wxSize((this->GetSize().x-240),(this->GetSize().y-90)));
Scrollforframe1 = new myCanvas_1(window3, wxID_ANY_DRAW1, wxPoint(10, 15), wxSize((this->GetSize().x-200),(this->GetSize().y-70)));
//Scrollforframe1->blackboard->hwnd = (HWND)this->GetHWND();
////
(void) new wxButton(window3, wxID_ANY_CORE, wxT("Nucleolus"),
wxPoint(1090*scaleX, 10*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_OTHERTF, wxT("Other Factor"),
wxPoint(1090*scaleX, 90*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_GENE, wxT("Gene"),
wxPoint(1090*scaleX, 50*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_PRO, wxT("State transition"),
wxPoint(1090*scaleX, 130*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_EFFECT, wxT("Effect"),
wxPoint(1090*scaleX, 170*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_CONTROL, wxT("Reaction"),
wxPoint(1090*scaleX, 210*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_SIM_INTER, wxT("Save"),
wxPoint(1085*scaleX, 330*scaleY), wxSize(75*scaleX,16));
(void) new wxButton(window3, wxID_SIM_CORE, wxT("Load"),
wxPoint(1170*scaleX, 330*scaleY), wxSize(75*scaleX,16));
//(void) new wxStaticText(window3, wxID_SIM_GENE_NAME_T, wxT("File dir:"),
// wxPoint(1090*scaleX, 300), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window3, wxID_SIM_GENE_NAME, wxT(""),
// wxPoint(1090*scaleX, 330), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_ANY_BEGIN, wxT("Single Cell Simulate"),
wxPoint(1090*scaleX, 370*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_ANY_BEGIN_CELL, wxT("Statistic Simulate"),
wxPoint(1090*scaleX, 410*scaleY), wxSize(150*scaleX,16));
(void) new wxStaticText(window3, wxID_SIM_GENE_NAME_TIME, wxT("Input time(Min):"),
wxPoint(1090*scaleX, 450*scaleY), wxSize(200*scaleX,16));
(void) new wxTextCtrl(window3, wxID_SIM_GENE_NAME_LAST_TIME, wxT(""),
wxPoint(1090*scaleX, 490*scaleY), wxSize(150*scaleX,16));
(void) new wxStaticText(window3, wxID_SIM_GENE_NUMBER, wxT("Input cell count:"),
wxPoint(1090*scaleX, 530*scaleY), wxSize(250*scaleX,16));
text = new wxTextCtrl(window3,wxID_TIME_SIM, wxT(""),
wxPoint(1090*scaleX, 570*scaleY), wxSize(150*scaleX,16));
(void) new wxButton(window3, wxID_ANY_NEW, wxT("Create new model"),
wxPoint(1090*scaleX, 610*scaleY), wxSize(150*scaleX,16));
//(void) new wxButton(window1, wxID_ANY_SHOWEDGE, wxT("Calculate Gene_Pairs"),
// wxPoint(1044*scaleX, 50), wxSize(150*scaleX,16));
//(void) new wxButton(window1, wxID_ANY_NETWORK, wxT("Get Networks"),
// wxPoint(1044*scaleX, 100), wxSize(150*scaleX,16));
//(void) new wxButton(window1, wxID_LOAD_NETWORK, wxT("Load Networks"),
// wxPoint(1044*scaleX, 150), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window1, wxID_A_GENEMI, wxT(""),
// wxPoint(1044*scaleX, 5), wxSize(150*scaleX,16));
//(void) new wxButton(window2, wxID_A_SHUFFLE, wxT("Shuffle"),
// wxPoint(15*scaleX, 150), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window1, wxID_A_GENE, wxT(""),
// wxPoint(1044*scaleX, 200), wxSize(150*scaleX,16));
// (void) new wxButton(window1, wxID_A_GENE_SHOW, wxT("Show"),
// wxPoint(1044*scaleX, 250), wxSize(150*scaleX,16));
// (void) new wxButton(window2, wxID_A_GENEMI_RESULT, wxT("ReSet_Pvalue"),
// wxPoint(200*scaleX, 150), wxSize(150*scaleX,16));
///(void) new wxStaticBox(window2, wxID_ANY, wxT("Set for From data to networks"),
// wxPoint(10*scaleX, 40), wxSize(800*scaleX,450));
//(void) new wxTextCtrl(window2, wxID_NUMBER_SAMPLE, wxT("336"),
// wxPoint(15*scaleX, 60), wxSize(150*scaleX,16));
// (void) new wxTextCtrl(window2, wxID_NUMBER_SHUFFLE, wxT("100"),
// wxPoint(15*scaleX, 60), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window2, wxID_I_NUMBER, wxT("0.05158849"),
// wxPoint(15*scaleX, 230), wxSize(150*scaleX,16));
// (void) new wxTextCtrl(window2, wxID_I_NUMBERTOL, wxT("0.91945"),
// wxPoint(215*scaleX, 230), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window2, wxID_SHUFFLEFILE_DIR, wxT("C:\\D_ARACNE\\"),
// wxPoint(15*scaleX, 150), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window2, wxID_A_GENEOTHERNAME, wxT(""),
// wxPoint(15*scaleX, 310), wxSize(150*scaleX,16));
//wxcheck = new wxCheckBox(window2, wxID_IF_SHUFFLE_DIRECT, wxT("If Calculate by complex "),
// wxPoint(215*scaleX, 60), wxDefaultSize,wxCHK_2STATE );
//wxcheck1 = new wxCheckBox(window2, wxID_IF_SHUFFLE_RESULT_LAW, wxT("Select shuffle result by pvalue"),
// wxPoint(215*scaleX, 150), wxDefaultSize,wxCHK_2STATE );
//(void) new wxStaticBox(window2, wxID_ANY, wxT("Set for Monte carlo"),
// wxPoint(10*scaleX, 490), wxSize(800*scaleX,200));
// (void) new wxButton(window2, wxID_A_MONTE, wxT("Monte Carlo"),
// wxPoint(15*scaleX, 530), wxSize(150*scaleX,16));
//(void) new wxStaticBox(window2, wxID_ANY, wxT("Calculate Test"),
// wxPoint(815*scaleX, 40), wxSize(400*scaleX,650));
//(void) new wxButton(window2, wxID_ANY_OK, wxT("OK"),
// wxPoint(825*scaleX, 125), wxSize(150*scaleX,16) );
//(void) new wxTextCtrl(window2, wxID_TEST_ONE, wxT(""),
// wxPoint(825*scaleX, 90), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window2, wxID_TEST_TWO, wxT(""),
// wxPoint(995*scaleX, 90), wxSize(150*scaleX,16));
//(void) new wxTextCtrl(window2, wxID_TEST_RESULT, wxT(""),
// wxPoint(825*scaleX, 170), wxSize(150*scaleX,16));
//wxcheck->SetValue(false);
//wxcheck1->SetValue(true);
number_sample = 0;
myid = -1;
//m_timer.Start(10000);
}
MainFrame::~MainFrame()
{
//delete textCtrl;
//delete button;
//delete wxcheck;
//delete wxcheck1;
delete notebook;
delete gene_matrix;
delete calculatemi;
delete mulithread_getnetworks;
delete mc;
delete blackboard;
}
void MainFrame::OnTimer(wxTimerEvent& event)
{
//using boost::lexical_cast;
//string temp2 = boost::lexical_cast(shuffel->times);
//((wxButton*)this->FindWindow(wxID_A_SHUFFLE))->SetLabel(wxString::Format("%d",shuffel->times));
}
void MainFrame::OnButtonMonteCarlo(wxCommandEvent &event)
{
if(this->gene_matrix->micro_set.size() == 0 ){
return;
}
GetParam();
mc->Find_appropriate_width_tolerance();
}
void MainFrame::OnButtonShowControl(wxCommandEvent &event)
{
int i;
if(shuffel->obj_index == -1){
return;
}
if(net->c.size() == 0 || net->g.size() == 0){
return;
}
wxString whichgene = ((wxTextCtrl*)this->FindWindow(wxID_A_GENE))->GetValue();
for(i = 0; i< net->g.size();i++){
if(whichgene == net->g[i].name){
Scrollforframe->index_vip = i;
return;
}
}
if(i == net->g.size()){
Scrollforframe->index_vip = -1;
wxMessageBox("Error gene name!");
return;
}
}
void MainFrame::OnButtonLoadnetwork(wxCommandEvent &event)
{
if(shuffel->obj_index == -1){
return;
}
wxString dirname = calculatemi->dirname;
dirname = dirname + gene_matrix->micro_set[shuffel->obj_index].name + "_network" + ".tmp";//"37724_at"
wxFile file;unsigned char * t;
if(file.Exists(dirname)){
if(file.Open(dirname,wxFile::read_write)){
if(net->c.size() != 0)
net->c.clear();
if(net->g.size() != 0)
net->g.clear();
int nSize = file.Length();
t = new unsigned char[nSize];
file.Read(t,nSize);
wxString temp_data = (wxString)t;
int index_connect = temp_data.Find("***");
wxString gene_data = temp_data.SubString(0,index_connect);
temp_data.Remove(0,index_connect+3);
index_connect = temp_data.Find("total");
string numb = temp_data.SubString(0,index_connect-1);
int number_gene = boost::lexical_cast(numb);
net->size_total = number_gene;
temp_data.Remove(index_connect-1,8);
wxString conn_data = temp_data.SubString(0,temp_data.length());
while(1){
Gene * g = new Gene();
int t = gene_data.Find(":");
if(t == -1)
break;
wxString name = gene_data.SubString(0,t-1);
g->name = name;
gene_data.Remove(0,t+3);
t = gene_data.Find('\t');
string x_coop = gene_data.SubString(0,t-1);
int coop_x = boost::lexical_cast(x_coop);
g->x = coop_x;
gene_data.Remove(0,t+1);
t = gene_data.Find('\t');
string y_coop = gene_data.SubString(0,t-1);
int coop_y = boost::lexical_cast(y_coop);
g->y = coop_y;
gene_data.Remove(0,t+1);
t = gene_data.Find('\t');
string express_index = gene_data.SubString(0,t-1);
int index_exp = boost::lexical_cast(express_index);
g->index_express = index_exp;
gene_data.Remove(0,t+1);
t = gene_data.Find('\t');
string index0 = gene_data.SubString(0,t-1);
int index = boost::lexical_cast(index0);
g->index = index;
gene_data.Remove(0,t+1);
t = gene_data.Find('\t');
string original_index = gene_data.SubString(0,t-1);
int index1 = boost::lexical_cast(original_index);
g->index_orginial = index1;
gene_data.Remove(0,t+1);
t = gene_data.First("have");
int t0 = gene_data.First('\n');
if(t != -1 && t < t0)
g->if_have_other = true;
else
g->if_have_other = false;
t = gene_data.Find('\n');
gene_data.Remove(0,t+1);
net->g.push_back(*g);
}
while(1 ){
Ccontrol * c = new Ccontrol();
int t = conn_data.Find(":");
if(t == -1)
break;
string indexc = conn_data.SubString(0,t-1);
int index = boost::lexical_cast(indexc);
c->index = index;
conn_data.Remove(0,t+3);
t = conn_data.Find('\t');
string index_begin = conn_data.SubString(0,t-1);
index = boost::lexical_cast(index_begin);
c->index_begin = index;
conn_data.Remove(0,t+1);
t = conn_data.Find('\t');
string index_end = conn_data.SubString(0,t-1);
index = boost::lexical_cast(index_end);
c->index_end = index;
conn_data.Remove(0,t+1);
t = conn_data.Find('\t');
string index_begin_express = conn_data.SubString(0,t-1);
index = boost::lexical_cast(index_begin_express);
c->index_begin_express = index;
conn_data.Remove(0,t+1);
t = conn_data.Find('\t');
string index_end_express = conn_data.SubString(0,t-1);
index = boost::lexical_cast(index_end_express);
c->index_end_express = index;
conn_data.Remove(0,t+1);
t = conn_data.find('\t');
string mi_i = conn_data.SubString(0,t-1);
int index_point = mi_i.find('.');
index_point += 4;
mi_i = mi_i.substr(0,index_point);
double index1 = boost::lexical_cast(mi_i);
c->mi = index1;
conn_data.Remove(0,t+1);
t = conn_data.First("delete");
int t0 = conn_data.First('\n');
if(t != -1 && t < t0)
c->delete_or_keep = true;
else
c->delete_or_keep = false;
t = conn_data.Find('\n');
conn_data.Remove(0,t+1);
net->c.push_back(*c);
}
}
file.Close();
delete []t;
}
else{
wxMessageBox("Error no modle has been saved!");
return;
}
}
void MainFrame::OnButtonClick(wxCommandEvent &event)
{
wxFileDialog dialog(this, _T("Load the data"),
wxEmptyString, wxEmptyString, "txt files (*.txt)|*.txt",
wxMULTIPLE);
if (dialog.ShowModal() == wxID_OK)
{
wxString defaultDir = dialog.GetPath().c_str();//((wxTextCtrl*)this->FindWindow(ID_TEXTCTRL))->GetValue();
wxString temp = defaultDir;
wxString dir_temp = gene_matrix->Path_name;
if(temp != gene_matrix->Path_name){
gene_matrix->Path_name = temp;
if(gene_matrix->get_original_data(gene_matrix->Path_name)){
if(gene_matrix->original_data != NULL){
delete [] gene_matrix->original_data;
gene_matrix->original_data = NULL;
}
}
else{
gene_matrix->Path_name = dir_temp;
}
}
}
}
void MainFrame::OnButtonClickResetpvalue(wxCommandEvent& event)
{
if(calculatemi->gene_matrix_for_calcu_mi->pvalue.size() != 0){
if(calculatemi->gene_matrix_for_calcu_mi->pvalue.size() != 0){
for(int i = 0;i< calculatemi->gene_matrix_for_calcu_mi->pvalue.size(); i++){
calculatemi->gene_matrix_for_calcu_mi->pvalue[i].clear();
}
calculatemi->gene_matrix_for_calcu_mi->pvalue.clear();
for(int i = 0;i< gene_matrix->micro_set.size(); i++){
p i_pvalue;
calculatemi->gene_matrix_for_calcu_mi->pvalue.push_back(i_pvalue);
}
}
}
}
void MainFrame::OnCheck_Shuffle_Direct(wxCommandEvent &event)
{
bool direct = false;//wxcheck->GetValue();
if(direct == true){//if_complex_calculate
//shuffel->shuffle_direct = true;
mulithread_getnetworks->if_complex_calculate = true;
Scrollforframe->if_complex_calculate = true;
}
else{
mulithread_getnetworks->if_complex_calculate = false;
Scrollforframe->if_complex_calculate = false;
}
}
void MainFrame::OnCheck_Shuffle_result_law(wxCommandEvent &event)
{
bool direct = true;//wxcheck1->GetValue();
if(direct == true){
this->calculatemi->law = true;
}
else{
this->calculatemi->law = false;
}
}
void MainFrame::OnSlider(wxCommandEvent &event)
{
//取编辑框中的文本并用信息框显示出来
}
void MainFrame::OnButtonGetNetwork(wxCommandEvent& event)
{
if(gene_matrix->mi_matrix == gene_matrix->head_mi_matrix){
wxMessageBox("Calculate MI is the first step!");
return;
}
//string p_value_temp = ((wxTextCtrl*)this->FindWindow(wxID_I_NUMBER))->GetValue();
//double temp = boost::lexical_cast(p_value_temp);
//if(temp != calculatemi->pvalue){
// wxMessageBox("Please Recalculate MI !");
// return;
// }
GetParam();
if(net->c.size() != 0)
net->c.clear();
if(net->g.size() != 0)
net->g.clear();
mulithread_getnetworks->Get();
net = mulithread_getnetworks->net;
//Network * net1;
mpi->Rebuild_network(net,this->myid);
}
void MainFrame::OnShowEdge(wxCommandEvent& event)
{
int tr = omp_get_num_procs();
if(this->gene_matrix->micro_set.size() == 0 ){
return;
}
if(calculatemi->prob_table == NULL && calculatemi->norm_1D_table == NULL){
initial_table();
}
int size_number_sample = gene_matrix->micro_set[0].a_micro.size();
if(size_number_sample != this->number_sample){
wxMessageBox("Please Reset the Parameter");
return;
}
if(calculatemi->prob_table == NULL){
return;
}
else{
//string p_value_temp = ((wxTextCtrl*)this->FindWindow(wxID_I_NUMBER))->GetValue();
//double temp = boost::lexical_cast(p_value_temp);
if(calculatemi->pvalue < 0.0){
wxMessageBox("Please Get Pvalue first!");
return;
}
this->gene_matrix->delete_maxtri();
if(gene_matrix->index_temp.size() != 0)
gene_matrix->index_temp.clear();
this->calculatemi->number = size_number_sample;
wxString Center_Gene_name = ((wxTextCtrl*)this->FindWindow(wxID_A_GENEMI))->GetValue();
int i = this->gene_matrix->Getindexofonegene(Center_Gene_name);
if(i == -1){
wxMessageBox("Error,Gene's name is error");
return;
}
shuffel->obj_index = i;
if(this->calculatemi->name_for_now_gene != Center_Gene_name && this->calculatemi->name_for_now_gene == ""){
this->calculatemi->name_for_now_gene = Center_Gene_name;
}
else if(this->calculatemi->name_for_now_gene != Center_Gene_name){
//this->gene_matrix->delete_maxtri();
//gene_matrix->index_temp.clear();
this->calculatemi->name_for_now_gene = Center_Gene_name;
}
else if(this->calculatemi->name_for_now_gene == Center_Gene_name){
return;
}
wxString Center_Gene_name_other = ((wxTextCtrl*)this->FindWindow(wxID_A_GENEOTHERNAME))->GetValue();
if(Center_Gene_name_other != ""){
int ii = this->gene_matrix->Getindexofonegene(Center_Gene_name_other);
if(ii == -1){
wxMessageBox("Error,Gene's byname is error");
return;
}
calculatemi->other_name_index = ii;
}
//calculatemi->pvalue = temp;
shuffel->obj_index = i;
int j = 0;
while( j < this->gene_matrix->micro_set.size() ){
this->calculatemi->get_GenePairs_Mi(i,j);
j++;
}
save_mi_result();
}
wxPaintEvent event1;
event1.SetEventObject(Scrollforframe);
Scrollforframe->OnPaint(event1);
}
void MainFrame::save_mi_result()
{
double max = calculatemi->pvalue;string temp2;
string temp1 = "Pvalue = " + boost::lexical_cast(max) + '\r'+'\n';
gene_matrix->mi_matrix = gene_matrix->head_mi_matrix;
for(int i = 0;i< gene_matrix->micro_set.size();i++){
if(gene_matrix->mi_matrix->mi > max){
double tr = gene_matrix->mi_matrix->mi;
using boost::lexical_cast;
temp2 = boost::lexical_cast(tr);
temp1 += temp2 +'\t' + (string)(gene_matrix->micro_set1[i].name) + '\r'+'\n';
}
gene_matrix->mi_matrix = gene_matrix->mi_matrix->lnext;
}
int count = temp1.length();
const char * t = temp1.c_str();
wxString temp_dir = calculatemi->dirname;
calculatemi->dirname = calculatemi->dirname + gene_matrix->micro_set[shuffel->obj_index].name+"_middle_result.tmp";
wxFile file;
file.Create(calculatemi->dirname,true);
file.Open(calculatemi->dirname,wxFile::read_write);
file.Write(t,count);
file.Close();
calculatemi->dirname = temp_dir;
}
void MainFrame::initial_table()
{
int number = gene_matrix->micro_set[0].a_micro.size();
number_sample = number;
this->calculatemi->number = number;
calculatemi->prob_table = new double * [number];
for ( int i = 0; i < number; i++ )
{
calculatemi->prob_table[i] = new double[number];
for ( int j = 0; j < number; j++ )
{
calculatemi->prob_table[i][j] = -1.0;
}
}
calculatemi->norm_1D_table = new double[number];
calculatemi->norm_2D_table = new double * [number];
for ( int p = 0; p < number; p++ )
{
calculatemi->norm_2D_table[p] = new double[number];
}
double sigma = calculatemi->sigma;
for (int i=0; inorm_1D_table[i] = 0.5*( calculatemi->erf( (1-x)/(sigma*M_SQRT2),0 ) - calculatemi->erf( (0-x)/(sigma*M_SQRT2),0 ) );
}
for (int j=0; jnorm_2D_table[j][k] = calculatemi->norm_1D_table[j]*calculatemi->norm_1D_table[k];
calculatemi->norm_2D_table[k][j] = calculatemi->norm_2D_table[j][k];
}
}
}
void MainFrame::OnButtonClickShuffle(wxCommandEvent &event)
{
if(gene_matrix->mi_matrix == gene_matrix->head_mi_matrix){
wxMessageBox("Calculate MI is the first step!");
return;
}
wxString Center_Gene_name = ((wxTextCtrl*)this->FindWindow(wxID_A_GENEMI))->GetValue();
int i = this->gene_matrix->Getindexofonegene(Center_Gene_name);
if(i == -1){
wxMessageBox("Error,Gene's name is error");
return;
}
if(calculatemi->gene_matrix_for_calcu_mi->pvalue.size() == 0){
GetParam();
if(calculatemi->prob_table == NULL && calculatemi->norm_1D_table == NULL){
initial_table();
}
shuffel->random_shuffle();
}
else{
shuffel->select_pvalue();
}
}
void MainFrame::GetParam()
{
boost::smatch what;
wxString Center_Gene_name = ((wxTextCtrl*)this->FindWindow(wxID_A_GENEMI))->GetValue();
int i = this->gene_matrix->Getindexofonegene(Center_Gene_name);
if(i == -1){
wxMessageBox("Error,Gene's name is error");
return;
}
shuffel->obj_index = i;
wxString Center_Gene_name_other = ((wxTextCtrl*)this->FindWindow(wxID_A_GENEOTHERNAME))->GetValue();
if(Center_Gene_name_other != ""){
i = this->gene_matrix->Getindexofonegene(Center_Gene_name_other);
if(i == -1){
wxMessageBox("Error,Gene's byname is error");
return;
}
shuffel->obj_index1 = i;
}
calculatemi->name_for_now_gene = Center_Gene_name;
int size_number_sample = gene_matrix->micro_set[0].a_micro.size();
calculatemi->number = size_number_sample;
wxString number_of_sample = ((wxTextCtrl*)this->FindWindow(wxID_NUMBER_SHUFFLE))->GetValue();
if(number_of_sample != "" && boost::regex_match((string)number_of_sample, what,reNumber))
shuffel->shuffle_times = (int)atof(number_of_sample.c_str());
else
wxMessageBox("Please correctly set shuffle times!");
//calculatemi->dirname = ((wxTextCtrl*)this->FindWindow(wxID_SHUFFLEFILE_DIR))->GetValue();
//string p_value_temp = ((wxTextCtrl*)this->FindWindow(wxID_I_NUMBER))->GetValue();
//calculatemi->pvalue = boost::lexical_cast(p_value_temp);
string tol_temp = ((wxTextCtrl*)this->FindWindow(wxID_I_NUMBERTOL))->GetValue();
mulithread_getnetworks->tolerance = boost::lexical_cast(tol_temp);
}
void MainFrame::OnPaint( wxPaintEvent &WXUNUSED(event))
{
wxPaintDC dc(this);
PrepareDC(dc);
wxSize sz = Scrollforframe->GetClientSize();
wxPoint point = Scrollforframe->GetPosition();
wxRect rectToDraw(point.x, point.y, point.x+sz.GetWidth(), point.y+sz.GetHeight());
dc.DrawRectangle(rectToDraw);
dc.Clear();
}
void MainFrame::OnButtonClickOK(wxCommandEvent &event)
{
if(this->gene_matrix->micro_set.size() == 0 ){
return;
}
if(calculatemi->prob_table == NULL && calculatemi->norm_1D_table == NULL){
initial_table();
}
int size_number_sample = gene_matrix->micro_set[0].a_micro.size();
if(size_number_sample != this->number_sample){
wxMessageBox("Please Reset the Parameter");
return;
}
if(calculatemi->prob_table == NULL){
return;
}
wxString Mione = ((wxTextCtrl*)this->FindWindow(wxID_TEST_ONE))->GetValue();
wxString Mitwo = ((wxTextCtrl*)this->FindWindow(wxID_TEST_TWO))->GetValue();
//shuffel->shuffle_times = (int)atof(number_of_sample.c_str());
int i = this->gene_matrix->Getindexofonegene(Mione);
int j = this->gene_matrix->Getindexofonegene(Mitwo);
if(i == -1 || j == -1){
wxMessageBox("Error,Please Reinput the gene's name!");
return;
}
double mi = this->calculatemi->get_GenePairs_Mi_and_save(i,j);
string mi_result = boost::lexical_cast(mi);
((wxTextCtrl*)this->FindWindow(wxID_TEST_RESULT))->SetValue(mi_result.c_str());
}
void MainFrame::OnDrawGene(wxCommandEvent &event)
{
this->Scrollforframe1->state = 1;
}
void MainFrame::OnDrawOtherTf(wxCommandEvent &event)
{
this->Scrollforframe1->state = 2;
}
void MainFrame::OnDrawTf(wxCommandEvent& event)
{
}
void MainFrame::OnDrawControl(wxCommandEvent& event)
{
this->Scrollforframe1->state = 3;
}
void MainFrame::OnDrawLine(wxCommandEvent& event)
{
this->Scrollforframe1->state = 4;
}
void MainFrame::OnDrawCore(wxCommandEvent& event)
{
this->Scrollforframe1->state = 5;
}
void MainFrame:: OnDraweffect(wxCommandEvent& event)
{
this->Scrollforframe1->state = 6;
}
void MainFrame::OnSaveModle(wxCommandEvent& event)
{
wxFileDialog dialog(this, _T("Save a model"),
wxEmptyString, wxEmptyString, "SBML files (*.xml)|*.xml|Other files (*.sim)|*.sim",
wxMULTIPLE);
if (dialog.ShowModal() == wxID_OK)
{
this->Scrollforframe1->dirname = calculatemi->dirname;
string tempfilename = dialog.GetPath().c_str();//((wxTextCtrl*)this->FindWindow(wxID_SIM_GENE_NAME))->GetValue();
if(tempfilename.length() != 0){
Scrollforframe1->dirname = Scrollforframe1->dirname + tempfilename.c_str();// + ".sim";
this->Scrollforframe1->savemodle();
this->Scrollforframe1->dirname = calculatemi->dirname;
}
else
wxMessageBox("Please set the modle's name");
}
}
void MainFrame::OnLoadModle(wxCommandEvent& event)
{
wxFileDialog dialog(this, _T("Load a model"),
wxEmptyString, wxEmptyString, "SBML files (*.xml)|*.xml|Other files (*.sim)|*.sim",
wxMULTIPLE);
if (dialog.ShowModal() == wxID_OK)
{
this->Scrollforframe1->dirname = calculatemi->dirname;
string tempfilename = dialog.GetPath().c_str();//((wxTextCtrl*)this->FindWindow(wxID_SIM_GENE_NAME))->GetValue();
if(tempfilename.length() != 0){
Scrollforframe1->dirname = Scrollforframe1->dirname + tempfilename.c_str();// + ".sim";
this->Scrollforframe1->loadmodle();
this->Scrollforframe1->dirname = calculatemi->dirname;
//this->Scrollforframe1->blackboard->filedir = calculatemi->dirname.c_str();
/*
blackboard->genes.clear();
blackboard->ct.clear();
blackboard->lc.clear();
blackboard->otf.clear();
blackboard->rc_bl.clear();
blackboard->genes1.clear();
blackboard->ct1.clear();
blackboard->lc1.clear();
blackboard->otf1.clear();
*/
}
else
wxMessageBox("Please set the modle's name");
}
wxPaintEvent event1;
event1.SetEventObject(Scrollforframe1);
Scrollforframe1->OnPaint(event1);
}
void MainFrame::OnShowGeneandotherparamemt()
{
}
void MainFrame::OnBeginsim(wxCommandEvent& event)
{
if(this->blackboard->genes1.size() == 0){
wxMessageBox("Please load the model first");
return;
}
boost::smatch what;
this->blackboard->ave.clear();
string temptime = ((wxTextCtrl*)this->FindWindow(wxID_SIM_GENE_NAME_LAST_TIME))->GetValue();
if(temptime == ""){
wxMessageBox("Please set the simulate time");
return;
}
if(boost::regex_match(temptime, what,reNumber1)
||
boost::regex_match(temptime, what,reNumber)){
this->blackboard->simulate_time = boost::lexical_cast(temptime);
string count_s = text->GetValue();//
if(boost::regex_match(count_s, what,reNumber)){
if(this->blackboard->activation(0,1)){
this->blackboard->thread_number = 1;
ResultDialog * dlg = new ResultDialog(this,wxID_ANY);//set gene's para
if ( dlg->ShowModal() == wxID_OK )
{
}
delete dlg;
}
}
}
}
void MainFrame:: OnBeginsimcellcount(wxCommandEvent& event)
{
if(this->blackboard->genes1.size() == 0){
wxMessageBox("Please load the model first");
return;
}
boost::smatch what;
this->blackboard->ave.clear();
string count_s = text->GetValue();//
string temptime = ((wxTextCtrl*)this->FindWindow(wxID_SIM_GENE_NAME_LAST_TIME))->GetValue();
if(temptime == ""){
wxMessageBox("Please set the simulate time");
return;
}
if(boost::regex_match(temptime, what,reNumber1)
||
boost::regex_match(temptime, what,reNumber)){
this->blackboard->simulate_time = boost::lexical_cast(temptime);
if(boost::regex_match(count_s, what,reNumber)){
if(count_s != "" && count_s != "1"){
int count = boost::lexical_cast(count_s);
if(this->blackboard->activation(1,count)){
this->blackboard->thread_number = count;
ResultDialog * dlg = new ResultDialog(this,wxID_ANY);//set gene's para
if(this->blackboard->addr.size() != 0){//wxMessageBox("3");
boost::thread thrd((boost::bind(&thread_all,this->blackboard,count,this->blackboard->addr.size())));
thrd.join();
}
if ( dlg->ShowModal() == wxID_OK )
{
}
delete dlg;
}
}
}
}
}
void MainFrame::Show_time_sim(string time)
{
}
void MainFrame::OnNewModel(wxCommandEvent& event)
{
this->blackboard->ave.clear();
this->blackboard->ct.clear();
this->blackboard->ct1.clear();
this->blackboard->lc.clear();
this->blackboard->lc1.clear();
this->blackboard->genes.clear();
this->blackboard->genes1.clear();
this->blackboard->otf.clear();
this->blackboard->otf1.clear();
this->blackboard->pc_b.clear();
this->blackboard->rc_bl.clear();
this->blackboard->cr.high = 0;
this->blackboard->cr.wid = 0;
this->blackboard->cr.p1.x = 0;
this->blackboard->cr.p1.y = 0;
wxPaintEvent event1;
event1.SetEventObject(this->Scrollforframe1);
this->Scrollforframe1->OnPaint(event1);
}