/*************************************************************************************
* 文件名:DNA序列
* 文件功能描述:一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。
给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员经常会需要在其中找出GC-Ratio最高的子序列。找出GC比例最高的子串。
* 文件作者名:志
* 修改记录:2016-12-11
**************************************************************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/**************************************************************************************
* 函数名: GC_Ratio
* 函数功能说明:找出GC比例最高的子串。
* 输入参数说明:输入一个string型基因序列,和int型子串的长度
* 输出参数说明:
* 返回值说明:
* 修改记录:2016-12-11
* GWDelight Copyright.2015-2016
**************************************************************************************/
char *GC_Ratio(char *str, int n)
{
char *result = (char *)malloc(sizeof(char)*n+1);
if(NULL == result)
{
printf("malloc error");
return NULL;
}
char *p = str;
int i = 0, j = 0, MaxCnt = 0,TemCnt = 0;
for(i; i < strlen(str) - n - 1; i++)
{
for(j; j < n; j++)
{
if(('G' == *(str + i + j)) || ('C' == *(str + i + j)))
TemCnt++;
}
if(TemCnt > MaxCnt)
{
p = str + i;
MaxCnt = TemCnt;
if(n == MaxCnt)
{
break;
}
}
}
if(MaxCnt == 0)
{
return NULL;
}
else
{
strncpy(result,p,n);
return result;
}
}
int main()
{
int n = 0;
char str[2048]={0};
printf("请输入(A/C/G/T)要检测的DNA序列:");
scanf("%s", str);
printf("请输入子串的长度:");
scanf("%d", &n);
printf("%s\n", GC_Ratio(str, n));
}
DNA序列找出GC比例最高的子串
最新推荐文章于 2020-04-19 23:56:12 发布