メモ ハプロタイプ・ディプロタイプの組換え履歴を分岐木管理
package homoStretch;
import java.io.IOException;
public class CousinMarriage {
int id;
int gen;
int num;
int[] numInGen;
Person[] person;
int len;
double rec;
Person rootPerson=new Person(-1,-1);
public CousinMarriage(int id,int gen,int num,int[] numInGen,int len,double rec){
this.id=id;
this.gen=gen;
this.num=num;
this.numInGen=numInGen;
this.len=len;
this.rec=rec;
person=new Person[num];
int id0=0;int gen0=0;int idInGen0=0;
int[] hapid0={0,1};
Person[] parents0 = {rootPerson,rootPerson};
person[0]=new Person(id0,gen0,idInGen0,hapid0,parents0,len);
//person[0].Print("\t", "\n");
id0=1;gen0=0;idInGen0=1;
int[] hapid1={2,3};
person[1]=new Person(id0,gen0,idInGen0,hapid1,parents0,len);
//person[1].Print("\t", "\n");
id0=2;gen0=0;idInGen0=2;
int[] hapid2={4,5};
person[2]=new Person(id0,gen0,idInGen0,hapid2,parents0,len);
//person[2].Print("\t", "\n");
id0=3;gen0=0;idInGen0=3;
int[] hapid3={6,7};
person[id0]=new Person(id0,gen0,idInGen0,hapid3,parents0,len);
//person[2].Print("\t", "\n");
id0=4;gen0=0;idInGen0=4;
int[] hapid4={8,9};
person[id0]=new Person(id0,gen0,idInGen0,hapid4,parents0,len);
//person[2].Print("\t", "\n");
id0=5;gen0=0;idInGen0=5;
int[] hapid5={10,11};
person[id0]=new Person(id0,gen0,idInGen0,hapid5,parents0,len);
//person[2].Print("\t", "\n");
/*
id0=5;gen0=1;idInGen0=3;
int[] hapid3={6,7};
person[5]=new Person(id0,gen0,idInGen0,hapid3,parents0,len);
//person[5].Print("\t", "\n");
*/
id0=6;gen0=1;idInGen0=0;
person[id0]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[3].Print("\t", "\n");
id0=7;gen0=1;idInGen0=1;
person[id0]=Child(id0,gen0,idInGen0,person[2],person[3],len,rec);
//person[3].Print("\t", "\n");
id0=8;gen0=1;idInGen0=2;
person[id0]=Child(id0,gen0,idInGen0,person[2],person[3],len,rec);
//person[3].Print("\t", "\n");
id0=9;gen0=1;idInGen0=3;
person[id0]=Child(id0,gen0,idInGen0,person[4],person[5],len,rec);
//person[3].Print("\t", "\n");
id0=10;gen0=2;idInGen0=0;
person[id0]=Child(id0,gen0,idInGen0,person[6],person[7],len,rec);
//person[3].Print("\t", "\n");
id0=11;gen0=2;idInGen0=1;
person[id0]=Child(id0,gen0,idInGen0,person[8],person[9],len,rec);
//person[3].Print("\t", "\n");
/*
id0=4;gen0=1;idInGen0=2;
person[4]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[4].Print("\t", "\n");
id0=6;gen0=2;idInGen0=0;
person[6]=Child(id0,gen0,idInGen0,person[2],person[3],len,rec);
//person[6].Print("\t", "\n");
id0=7;gen0=2;idInGen0=1;
person[7]=Child(id0,gen0,idInGen0,person[4],person[5],len,rec);
//person[7].Print("\t", "\n");
*/
/*
for(int i=0;i<12;i++){
person[i].Print("\t", "\n");
}
*/
for(int i=0;i<numInGen[3];i++){
id0=12+i;gen0=3;idInGen0=i;
person[id0]=Child(id0,gen0,idInGen0,person[10],person[11],len,rec);
//person[id0].Print("\t", "\n");
person[id0].PrintDiplotype(len);
}
}
static Person Child(int id,int gen,int idInGen,Person p1,Person p2,int len,double rec){
Person[] prnt={p1,p2};
int ch=0;
double rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree=new BinarySearchTreeHaplotype();
int preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec1\t"+i);
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree);
//System.out.println("===========");
ch=0;
rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree2=new BinarySearchTreeHaplotype();
preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec2\t"+i);
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree2);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree2);
Person ret = new Person(id,gen,idInGen,tree,tree2,prnt);
ret.diplotree=BinarySearchTreeHaplotype.MakeDiplotype(ret.haptree[0],ret.haptree[1], len);
//ret.PrintDiplotype(len);
return ret;
}
public static void main(String[] args) throws IOException{
/*
* Make Cousin Marriage with "k" offsprings from cousin-pair
*/
int id=0;
int gen=4;
int numK=1;
int[] numInGen={6,4,2,numK};
int num=sum(numInGen);
int len=3000000;
double rec=10000;
CousinMarriage f=new CousinMarriage(id,gen,num,numInGen,len,rec);
}
static int sum(int[] a){
int ret=0;
for(int i=0;i<a.length;i++){
ret+=a[i];
}
return ret;
}
}
package homoStretch;
import java.io.IOException;
public class CousinMarriage {
int id;
int gen;
int num;
int[] numInGen;
Person[] person;
int len;
double rec;
Person rootPerson=new Person(-1,-1);
public CousinMarriage(int id,int gen,int num,int[] numInGen,int len,double rec){
this.id=id;
this.gen=gen;
this.num=num;
this.numInGen=numInGen;
this.len=len;
this.rec=rec;
person=new Person[num];
int id0=0;int gen0=0;int idInGen0=0;
int[] hapid0={0,1};
Person[] parents0 = {rootPerson,rootPerson};
person[0]=new Person(id0,gen0,idInGen0,hapid0,parents0,len);
//person[0].Print("\t", "\n");
id0=1;gen0=0;idInGen0=1;
int[] hapid1={2,3};
person[1]=new Person(id0,gen0,idInGen0,hapid1,parents0,len);
//person[1].Print("\t", "\n");
id0=2;gen0=1;idInGen0=0;
int[] hapid2={4,5};
person[2]=new Person(id0,gen0,idInGen0,hapid2,parents0,len);
//person[2].Print("\t", "\n");
id0=5;gen0=1;idInGen0=3;
int[] hapid3={6,7};
person[5]=new Person(id0,gen0,idInGen0,hapid3,parents0,len);
//person[5].Print("\t", "\n");
id0=3;gen0=1;idInGen0=1;
person[3]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[3].Print("\t", "\n");
id0=4;gen0=1;idInGen0=2;
person[4]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[4].Print("\t", "\n");
id0=6;gen0=2;idInGen0=0;
person[6]=Child(id0,gen0,idInGen0,person[2],person[3],len,rec);
//person[6].Print("\t", "\n");
id0=7;gen0=2;idInGen0=1;
person[7]=Child(id0,gen0,idInGen0,person[4],person[5],len,rec);
//person[7].Print("\t", "\n");
for(int i=0;i<numInGen[3];i++){
id0=8+i;gen0=3;idInGen0=i;
person[id0]=Child(id0,gen0,idInGen0,person[6],person[7],len,rec);
//person[id0].Print("\t", "\n");
person[id0].PrintDiplotype(len);
}
}
static Person Child(int id,int gen,int idInGen,Person p1,Person p2,int len,double rec){
Person[] prnt={p1,p2};
int ch=0;
double rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree=new BinarySearchTreeHaplotype();
int preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec1\t"+i);
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree);
//System.out.println("===========");
ch=0;
rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree2=new BinarySearchTreeHaplotype();
preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec2\t"+i);
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree2);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree2);
Person ret = new Person(id,gen,idInGen,tree,tree2,prnt);
ret.diplotree=BinarySearchTreeHaplotype.MakeDiplotype(ret.haptree[0],ret.haptree[1], len);
//ret.PrintDiplotype(len);
return ret;
}
public static void main(String[] args) throws IOException{
/*
* Make Cousin Marriage with "k" offsprings from cousin-pair
*/
int id=0;
int gen=4;
int numK=1;
int[] numInGen={2,4,2,numK};
int num=sum(numInGen);
int len=1000000;
double rec=1000;
CousinMarriage f=new CousinMarriage(id,gen,num,numInGen,len,rec);
}
static int sum(int[] a){
int ret=0;
for(int i=0;i<a.length;i++){
ret+=a[i];
}
return ret;
}
}
package homoStretch;
public class Person {
public int id;
public int gen;
public int idInGen;
//public int seq;
public BinarySearchTreeHaplotype haptree;
public BinarySearchTreeHaplotype diplotree;
public Person parents;
public Person children;
public int diplotypeList;
public void PrintDiplotype(int len){
//int ret=new int[diplotree.numNode][3];
//int counter=0;
System.out.println("DDDDDDDDDDDDDDDDDDD");
int tmp={haptree[0].searchNode(len-1).base,
haptree[1].searchNode(len-1).base};
diplotree.PrintDiplotype(tmp);
System.out.println("DDDDDDDDDDDDDDDDDDD");
/*
double tmpanswer= diplotree.GetInfoNode();
System.out.println("$$$$$$$$$$$$");
for(int i=0;i
id=id_;
gen=gen_;
idInGen=idInGen_;
//seq =StatUtilsX.MiscUtilX.DeepCopyInt3(seq);
haptree = new BinarySearchTreeHaplotype[2];
haptree[0]=new BinarySearchTreeHaplotype();
haptree[1]=new BinarySearchTreeHaplotype();
haptree[0].insertNode((double)len-1,hapid[0]);
haptree[1].insertNode((double)len-1,hapid[1]);
parents=new Person[2];
parents[0]=parents_[0];
parents[1]=parents_[1];
diplotree = BinarySearchTreeHaplotype.MakeDiplotype(haptree[0],haptree[1], len);
//PrintDiplotype(len);
}
public Person(int id_,int gen_,int idInGen_,BinarySearchTreeHaplotype tr1,BinarySearchTreeHaplotype tr2, Person parents_){
id=id_;
gen=gen_;
idInGen=idInGen_;
//seq =StatUtilsX.MiscUtilX.DeepCopyInt3(seq);
haptree = new BinarySearchTreeHaplotype[2];
haptree[0]=tr1;
haptree[1]=tr2;
parents=new Person[2];
parents[0]=parents_[0];
parents[1]=parents_[1];
//diplotree = haptree[0].MakeDiplotype(haptree[1], len);
//Diplotype(len);
}
public Person(int id,int gen){
//rootPerson
this.id=id;
this.gen=gen;
}
public void Print(String sep1,String sep2){
System.out.print(String(sep1,sep2));
System.out.print("hap1"+sep2);
System.out.print("numRec"+sep1+haptree[0].numNode+sep2);
System.out.print("########"+sep2);
haptree[0].printNode();
System.out.print("hap2"+sep2);
System.out.print("numRec"+sep1+haptree[1].numNode+sep2);
System.out.print("########"+sep2);
haptree[1].printNode();
System.out.println();
System.out.print("diplotree"+sep2);
diplotree.printNode();
}
public String String(String sep1,String sep2){
String ret="---------------"+sep2;
ret+=id+sep2;
ret+=gen+sep2;
ret+=idInGen+sep2;
return ret;
}
}
- 旧版
package homoStretch;
import java.io.IOException;
public class CousinMarriage {
int id;
int gen;
int num;
int[] numInGen;
Person[] person;
int len;
double rec;
Person rootPerson=new Person(-1,-1);
public CousinMarriage(int id,int gen,int num,int[] numInGen,int len,double rec){
this.id=id;
this.gen=gen;
this.num=num;
this.numInGen=numInGen;
this.len=len;
this.rec=rec;
person=new Person[num];
int id0=0;int gen0=0;int idInGen0=0;
int[] hapid0={0,1};
Person[] parents0 = {rootPerson,rootPerson};
person[0]=new Person(id0,gen0,idInGen0,hapid0,parents0,len);
//person[0].Print("\t", "\n");
id0=1;gen0=0;idInGen0=1;
int[] hapid1={2,3};
person[1]=new Person(id0,gen0,idInGen0,hapid1,parents0,len);
//person[1].Print("\t", "\n");
id0=2;gen0=1;idInGen0=0;
int[] hapid2={4,5};
person[2]=new Person(id0,gen0,idInGen0,hapid2,parents0,len);
//person[2].Print("\t", "\n");
id0=5;gen0=1;idInGen0=3;
int[] hapid3={6,7};
person[5]=new Person(id0,gen0,idInGen0,hapid3,parents0,len);
//person[5].Print("\t", "\n");
id0=3;gen0=1;idInGen0=1;
person[3]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[3].Print("\t", "\n");
id0=4;gen0=1;idInGen0=2;
person[4]=Child(id0,gen0,idInGen0,person[0],person[1],len,rec);
//person[4].Print("\t", "\n");
id0=6;gen0=2;idInGen0=0;
person[6]=Child(id0,gen0,idInGen0,person[2],person[3],len,rec);
//person[6].Print("\t", "\n");
id0=7;gen0=2;idInGen0=1;
person[7]=Child(id0,gen0,idInGen0,person[4],person[5],len,rec);
//person[7].Print("\t", "\n");
for(int i=0;i<numInGen[3];i++){
id0=8+i;gen0=3;idInGen0=i;
person[id0]=Child(id0,gen0,idInGen0,person[6],person[7],len,rec);
//person[id0].Print("\t", "\n");
person[id0].PrintDiplotype(len);
}
}
static Person Child(int id,int gen,int idInGen,Person p1,Person p2,int len,double rec){
Person[] prnt={p1,p2};
int ch=0;
double rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree=new BinarySearchTreeHaplotype();
int preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec1\t"+i);
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p1.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree);
//System.out.println("===========");
ch=0;
rand=Math.random();
if(rand>0.5){
ch=1;
}
BinarySearchTreeHaplotype tree2=new BinarySearchTreeHaplotype();
preloc=-1;
for(int i=0;i<len-1;i++){
rand=Math.random();
if(rand<1/rec){
//System.out.println("rec2\t"+i);
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)i, tree2);
preloc=i;
}
}
ch++;
if(ch==2){
ch=0;
}
p2.haptree[ch].ExtractAndAddNode((double)preloc, (double)len-1, tree2);
Person ret = new Person(id,gen,idInGen,tree,tree2,prnt);
ret.diplotree=BinarySearchTreeHaplotype.MakeDiplotype(ret.haptree[0],ret.haptree[1], len);
//ret.PrintDiplotype(len);
return ret;
}
public static void main(String[] args) throws IOException{
/*
* Make Cousin Marriage with "k" offsprings from cousin-pair
*/
int id=0;
int gen=4;
int numK=1;
int[] numInGen={2,4,2,numK};
int num=sum(numInGen);
int len=1000000;
double rec=1000;
CousinMarriage f=new CousinMarriage(id,gen,num,numInGen,len,rec);
}
static int sum(int[] a){
int ret=0;
for(int i=0;i<a.length;i++){
ret+=a[i];
}
return ret;
}
}