22 * cpoly.c: This program is used to extract heterozygote SNPs from multiple samples
33 * Author: Nick Patterson
44 * Revised by: Mengyao Zhao
5- * Last revise date: 2015-05-07
5+ * Last revise date: 2015-08-10
66 * Contact: mengyao_zhao@hms.harvard.edu
77 */
88
@@ -26,13 +26,7 @@ typedef struct {
2626} ASC ;
2727
2828char * table_path = NULL ;
29- //char *iubfile = NULL ;
30- //char *iubmaskfile = NULL ;
31-
3229char * regname = NULL ;
33- //char *parflist = "/home/np29/biology/neander/nickdir/xwdir/may12src/parfxlm" ;
34- //char *iubfile = "/home/np29/cteam/release/hetfaplus.dblist" ; // default database
35- //char *iubmaskfile = "/home/np29/cteam/release/maskplus.dblist" ;
3630char * iubfile = "/home/mz128/cteam/dblist/hetfa_postmigration.dblist" ;
3731char * iubmaskfile = "/home/mz128/cteam/dblist/mask_postmigration.dblist" ;
3832char * parname = NULL ;
@@ -166,7 +160,7 @@ int main(int argc, char **argv)
166160 else xchrom = atoi (regname ) ;
167161 }
168162
169- fprintf (stderr , "call numlines in [main]\n" );
163+ // fprintf(stderr, "call numlines in [main]\n");
170164 npops = numlines (indivname ) ;
171165 ZALLOC (poplist , npops , char * ) ;
172166 npops = getss (poplist , indivname ) ;
@@ -209,7 +203,6 @@ int main(int argc, char **argv)
209203 lo = lopos ;
210204 hi = MIN (hipos , lo + pagesize ) ;
211205 loadfa (poplist , npops , & fainfo , reg , lo , hi ) ;
212- //fprintf(stderr, "main: fapt->fai: %p\n", fainfo[0]->fai);
213206 printf ("npops: %d\n" , npops ) ;
214207 for (k = 0 ; k < npops ; ++ k ) {
215208 fapt = fainfo [k ] ;
@@ -234,7 +227,6 @@ int main(int argc, char **argv)
234227 reg = regname ;
235228
236229 for (pos = lopos ; pos <= hipos ; ++ pos ) {
237- //t = getiub(cc, ccmask, fainfo, reg, pos) ;
238230 t = getiub (cc , ccmask , fainfo , ss , pos ) ;
239231 if (t == -5 ) break ;
240232 if (t < 0 ) continue ;
@@ -307,9 +299,7 @@ void prints(FILE *fff, int pos, char c1, char c2)
307299 fprintf (fff , "%15s " , sss ) ;
308300 fprintf (fff , "%3s 0 %12d " , regname , pos ) ;
309301 fprintf (fff , "%c %c\n" , c1 , c2 ) ;
310-
311302 return ;
312-
313303}
314304
315305int checktriallelic (char * pc1 , char * pc2 , char x1 , char x2 )
@@ -391,7 +381,7 @@ int getdbname(char *dbase, char *name, char **pfqname)
391381 char * * * names ;
392382 int n , k , t , i ;
393383
394- fprintf (stderr , "call numlines in [getdbname]\n" );
384+ // fprintf(stderr, "call numlines in [getdbname]\n");
395385 n = numlines (dbase ) ;
396386
397387 ZALLOC (names , 3 , char * * ) ;
@@ -435,15 +425,19 @@ int loadfa(char **poplist, int npops, FATYPE ***pfainfo, char *reg, int lopos, i
435425 region = (char * )malloc ((23 + strlen (reg ))* sizeof (char ));
436426 sprintf (region , "%s:%d-%d" , reg , lo , hipos );
437427
438- if (db == 0 ) refname = strcat (table_path , "Href.fa" );
439- else getdbname (iubfile , "Href" , & refname );
428+ if (db == 0 ) {
429+ strcpy (refname , table_path );
430+ strcat (refname , "Href.fa" );
431+ } else getdbname (iubfile , "Href" , & refname );
440432
441433 if (ncall == 1 ) {
442434 ZALLOC (falist , npops , char * ) ;
443435 ZALLOC (famasklist , npops , char * ) ;
444436 if (db == 0 ) {
445- numfalist = setfalist (poplist , npops , ".fa" , falist ) ;
446- t = setfalist (poplist , npops , ".filter.fa" , famasklist ) ;
437+ numfalist = setfalist (poplist , npops , ".ccomp.fa.rz" , falist ) ;
438+ t = setfalist (poplist , npops , ".ccompmask.fa.rz" , famasklist ) ;
439+ //numfalist = setfalist(poplist, npops, ".fa", falist) ;
440+ //t = setfalist(poplist, npops, ".filter.fa", famasklist) ;
447441 } else {
448442 numfalist = getfalist (poplist , npops , iubfile , falist ) ; // set falist with the absolute path of hetfa files in .dblist file
449443 t = getfalist (poplist , npops , iubmaskfile , famasklist ) ;
@@ -524,7 +518,6 @@ int loadfa(char **poplist, int npops, FATYPE ***pfainfo, char *reg, int lopos, i
524518 if (len_s == 0 ) fatalx ("bad fetch %s %s\n" , fapt -> faname , region ); // fetch fai
525519
526520 len = len_r < len_s ? len_r : len_s ;
527- // len = len_s;
528521 if (rz == 1 ) // raziped
529522 for (i = 0 ; i < len ; ++ i )
530523 if (fapt -> rstring [i ] == 'Q' ) fapt -> rstring [i ] = ref [i ];
@@ -620,7 +613,7 @@ int getiub(char *cc, char *ccmask, FATYPE **fainfo, char *reg, int pos)
620613
621614 if (newreg == YES ) {
622615
623- printf ("zznewrrr %s :: %s %d %d %d\n" ,lastreg , regbuff , pos , lastlo , lasthi ) ; fflush (stdout ) ;
616+ // printf("zznewrrr %s :: %s %d %d %d\n",lastreg, regbuff, pos, lastlo, lasthi) ; fflush(stdout) ;
624617 fflush (stdout ) ;
625618 freestring (& regname ) ;
626619
@@ -632,18 +625,17 @@ int getiub(char *cc, char *ccmask, FATYPE **fainfo, char *reg, int pos)
632625 }
633626
634627 if (newpage == YES ) {
635- fprintf (stderr , "pos-getiub: %d\n" , pos );
628+ // fprintf(stderr, "pos-getiub: %d\n", pos);
636629 fflush (stdout ) ;
637630 lastlo = pos ;
638631 lasthi = pos + pagesize ;
639632 lastlo = MAX (lastlo , lopos ) ;
640633 lasthi = MAX (lasthi , hipos ) ;
641634 lasthi = MIN (lasthi , lastlo + pagesize ) ;
642- printf ("calling loodfa %s %d %d \n" , regname , lastlo , lasthi ) ;
635+ // printf("calling loodfa %s %d %d \n", regname, lastlo, lasthi) ;
643636 fflush (stdout ) ;
644- //fprintf(stderr, "getiub: fapt->fai: %p\n", fainfo[0]->fai);
645637 loadfa (poplist , npops , & fainfo , regname , lastlo , lasthi ) ;
646- printf ("newpage: %d %p %d %d\n" , pos , topheap (), lastlo , lasthi ) ;
638+ // printf("newpage: %d %p %d %d\n", pos, topheap(), lastlo, lasthi) ;
647639
648640 fflush (stdout ) ;
649641 }
@@ -769,13 +761,14 @@ int setfalist(char **poplist, int npops, char *dbfile, char **iublist) {
769761 int t ;
770762 for (t = 0 ; t < npops ; ++ t ) {
771763 iublist [t ] = strdup (table_path );
772- iublist [t ] = (char * ) realloc (iublist [t ], 64 );
764+ iublist [t ] = (char * ) realloc (iublist [t ], strlen ( iublist [ t ]) + strlen ( poplist [ t ]) + strlen ( dbfile ) + 1 );
773765 iublist [t ] = strcat (iublist [t ], poplist [t ]);
774- if ((!strcmp (poplist [t ], "Chimp" ) || !strcmp (poplist [t ], "Href" )) && strcmp (dbfile , ".fa" )) {
775- free (iublist [t ]);
766+
767+ if ((!strcmp (poplist [t ], "Chimp" ) || !strcmp (poplist [t ], "Href" )) && !strcmp (dbfile , ".ccomp.fa.rz" ))
768+ iublist [t ] = strcat (iublist [t ], ".fa" );
769+ else if ((!strcmp (poplist [t ], "Chimp" ) || !strcmp (poplist [t ], "Href" )) && !strcmp (dbfile , ".ccompmask.fa.rz" ))
776770 iublist [t ] = "NULL" ;
777- } else
778- iublist [t ] = strcat (iublist [t ], dbfile );
771+ else iublist [t ] = strcat (iublist [t ], dbfile );
779772 }
780773 return npops ;
781774}
@@ -817,25 +810,8 @@ int getfalist(char **poplist, int npops, char *dbfile, char **iublist)
817810
818811 fclose (fff ) ;
819812 return nx ;
820-
821813}
822- /*
823- char *myfai_fetch(faidx_t *fai, char *reg, int *plen)
824- {
825- char *treg, *s ;
826- treg = strdup(reg) ;
827814
828- if (fai==NULL) fatalx("(my_fai_fetch): fai NULL\n") ;
829-
830- s = fai_fetch(fai, treg, plen) ;
831- if (*plen > 0) {
832- free(treg) ;
833- return s ;
834- }
835- free(treg) ;
836- return NULL ;
837- }
838- */
839815void clearfainfo (FATYPE * fapt , int mode )
840816{
841817
@@ -924,7 +900,6 @@ int abx(int a, int b)
924900}
925901
926902int abxok (int abx , int abxmode ) {
927-
928903 int t ;
929904
930905 if (abxmode >= 10 ) {
@@ -933,8 +908,6 @@ int abxok(int abx, int abxmode) {
933908 return NO ;
934909 }
935910
936-
937-
938911 switch (abxmode ) {
939912 case 0 :
940913 return YES ;
0 commit comments