📄 donofinddlg.cpp
字号:
// donofindDlg.cpp : implementation file
//
#include "stdafx.h"
#include "donofind.h"
#include "donofindDlg.h"
#include "DirDialog.h"
#include "math.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()
/////////////////////////////////////////////////////////////////////////////
// CDonofindDlg dialog
CDonofindDlg::CDonofindDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDonofindDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDonofindDlg)
m_spval = 0.0;
m_cval = 0.0;
m_donoOutput = _T("");
m_snval = _T("0.95");
m_fpnum = 0;
m_tpnum = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//参数初始化
m_donoTotal=0;
TrainReady=0;
TestReady=0;
m_cval=-4.488039;
m_fpnum=m_tpnum=0;
//初始化 P- 概率表
unsigned char xx;
for(xx=0; xx<9; xx++)
{
ProbNega[xx][0]=0.262;
ProbNega[xx][1]=0.272;
ProbNega[xx][2]=0.231;
if ((xx&0x01)==0)ProbNega[xx][3]=0.236;
else ProbNega[xx][3]=0.235;
}
}
void CDonofindDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDonofindDlg)
DDX_Text(pDX, IDC_SPVAL, m_spval);
DDX_Text(pDX, IDC_CVAL, m_cval);
DDX_Text(pDX, IDC_DONOOUTPUT, m_donoOutput);
DDX_Text(pDX, IDC_SNVAL, m_snval);
DDX_Text(pDX, IDC_FP, m_fpnum);
DDX_Text(pDX, IDC_TP, m_tpnum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDonofindDlg, CDialog)
//{{AFX_MSG_MAP(CDonofindDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TRAINSET, OnTrainset)
ON_BN_CLICKED(IDC_TESTSET, OnTestset)
ON_BN_CLICKED(IDC_LOOKPRO, OnLookpro)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_EN_CHANGE(IDC_SNVAL, OnChangeSnval)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDonofindDlg message handlers
BOOL CDonofindDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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 CDonofindDlg::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 CDonofindDlg::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 CDonofindDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDonofindDlg::OnTrainset()
{
CDirDialog m_path; //建立浏览框的一个类
CFileFind m_find;
CString szDir,path,str,str2,str3;
BOOL res;
char *filestr;
DWORD i=0,lens,atcg1;
CFile file;
unsigned int temp=m_donoTotal;
char flag=0,j=0;
int m_actualNum;
unsigned int m_nNums=0;
unsigned int num=0;//“..”后“,”前的数字
char tranum=0;
//////////////////////////////////////////////////////////////////////////
//提取一个文件夹中的所有txt文档中的donor片段(长度为9),以atcg的ASCII码值存放
//在二维数组m_seg9[1000][9]中
//////////////////////////////////////////////////////////////////////////
if(m_path.DoBrowse(NULL)==IDOK)
{
m_donoTotal=0; //重新设定训练集,清零donor片段个数
szDir=m_path.m_strPath;
if(szDir.Right(1) != "\\")szDir += "\\"; //在路径最后加上“\”
//MessageBox(szDir);
szDir += "*.txt";
res=m_find.FindFile(szDir); //运用FindNextFile之前必须有的一个函数,设置目录及文件类型用
/************************************************************************/
/* 提取9单位的donor片段到 m_seg9[1000][9]中去 */
/************************************************************************/
while(res)
{
res=m_find.FindNextFile(); //若还有文档返回值res为1,否则为0
if(!m_find.IsDirectory() && !m_find.IsDots()) //文件夹以文档形式存,排除目录和/.. /.情况
{
path=m_find.GetFilePath();
file.Open(path,CFile::modeRead);
lens=file.GetLength();
filestr=new char[lens+1];
file.Read(filestr,lens);
file.Close();
if(filestr[0]=='L')//排除非正常格式的干扰文件
{
//定位
atcg1=0,i=0;
while (filestr[atcg1]!='a' && filestr[atcg1]!='t' && filestr[atcg1]!='c' && filestr[atcg1]!='g')atcg1++;
//此时filestr[atcg1]为第一个碱基
do{
while (filestr[i++]!='.') ;
//此时filestr[i]为数字前一个字符“.”(第二个“.”)
//提取 .. 后面的数字
num=0;//“..”后“,”前的数字
tranum=0;
i++;
while(filestr[i] >= '0' && filestr[i] <= '9')
{
//str2.Format("%c",filestr[i]);
//MessageBox(str2);
tranum=filestr[i]-'0';
num = num*10 + tranum;
i++;
//str3.Format("%d",tranum);
//MessageBox(str3);
}
//此时filestr[i]为数字后的第一个字符“,”或“)”
//此时数组第0个元素应存第num-3个基因
m_nNums = (num-3-1)/60;
m_nNums <<= 1; //回车换行是两个操作符,所以行数×2即中间夹杂的数,此种方法是为了快速定位,提高算法效率
flag=0,j=0;
while (1)
{
m_actualNum=atcg1+(num-3-1)+m_nNums+j;
if( filestr[m_actualNum] == 'a' || filestr[m_actualNum] == 't' ||
filestr[m_actualNum] == 'c' || filestr[m_actualNum] == 'g' ||
filestr[m_actualNum] == 'n' || filestr[m_actualNum] == 'k')
{
m_seg9[m_donoTotal][flag]=filestr[m_actualNum];
flag++;
};
j++;
if(flag == 9)break;
}
m_donoTotal++;
}
while(filestr[i] != ')');
}
delete []filestr;
}
}
/************************************************************************/
/*将二维数组m_seg9[1000][9]中atcg处理成概率存到ProbPosi[9][4]中去 */
/************************************************************************/
if(m_donoTotal >= 1)m_donoTotal -= 1;//消除上面最后的加一
unsigned char posi,segNum;
unsigned int p_a=0, p_t=0, p_c=0, p_g=0;
for(posi=0;posi<9;posi++ )
{
p_a=0, p_t=0, p_c=0, p_g=0;
for(segNum=0; segNum<= m_donoTotal; segNum++)
{
switch(m_seg9[segNum][posi])
{
case 'a':p_a++;break;
case 't':p_t++;break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -