コード例 #1
0
ファイル: convertf.c プロジェクト: b1234561/AdmixTools
void flip1(SNP *cupt, int phasedmode, int flipreference) 
{
      if (phasedmode == NO)  flipalleles(cupt) ;
      if (phasedmode == YES)  flipalleles_phased(cupt) ;
// just flips genotypes  
      if (flipreference) cswap(&cupt -> alleles[0], &cupt -> alleles[1]) ;
}
コード例 #2
0
int 
mergeit(SNP **snpm1, SNP **snpm2, Indiv ***pindm1, Indiv **indm2, 
 int nums1, int nums2, int numi1, int numi2)   
{
   SNP *cupt1, *cupt2 ;
   int k, x, g, t  ;
   double y ;
   long rlen, packlen ; 
   static unsigned char *packg ;
   unsigned char *buff ;
   Indiv **indm1 ;
   static Indiv **indivmarkers ;
   int numindivs, numsnps ;

   indm1 = *pindm1 ;
   numindivs = numi1 + numi2 ;
   numsnps = nums1 ;
   ZALLOC(indivmarkers, numindivs, Indiv *) ;

   t = 0 ;
   for (x=0; x<numi1; ++x)  {  
    indivmarkers[t] = indm1[x]  ;
    ++t ;
   }
   for (x=0; x<numi2; ++x)  {  
    indivmarkers[t] = indm2[x]  ;
    ++t ;
   }
// we don't bother with a destructor here.   Sloppy code

   y = (double) (numindivs * 2) / (8 * (double) sizeof (char)) ;
   rlen = nnint(ceil(y)) ;
   rlen = MAX(rlen, 48)  ;
   packlen = numsnps*rlen ;
   ZALLOC(packg, packlen, unsigned char) ;
   cclear((unsigned char *) packg, 0XFF, packlen) ;
// wipe to invalid

   buff = packg ;
   for (k=0; k<nums1; k++) {  
    cupt1 = snpm1[k] ;
    x = cupt1 -> tagnumber ;
    if (x < 0 ) cupt1 -> ignore = YES ;
    if (cupt1 -> ignore) continue ;
    cupt2 = snpm2[x] ; 
    if (cupt2 -> isrfake) { 
     if (phasedmode == NO)  flipalleles(cupt2) ;
     if (phasedmode == YES)  flipalleles_phased(cupt2) ;
    }
    for (t=0; t<numi1; ++t) {  
      g = getgtypes(cupt1, t) ;
      if (g<0) continue ;
      wbuff((unsigned char *)buff, t, g) ;
    }
    for (t=0; t<numi2; ++t) {  
      g = getgtypes(cupt2, t) ;
      if (g<0) continue ;
      wbuff((unsigned char *)buff, numi1+t, g) ;
    }
    cupt1 -> ngtypes = numindivs ;
    cupt1 -> pbuff = (char *) buff ;
    buff += rlen ;
   }
   *pindm1 = indivmarkers ;
   return numindivs ;
}