C&C++实现DNA碱基序列的随机基因突变

该程序基于C++,用于模拟DNA序列的随机基因突变,包括替换、增添和缺失三种类型。用户输入碱基序列和突变点数量,程序通过生成随机数确定突变点和类型,输出突变后的序列和统计信息,适用于遗传学研究中的数据处理。
摘要由CSDN通过智能技术生成

一、遗传学相关知识

DNA是所有细胞生物的遗传物质,DNA分子是脱氧核糖核苷酸的多聚体,脱氧核糖核苷酸由碱基、脱氧核糖和磷酸连接起来构成。核糖和磷酸都是相同的,碱基有四种类型:A(腺嘌呤)、G(鸟嘌呤)、C(胞嘧啶)、T(胸腺嘧啶)。从而二级结构脱氧核糖核苷酸也有四种类型。脱氧核糖核苷酸组成了三级结构脱氧核糖核苷酸链,脱氧核糖核苷酸链经过交叉、盘旋形成了DNA分子。

DNA序列的遗传过程中会发生基因突变,基因突变表现为碱基序列发生变化。碱基序列会偶然发生三种类型的突变:替换、增添和缺失。发生突变的位置是随机的,各个位置发生突变的类型是随机的,并且突变后的新碱基也是随机产生的。

二、程序目的及要求

需要一个能够快速实现给定碱基序列随机基因突变的程序,包括三种突变类型:替换、增添和缺失。对于每一个突变点位,只考虑单个基因的突变和单次突变。我们给出需要突变的DNA碱基序列和突变点的数量,每次突变的点位是随机的,每个点位突变的类型也是随机的。程序的流程图如下:

三、程序具体实现

1.输入

需要用户输入一段碱基序列和突变点的数量(应小于序列的长度),输入界面如图:

2.随机突变

(1)随机突变点位的产生

首先,根据碱基序列(长度为m)和突变点的数量n,其中n<m,用随机数函数生成n个用于确定突变点位的随机数,)和n个用于确定每个突变点位突变类型的随机数()。

(2)突变过程

通过链表,从左到右遍历整个碱基序列,根据产生的随机突变点位和每个点位的突变类型进入相应的突变程序板块。大致流程图如下:

替换:将该点位的碱基随机改变为与其不同的碱基

增添:在该点位之后随机添加一个任一类型的碱基

缺失:将该点位的碱基删除

(3)过程记录

运用链表,记录每一突变点位的突变类型,并做统计。

3.输出

输出每一突变点位及其突变类型、新的碱基序列和统计得到的各突变类型的总数。输出界面如图:

四、源代码

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream> 
using namespace std;
#include <vector>
#include <stdlib.h>
#include <time.h> 
#include <string>

int Exchange_count = 0;
int Delete_count = 0;
int Add_count = 0;
int len = 0;

void change(vector<char>& ba,int position,int k)//Random base replacement function
{
    int kind = 0, na = 0, j = 0;
    char ch;
    srand(time(0));
    int nk[2];
    for (j = 0; j < 2; j++)
        nk[j] = rand() % 4;
    switch (k) {
    case 0://substitution
    {
        kind = nk[0];
        switch (kind) {
        case 0:
            ch = 'A';
        case 1:
            ch = 'T';
        case 2:
            ch = 'G';
        case 3:
            ch = 'C';
        }
        ba[position] = ch;
        Exchange_count++;
        break;
    }
    case 1://deletion
    {
        ba.erase(ba.begin() + position);
        Delete_count++;    
        break;
    }
    case 2://addition
    {
        kind = nk[1];
        switch (kind) {
        case 0:
            ch = 'A';
        case 1:
            ch = 'T';
        case 2:
            ch = 'G';
        case 3:
            ch = 'C';
        ba.insert(ba.begin() + position, ch);            
        }
        Add_count++;
        break;
    }
    }
}

int main()
{
    vector<char> base;
    string str;
    FILE* pf;
    int num, amount, rans[256], k[256], i = 0;
    srand(time(0));
    cout << "Please input the original base sequence:" << endl;
    cin >> str;
    cout << "Please input the amount of mutain point:" << endl;
    cin >> num;
    const char* str2 = str.c_str();
    amount = strlen(str2);
    ofstream outfile("base.txt", ios::app);
    outfile << "\n"; outfile << num; outfile << "/"; outfile << amount;
    outfile << "\n"; outfile << str;
    for (i = 0; i < num; i++)
        rans[i] = rand() % amount;//Generate random numbers of points of mutation
    for (i = 0; i < num; i++)
        k[i] = rand() % 3;//Generate random numbers of types of mutation
    printf("The place and type of every mutation's point:\n");
    for (i = 0; i < num; i++)
    {
        switch (k[i])
        {
        case 0:printf("%d-REP ", rans[i]); break;
        case 1:printf("%d-DEL ", rans[i]); break;
        case 2:printf("%d-ADD ", rans[i]); break;
        }
    }        
    printf("\nThe new base sequence:\n");
    for (int i = 0; i <= str.length(); i++)
    {
        base.push_back(str[i]);//Create linked list
    }
    len = base.size();
    for (int i = 0; i < num; i++)//Random replacement of generated points
        change(base,rans[i],k[i]);
    for (vector<char>::iterator it = base.begin(); it != base.end(); it++)
        cout << *it;
    cout << endl;
    cout << "Replace_count:" << Exchange_count << endl;
    cout << "Delete_count:" << Delete_count << endl;
    cout << "Add_count:" << Add_count << endl;
    string str3(base.data(), base.size());
    outfile << "\n";outfile << str3;
    outfile.close();
    return 0;
}

五、程序总结

程序用C和C++实现一段给定碱基序列随机基因突变过程,模拟了生物学中简单基因突变的过程。本程序可以方便一些遗传学研究领域中数据预处理使用,比如计算编辑距离、基因测序等方面。这体现了计算机学科与其他学科的交叉与融合。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Celestial_Wings_2022

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值