📄 readdnadlg.cpp
字号:
// ReadDNADlg.cpp : implementation file
//
#include "stdafx.h"
#include "ReadDNA.h"
#include "ReadDNADlg.h"
#include "DlgSolution.h"
#include "DlgCos.h"
#include "DlgEu.h"
#include "DlgGeo.h"
#include "DlgCentroid.h"
#include "DlgResult.h"
#include "DlgCentAna.h"
#include "DlgClust.h"
#include <fstream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadDNADlg dialog
CReadDNADlg::CReadDNADlg(CWnd* pParent /*=NULL*/)
: CDialog(CReadDNADlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReadDNADlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
IsRead=false;
}
void CReadDNADlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReadDNADlg)
DDX_Control(pDX, IDC_LIST1, m_listdata);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReadDNADlg, CDialog)
//{{AFX_MSG_MAP(CReadDNADlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_READ, OnRead)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_FREQ, OnFreq)
ON_BN_CLICKED(IDC_OUTPUT, OnOutput)
ON_BN_CLICKED(IDC_CENTROID, OnCentroid)
ON_BN_CLICKED(IDC_COSINE, OnCosine)
ON_BN_CLICKED(IDC_ECLIDEAN, OnEclidean)
ON_BN_CLICKED(IDC_SOLUTION, OnSolution)
ON_BN_CLICKED(IDC_GEO, OnGeo)
ON_BN_CLICKED(IDC_RESULT, OnResult)
ON_BN_CLICKED(IDC_CENTANA, OnCentana)
ON_BN_CLICKED(IDC_CLUST, OnClust)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadDNADlg message handlers
BOOL CReadDNADlg::OnInitDialog()
{
CDialog::OnInitDialog();
InitList();
for (int j=0;j<40;j++)
for (int k=0;k<4;k++)
freq[j][k]=0;
for (j=0;j<40;j++)
for (int k=0;k<4;k++)
fret[j][k]=0;
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CReadDNADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CReadDNADlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CReadDNADlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CReadDNADlg::OnRead()
{
CString res;
CFileDialog dlg(true,"*.txt",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.TXT)|*.txt||",NULL);
dlg.DoModal();
char strchar;
CStdioFile file(dlg.GetPathName(),CFile::modeRead);
m_listdata.DeleteAllItems();
for (int i=0;i<40;i++)
{
res.Format("%d",i+1);
m_listdata.InsertItem(i,res);
do
{
file.Read(&strchar,1);
switch(strchar) {
case 'a':
freq[i][0]++;
break;
case 'g':
freq[i][1]++;
break;
case 'c':
freq[i][2]++;
break;
case 't':
freq[i][3]++;
break;
default:
break;
}
} while(strchar!='\n');
res.Format("%d",freq[i][0]);
m_listdata.SetItemText(i,1,res);
res.Format("%d",freq[i][1]);
m_listdata.SetItemText(i,2,res);
res.Format("%d",freq[i][2]);
m_listdata.SetItemText(i,3,res);
res.Format("%d",freq[i][3]);
m_listdata.SetItemText(i,4,res);
}
UpdateData(false);
CalcFreq();
IsRead=true;
}
void CReadDNADlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void CReadDNADlg::InitList()
{
m_listdata.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_listdata.InsertColumn(0,"样本");
m_listdata.InsertColumn(1,"A");
m_listdata.InsertColumn(2,"G");
m_listdata.InsertColumn(3,"C");
m_listdata.InsertColumn(4,"T");
m_listdata.SetColumnWidth(0,62);
m_listdata.SetColumnWidth(1,70);
m_listdata.SetColumnWidth(2,70);
m_listdata.SetColumnWidth(3,70);
m_listdata.SetColumnWidth(4,70);
}
void CReadDNADlg::OnFreq()
{
m_listdata.DeleteAllItems();
CString res;
for (int i=0;i<40;i++)
{
res.Format("%d",i+1);
m_listdata.InsertItem(i,res);
res.Format("%f",fret[i][0]);
m_listdata.SetItemText(i,1,res);
res.Format("%f",fret[i][1]);
m_listdata.SetItemText(i,2,res);
res.Format("%f",fret[i][2]);
m_listdata.SetItemText(i,3,res);
res.Format("%f",fret[i][3]);
m_listdata.SetItemText(i,4,res);
}
}
void CReadDNADlg::CalcFreq()
{
float sum=0;
for (int i=0;i<40;i++)
{
sum=0;
for (int j=0;j<4;j++)
{
sum+=freq[i][j];
}
for ( j=0;j<4;j++)
{
fret[i][j]=(float)freq[i][j]/sum;
}
}
}
void CReadDNADlg::OnOutput()
{
CString res;
CFileDialog dlg(false,"*.txt",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.TXT)|*.txt||",NULL);
dlg.DoModal();
CStdioFile file(dlg.GetPathName(),CFile::modeCreate|CFile::modeWrite);
for (int i=0;i<40;i++)
{
for (int j=0;j<4;j++)
{
res.Format("%f ",fret[i][j]);
file.WriteString(res);
}
res.Format("\n");
file.WriteString(res);
}
}
void CReadDNADlg::OnCentroid()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgCentroid dlg;
dlg.DoModal();
}
void CReadDNADlg::OnCosine()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgCos dlg;
dlg.DoModal();
}
void CReadDNADlg::OnEclidean()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgEu dlg;
dlg.DoModal();
}
void CReadDNADlg::OnSolution()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgSolution dlg;
dlg.DoModal();
}
void CReadDNADlg::OnGeo()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgGeo dlg;
dlg.DoModal();
}
void CReadDNADlg::OnResult()
{
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
// TODO: Add your control notification handler code here
CDlgResult dlg;
dlg.DoModal();
}
//DEL bool CReadDNADlg::IsRead()
//DEL {
//DEL
//DEL }
void CReadDNADlg::OnCentana()
{
// TODO: Add your control notification handler code here
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgCentAna dlg;
dlg.DoModal();
}
void CReadDNADlg::OnClust()
{
// TODO: Add your control notification handler code here
if(!IsRead)
{
AfxMessageBox("请先读入数据");
return;
}
CDlgClust dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -