📄 bootamova1.02.c
字号:
#include<fstream.h>
#include <strstrea.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <iostream.h>
#include <ctype.h>
#include <iomanip.h>
#include <time.h>
#define num 2000
struct HapMatrix
{
char Nam[10];
int fi;
char ATGC[num],Freq[2];
}HapM[20];
int main(int argc, char* argv[])
{
srand( (unsigned)time( NULL ) );
char strtemp[num];
int NbSamples;
char NamPop[20][10];
int SampSiz, NumHap;
char seq[100][num];
char ch,*ptr=NULL;
int length;
int boot;
cout<<"Input the number of bootstrap for AMOVA:"<<endl;
cin>>boot;
for(int ib=0;ib<boot;ib++)
{
/*open input.txt and read data*/
ifstream fin("input.txt", ios::in | ios::nocreate);
if (!fin) {
cerr<<"input.txt file not open!"<<endl;
exit(1);
}
/**/
/*open out.txt and write */
ofstream fout("out.dat", ios::app);
if (!fout) {
cerr<<"out.dat file not open!"<<endl;
exit(1);}
fout<<ib+1<<" ===================================="<<endl;
fout<<endl;
fout<<endl;
fout<<"[Profile]"<<endl;
fout<<"Title=\"random data set fo r AMOVA\""<<endl;
fout<<endl;
/*read NbSamples write initial information for AMOVA*/
fin.getline(strtemp,num,ch='\n');
NbSamples=atoi(strtemp);
cout<<NbSamples<<"#"<<endl;
fout<<" NbSamples="<<NbSamples<<endl;
fout<<" GenotypicData=0"<<endl;
fout<<" DataType=DNA"<<endl;
fout<<" LocusSeparator=NONE"<<endl;
fout<<" MissingData='?'"<<endl;
fout<<"[Data]"<<endl;
fout<<endl;
fout<<" [[Samples]]"<<endl;
/*read name of population into NamPop[][]*/
for (int i=0;i<NbSamples;i++)
{
fin.getline(strtemp,num,ch='\n');
strcpy(NamPop[i],strtemp);
}
/*read data from all population and output random datasets*/
for(int ABZ=0;ABZ<NbSamples;ABZ++)
{
/*read name of population and output*/
fin.getline(strtemp,num,ch='\n');
fout<<" SampleName="<<"\""<<strtemp<<"\""<<endl;
/*read sample size and number of haplotye*/
fin.getline(strtemp,num,ch='\n');
SampSiz=atoi(strtemp);
fin.getline(strtemp,num,ch='\n');
NumHap=atoi(strtemp);
fout<<" SampleSize="<<SampSiz<<endl;
cout<<"read sample size and number of haplotye"<<endl;
fout<<" SampleData= {"<<endl;
cout<<"SampleData= {"<<endl;
/*read sequence data into seq[][]*/
for(i=0;i<NumHap;i++)
{
fin.getline(strtemp,num,ch='\n');
length=strlen(strtemp);
strtemp[length]='\0';
strcpy(seq[i],strtemp);
strncpy(HapM[i].Nam,strtemp,10);
strncpy(HapM[i].Freq,strtemp+10,2);
HapM[i].fi=atoi(HapM[i].Freq);
ptr=strstr(strtemp," ");
strcpy(strtemp,ptr);
ptr=strstr(strtemp," ");
strcpy(HapM[i].ATGC,ptr+2);
}
int k1=0;
for(int j=0;j<NumHap;j++)
{
for(int k=0;k<HapM[j].fi;k++)
{
strcpy(seq[k1],HapM[j].ATGC);
k1++;
cout<<"k1="<<k1<<endl;
/*seq[j+k1][strlen(HapM[j].ATGC)]='\0';*/
}
}
/*cout<<seq[0]<<endl<<"&&"<<endl;
cout<<seq[7]<<endl<<"&&"<<endl;*/
for(i=0;i<NumHap;i++)
{
HapM[i].fi=0;
}
for(i=0;i<SampSiz;i++)
{
int RandNum;
if(SampSiz>1)
RandNum=1+rand() % (SampSiz-1);
else RandNum=0;
/*strcpy(strtemp,seq[RandNum]);
strtemp[length]='\0';*/
for (j=0;j<NumHap;j++)
{
int ptr1;
strncpy(strtemp,seq[RandNum],strlen(HapM[j].ATGC));
strtemp[strlen(HapM[j].ATGC)]='\0';
ptr1 = strcmpi(HapM[j].ATGC,strtemp);
/*cout<<HapM[j].ATGC<<endl;
cout<<strtemp<<"!"<<endl;*/
if(ptr1==0)
HapM[j].fi++;
}
/*cout<<"RandNum="<<RandNum<<endl;*/
/*fout<<strtemp<<endl;*/
}
for(j=0;j<NumHap;j++)
{
if(!HapM[j].fi==0)
fout<<HapM[j].Nam<<" "<<HapM[j].fi<<" "<<HapM[j].ATGC<<endl;
}
fout<<" }"<<endl;
cout<<"HapM[j].fi="<<HapM[0].fi<<endl;
cout<<"HapM[j].fi="<<HapM[1].fi<<endl;
cout<<"HapM[j].fi="<<HapM[2].fi<<endl;
/*for(i=0;i<SampSiz;i++)
{
cout<<seq[i]<<endl;
}*/
/*}*/
}
fout<<endl;
fout<<"#Definition of the group structure:"<<endl;
fout<<" [[Structure]]"<<endl;
fout<<" StructureName=\"Geographical division\""<<endl;
fout<<" NbGroups=1"<<endl;
fout<<" IndividualLevel=0"<<endl;
fout<<" Group={"<<endl;
for(i=0;i<NbSamples;i++)
{fout<<" "<<NamPop[i]<<endl;
}
fout<<" }"<<endl;
fout<<endl;
fout<<endl;
fout<<endl;
fin.close();
fout.close();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -