📄 clustermain.cpp
字号:
/*
Software and source code Copyright (C) 1998-2000 Stanford University
Written by Michael Eisen (eisen@genome.stanford.edu)
This software is copyright under the following conditions:
Permission to use, copy, and modify this software and its documentation
is hereby granted to all academic and not-for-profit institutions
without fee, provided that the above copyright notice and this permission
notice appear in all copies of the software and related documentation.
Permission to distribute the software or modified or extended versions
thereof on a not-for-profit basis is explicitly granted, under the above
conditions. However, the right to use this software in conjunction with
for profit activities, and the right to distribute the software or modified or
extended versions thereof for profit are *NOT* granted except by prior
arrangement and written consent of the copyright holders.
Use of this source code constitutes an agreement not to criticize, in any
way, the code-writing style of the author, including any statements regarding
the extent of documentation and comments present.
The software is provided "AS-IS" and without warranty of ank kind, express,
implied or otherwise, including without limitation, any warranty of
merchantability or fitness for a particular purpose.
In no event shall Stanford University or the authors be liable for any special,
incudental, indirect or consequential damages of any kind, or any damages
whatsoever resulting from loss of use, data or profits, whether or not
advised of the possibility of damage, and on any theory of liability,
arising out of or in connection with the use or performance of this software.
This code was written using Borland C++ Builder 4 (Inprise Inc., www.inprise.com)
and may be subject to certain additional restrictions as a result.
*/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClusterMain.h"
#include <math.h>
#include <dir.h>
#include "FileFormat.h"
#include "ClusterAbout.h"
#include "ShellApi.h"
#include "NumericalRecipes.h"
#include "MyUtils.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
/* This module contains the handling code for the main form of the program
as well as most of the computational routines. This is not the most elegant
way to have done this, but this software was written on the fly and did not
evolve in an entirely coherent manner. I have tried to organize things
logically. -MBE 2/2000 */
TMainForm *MainForm;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/* A node class TNode is defined here. This was put in mostly for future
versions of the program and isn't used extensively here */
__fastcall TNode::TNode() : TObject()
{
IsNode = false;
Child1 = NULL;
Child2 = NULL;
}
__fastcall TNode::~TNode()
{
if (IsNode)
{
delete Child1;
delete Child2;
}
}
/* Constructer for main form */
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
/* This allows drag-and-drop of files to work by sending all windows messages
to the handler routine AppMessage */
Application->OnMessage = AppMessage;
GeneMetricComboBox->ItemIndex = 0;
ArrayMetricComboBox->ItemIndex = 0;
/* Current version stored here; checked against master website to alter
user for updates */
AnsiString Version = "2.10";
try
{
NMHTTP1->Get("http://rana.stanford.edu/software/clusterversion.html");
}
catch (Exception &E)
{
}
if (Version != (AnsiString(NMHTTP1->Body)).SubString(0,Version.Length()) )
{
Caption = "Gene Cluster - Check for update at http://rana.stanford.edu/software";
}
else
{
Caption = "Gene Cluster";
}
/* Load in data from registry */
TRegistry *Registry = new TRegistry();
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey("Software\\Stanford\\Cluster\\WeightSettings",true);
try
{
GeneWeightCutoff = Registry->ReadFloat("GeneWeightCutoff");
}
catch (Exception &E)
{
GeneWeightCutoff = 0.9;
}
try
{
GeneWeightExp = Registry->ReadFloat("GeneWeightExp");
}
catch (Exception &E)
{
GeneWeightExp = 1.0;
}
try
{
ArrayWeightCutoff = Registry->ReadFloat("ArrayWeightCutoff");
}
catch (Exception &E)
{
ArrayWeightCutoff = 0.9;
}
try
{
ArrayWeightExp = Registry->ReadFloat("ArrayWeightExp");
}
catch (Exception &E)
{
ArrayWeightExp = 1.0;
}
Registry->CloseKey();
Registry->OpenKey("Software\\Stanford\\Cluster\\Directory",true);
try
{
LoadFileDialog->InitialDir = Registry->ReadString("LastOpenDirectory");
}
catch (Exception &E)
{
}
Registry->CloseKey();
delete Registry;
GeneWeightCutoffEdit->Text = GeneWeightCutoff;
GeneWeightExpEdit->Text = GeneWeightExp;
ArrayWeightCutoffEdit->Text = ArrayWeightCutoff;
ArrayWeightExpEdit->Text = ArrayWeightExp;
DragAcceptFiles(Handle,TRUE);
Rows = 0;
Columns = 0;
/* Default Filtering Parameters */
FilterPercentVal = 80.0;
FilterPercentEdit->Text = FilterPercentVal;
FilterSDVal = 2.0;
FilterSDEdit->Text = FilterSDVal;
FilterAbsValCount = 1;
FilterAbsValCountEdit->Text = FilterAbsValCount;
FilterAbsValVal = 2.0;
FilterAbsValEdit->Text = FilterAbsValVal;
FilterMaxMinVal = 2.0;
FilterMaxMinEdit->Text = FilterMaxMinVal;
/* Defaul SOM parameters */
SOMGenesXDim = 1;
SOMGenesYDim = 10;
SOMArraysXDim = 1;
SOMArraysYDim = 10;
SOMGenesTau = 0.02;
SOMArraysTau = 0.02;
SOMGenesIterations = 100000;
SOMArraysIterations = 20000;
/* Default K-means parameters */
GenesK = 10;
ArraysK = 10;
GMaxKCycles = 100;
AMaxKCycles = 100;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
TRegistry *Registry = new TRegistry();
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey("Software\\Stanford\\Cluster\\WeightSettings",true);
Registry->WriteFloat("GeneWeightCutoff",GeneWeightCutoff);
Registry->WriteFloat("GeneWeightExp",GeneWeightExp);
Registry->WriteFloat("ArrayWeightCutoff",ArrayWeightCutoff);
Registry->WriteFloat("ArrayWeightExp",ArrayWeightExp);
Registry->CloseKey();
Registry->OpenKey("Software\\Stanford\\Cluster\\Directory",true);
char Drive[3];
char Dir[260];
fnsplit(LoadFileDialog->FileName.c_str(),Drive,Dir,NULL,NULL);
AnsiString SaveDir = AnsiString(Drive) + AnsiString(Dir);
Registry->WriteString("LastOpenDirectory",SaveDir);
Registry->CloseKey();
delete Registry;
}
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
int i;
for (i=0;i<2*Rows-1;i++)
{
delete GeneData[i];
delete GeneMask[i];
}
delete GeneData;
delete GeneMask;
delete Headers;
delete IsData;
delete InColumn;
delete ArrayWeight;
delete ArrayOrder;
delete UniqID;
delete GeneName;
delete GeneWeight;
delete GeneOrder;
delete Use;
}
/* Enable Drag-Drop */
void __fastcall TMainForm::FormDragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
/* int i;
i = 10;
i = 10 * 10; */
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
Accept = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::AppMessage(tagMSG &Msg, bool &Handled)
{
if (Msg.message == WM_DROPFILES)
{
char lpszFile[256];
DragQueryFile((HANDLE) Msg.wParam, 0, lpszFile, sizeof(lpszFile));
LoadFile(AnsiString(lpszFile));
Handled = true;
}
/* DragFinish((HANDLE) wParam); */
/* for all other messages, Handled remains False so that other message handlers can respond */
}
/* Load in data from tab-delimited text file */
void __fastcall TMainForm::LoadFileButtonClick(TObject *Sender)
{
// User will select a data file (*.txt)
if (LoadFileDialog->Execute())
{
char Drive[3];
char Dir[260];
fnsplit(LoadFileDialog->FileName.c_str(),Drive,Dir,NULL,NULL);
LoadFileDialog->InitialDir = AnsiString(Drive) + AnsiString(Dir);
/* Load in the file */
LoadFile(LoadFileDialog->FileName);
/* Update buttons to reflect presence of data */
FilterResultsLabel->Visible = false;
AcceptFilterButton->Visible = false;
/* Update default SOM sizes */
SOMGenesYDim = 1 + sqrt((double)Rows);
SOMGenesYDimEdit->Text = SOMGenesYDim;
SOMArraysYDim = 1 + sqrt((double)Columns);
SOMArraysYDimEdit->Text = SOMArraysYDim;
/* Clear filtering information */
FileNameMemo->Lines->Clear();
FileNameMemo->Lines->Add(LoadFileDialog->FileName);
}
}
void __fastcall TMainForm::LoadFile(AnsiString FileName)
{
// Clear old Data
int i,j,l;
for (i=0;i<2*Rows-1;i++)
{
delete GeneData[i];
delete GeneMask[i];
GeneName[i] = "";
UniqID[i] = "";
}
delete GeneData;
delete GeneMask;
delete Headers;
delete IsData;
delete InColumn;
delete ArrayWeight;
delete ArrayOrder;
delete UniqID;
delete GeneName;
delete GeneOrder;
delete GeneWeight;
delete Use;
// Load file into TStringList to parse it
TStringList *List = new TStringList();
try
{
List->LoadFromFile(FileName);
// Extract file root
fnsplit(FileName.c_str(),NULL,NULL,ClusterName,NULL);
// Defaul JobName is root name of cluster file
JobNameEdit->Text = ClusterName;
int index;
AnsiString Line, Field;
int NameIndex, GeneWeightIndex, GeneOrderIndex;
// This is list for individual lines of tab-delimited data
TStringList *LineList = new TStringList();
//First Parse Header Line
//It is assumed that first line contains headers
Headers = new TStringList();
Line = List->Strings[0];
while ((Field = NextString(&Line)) != "DONE")
{
Headers->Insert(0,Field);
}
//First Column is always the UniqueID
UniqueID = Headers->Strings[0];
// Look to see if NAME/DESCRIPTION, GWEIGHT/WEIGHT, or GORDER/ORDER
// fields are present
NameIndex = max(max(Headers->IndexOf("NAME"),Headers->IndexOf("DESC")),
Headers->IndexOf("DESCRIPTION"));
GeneWeightIndex = max(Headers->IndexOf("GWEIGHT"),Headers->IndexOf("WEIGHT"));
GeneOrderIndex = max(Headers->IndexOf("GORDER"),Headers->IndexOf("ORDER"));
IsData = new bool[Headers->Count];
for (i=0;i<Headers->Count;i++)
{
IsData[i] = true;
}
Columns = Headers->Count; //Number of loaded columns
// Will decrement columns and set IsData to false for non-data columns
Columns--; //UniqueID Column always assumed
IsData[0] = false;
if (NameIndex > -1)
{
Columns--;
IsData[NameIndex] = false;
}
if (GeneWeightIndex > -1)
{
Columns--;
IsData[GeneWeightIndex] = false;
}
if (GeneOrderIndex > -1)
{
Columns--;
IsData[GeneOrderIndex] = false;
}
index = 0; // Position in list of data columns
InColumn = new int[Columns]; // Column in Input file of each data column
for (i=0;i<Headers->Count;i++)
{
if (IsData[i] == true)
{
InColumn[index] = i;
index++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -