@@ -467,7 +467,7 @@ void ti_index_save(const ti_index_t *idx, BGZF *fp)
467467 int32_t i , size , ti_is_be ;
468468 khint_t k ;
469469 ti_is_be = bam_is_big_endian ();
470- bgzf_write (fp , "TBI \1" , 4 );
470+ bgzf_write (fp , "PX2 \1" , 4 );
471471 if (ti_is_be ) {
472472 uint32_t x = idx -> n ;
473473 bgzf_write (fp , bam_swap_endian_4p (& x ), 4 );
@@ -552,8 +552,8 @@ static ti_index_t *ti_index_load_core(BGZF *fp)
552552 return 0 ;
553553 }
554554 bgzf_read (fp , magic , 4 );
555- if (strncmp (magic , "TBI \1" , 4 )) {
556- fprintf (stderr , "[ti_index_load] wrong magic number.\n" );
555+ if (strncmp (magic , "PX2 \1" , 4 )) {
556+ fprintf (stderr , "[ti_index_load] wrong magic number. Re-index if your index file was created by an earlier version of pairix. \n" );
557557 return 0 ;
558558 }
559559 idx = (ti_index_t * )calloc (1 , sizeof (ti_index_t ));
@@ -687,7 +687,7 @@ static void download_from_remote(const char *url)
687687
688688static char * get_local_version (const char * fn )
689689{
690- struct stat sbuf ;
690+ struct stat sbuf ;
691691 char * fnidx = (char * )calloc (strlen (fn ) + 5 , 1 );
692692 strcat (strcpy (fnidx , fn ), ".px2" );
693693 if ((strstr (fnidx , "ftp://" ) == fnidx || strstr (fnidx , "http://" ) == fnidx )) {
@@ -704,8 +704,9 @@ static char *get_local_version(const char *fn)
704704 download_from_remote (url );
705705 free (url );
706706 }
707- if (stat (fnidx , & sbuf ) == 0 ) return fnidx ;
708- free (fnidx ); return 0 ;
707+ if (stat (fnidx , & sbuf ) == 0 ) return fnidx ;
708+ free (fnidx );
709+ return 0 ;
709710}
710711
711712const char * * ti_seqname (const ti_index_t * idx , int * n )
@@ -723,11 +724,11 @@ const char **ti_seqname(const ti_index_t *idx, int *n)
723724ti_index_t * ti_index_load (const char * fn )
724725{
725726 ti_index_t * idx ;
726- char * fname = get_local_version (fn );
727+ char * fname = get_local_version (fn );
727728 if (fname == 0 ) return 0 ;
728729 idx = ti_index_load_local (fname );
729730 if (idx == 0 ) fprintf (stderr , "[ti_index_load] fail to load the index: %s\n" , fname );
730- free (fname );
731+ if ( fname ) free (fname );
731732 return idx ;
732733}
733734
0 commit comments