
LIST OF THE PROGRAMS


There are the following main programs.

1. construct_feature_values_from_allelefreqs_perlocus.m

A Matlab program of constructing the SNP allele frequency pattern of one locus.


2. find_compatible_trees_of_linear_patterns.m

A Matlab program of finding the compatible phylogenetic trees and branch length configurations for each allele frequency pattern.


3. retrieve_locipatterns_weights.c

A C program of retrieving the pattern indices and weights of all loci according to their encodevecs and genotypes.


4. partition_chromosome_by_projection_joint_classifier.c.
A C program of partitioning a chromosome of selected test subjects into local ancestry segments.



LIST OF THE TOY DATA

We provide toy data for each program.  The toy data comprises only the first few lines of the true data.  Therefore, applying the programs to the toy data won't generate sensible outputs.  If the users want to run the programs, they have to ensure the input data follow the same format in the toy data.

chr22.1kg.phase3.v5.snpconfigcnts.excerpt: The allele frequencies of 20 populations on 5 chromosome 22 loci in the 1000G data.  Each population has three alleles: 0, 1, 2.

chr22_overlap_splitfile001_excerpt.tsv: The SNP data of 1000G and HGDP subjects on 5 chromosome 22 loci.

ID_1000G_HGDP_complete.csv: The IDs, populations and continents of the subjects in the 1000G and HGDP data.

extendedcontinents.tsv: The continents in 1000G and HGDP data.

ALLhighfreq_1000G_HGDP.tsv: The encode vectors and occurring frequencies of all unique patterns inferred from the 1000G data.

combinedconsolidatedextendeduniquepatterns.tsv: The linear patterns and their occurring frequencies pertaining to the six continents.  Here, Europeans and Middle Easterns are combined into one class.  c1-c6 denote the order of these combined populations in the linear patterns.  N+ and N- denote the numbers of loci possessing each linear pattern with the positive and negative directions.

chr22combinedconsolidatedextendedlocipatternweights_excerpts.tsv: The pattern indices and weights of 6 loci on chromosome 22.

mergedcontinentclasslabels.tsv: The merged continental class labels (1-6) of subjects in the 1000G and HGDP data.  Class 0 denotes the 1000G subjects of mixed descendants in Americas.




HOW TO RUN THOSE PROGRAMS


1. construct_feature_values_from_allelefreqs_perlocus.m

Construct the continental assignments of the 20 1000G populations, and set the parameter values.  Then for each locus, read the population allele frequencies and apply construct_feature_values_from_allelefreqs_perlocus to it.


popstrs={'CDX','CHB','JPT','KHV','CHS','BEB','GIH','ITU','PJL','STU','ASW','ACB','ESN','GWD','LWK','MSL','YRI','GBR','FIN','IBS','TSI','CEU','CLM','MXL','PEL','PUR'};
npops=length(popstrs);
selinds=[1:10 13:22];
groupinds=zeros(1,npops);
groupinds(1:5)=4; groupinds(6:10)=3; groupinds(11:12)=6; groupinds(13:17)=1; groupinds(18:22)=2; groupinds(23:26)=5;
ginds=[find(groupinds==1) find(groupinds==2) find(groupinds==3) find(groupinds==4)];
groupinds2=[1*ones(1,5) 2*ones(1,5) 3*ones(1,5) 4*ones(1,5)];
npops2=length(groupinds2);
ngroups2=max(groupinds2);
npoints=npops2;

[ngroupconfigs,groupconfigs,ngvecs,gvecs,ngvecs2,gvecs2,ngs,gpinds,ngpcombvecs,gpcombvecs,n1s,n2s]=enumerate_configs(npoints,ngroups2,groupinds2);

spanrdthre=0.15; delta=0.25; largedthre=0.8; 
smalldthre=0.02; numthre=3; numthre2=2;
nloci=0; totalsnpinfo=zeros(1,2); ind=0;
encodevecs=zeros(1,(npops2+3+npops2*(npops2-1)/2));

chr=22;
filename=sprintf('../exampledata/chr%d.1kg.phase3.v5.snpconfigcnts.excerpts',chr);
fp=fopen(filename,'r');
s=fgets(fp); flag=1; 
 
while (flag==1)

 s=fgets(fp);  
 if ((length(s)<1)|(s<1))
  flag=0;
 else
  ind=ind+1;
  curpos=1;
  [curpos,item]=getnextitemval(s,curpos,9);
  val1=atof2(item);
  [curpos,item]=getnextitemval(s,curpos,9);
  val2=atof2(item);
  totalsnpinfo(ind,:)=[val1 val2];
  for i=3:9
   [curpos,item]=getnextitemval(s,curpos,9);
  end
  M=zeros(npops,3); 
  for i=1:npops
   for j=1:3
    [curpos,item]=getnextitemval(s,curpos,9);
    val=atof2(item);
    M(i,j)=val;
   end
  end
  PM=zeros(npops,3);
  for i=1:npops
   PM(i,:)=M(i,:)/sum(M(i,:));
  end
  F=zeros(npops,3);
  for i=1:npops
   F(i,:)=M(i,:)/sum(M(i,:));
  end
  F2=F(ginds,[1 3]);
  C=M(ginds,:); npoints=length(ginds);
  if (sum(sum(~((F2>=0)&(F2<=1))))>0)
   encodevec=zeros(1,(npops2+3+npops2*(npops2-1)/2));
  else
   encodevec=construct_feature_values_from_allelefreqs_perlocus(C,spanrdthre,delta,largedthre,smalldthre,numthre,numthre2,ngroups2,groupinds2,ngroupconfigs,groupconfigs,ngvecs,gvecs,ngvecs2,gvecs2,ngs,gpinds,ngpcombvecs,gpcombvecs,n1s,n2s);
  end
  encodevecs(ind,:)=encodevec;
 end
end
fclose(fp);



2. find_compatible_trees_of_linear_patterns

This program manually generates all compatible trees consistent with each linear pattern.  The program applies only to the 1000G linear patterns of four continents.

Run find_compatible_trees_of_linear_patterns on Matlab.



3. Retrieve the linear pattern indices and weights of all loci in the SNP data

Execute the C program retrieve_locipatterns_weights with the following inputs: directories of the input SNP data and output files, names of the continents, IDs and populations and continents of subjects in the data, the encode vectors of unique patterns and their occurring frequencies, the suffix of the files of SNP data, the suffix of the files of the encode vectors of the corresponding loci.  The outputs are the suffix of the pattern indices and weights of the loci, and the summary of all unique linear patterns at continental level.  The input arguments are depicted in the C code.  Here the pattern indices and weights of a few loci on chromosome 22 are recorded in chr22combinedconsolidatedextendedlocipatternweights_excerpts.tsv.


4. Partition a chromosome into segments of distinct local ancestry according to the linear patterns of the loci.

Execute the C program partition_chromosome_by_projection_joint_classifier2_1000G_HGDP with the following inputs: directories of the input SNP data and output files, chromosome number, several threshold parameters pertaining to the classifiers of local ancestry, the suffix of the training SNP data, the suffix of the pattern indices and weights of the corresponding loci, the suffix of the test SNP data, the ranges of the window sizes, the class labels of subjects in the training data, the unique linear patterns, the suffix of the output file of segments, the selected test subject IDs to be assessed.  The input arguments are depicted in the C code.  The inferred segments of a few test subjects are reported in chr22_overlap_splitfile_training_WestCombined_excerpts.tsv.




