c++/EEDB/ZDX/ZDXsegment.cpp
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// class level methods for getting statistics
//
//////////////////////////////////////////////////////////////////////////////////////////////////
class level methods for getting statistics
class level methods for getting statistics
double   EEDB::ZDX::ZDXsegment::calc_percent_completed(ZDXdb* zdxdb, bool show) {
  if(!zdxdb) { return -1; }
  int  zdxfd = zdxdb->connect(ZDXREAD);
  if(zdxfd == -1) { return -1; }
  EEDB::ZDX::zdx_chrom_table  ctable;
  int64_t offset = zdxdb->subsystem_offset(2);  
  long count=0;
  long completed=0;
  while(1) {
    if(offset == 0) { break; }
    lseek(zdxfd, offset, SEEK_SET);  
    if(read(zdxfd, &ctable, sizeof(EEDB::ZDX::zdx_chrom_table)) != sizeof(EEDB::ZDX::zdx_chrom_table)) { 
      zdxdb->disconnect();
      break;
    }
    for(int c_idx=0; c_idx<32; c_idx++) {
      zdx_chrom *zchrom = &(ctable.chroms[c_idx]);
      if(zchrom->segments_offset == 0) { break; }
      long num_segs = zchrom->chrom_length / zchrom->segment_size + 1;
      zdx_chrom_segment segments[num_segs];
      lseek(zdxfd, zchrom->segments_offset, SEEK_SET);
      if(read(zdxfd, segments, sizeof(zdx_chrom_segment)*num_segs) != (unsigned)sizeof(zdx_chrom_segment)*num_segs) {
        fprintf(stderr, "zdxsegement error read chrom_table segments\n");
        return -1;
      }
      if(show) { printf("%s %s %s [%d bp] ", ctable.assembly_name, zchrom->name, zchrom->ncbi_accession, zchrom->chrom_length); }
      for(long seg=0; seg<num_segs; seg++) {
        count++;
        if(segments[seg].znode > 0) {
          if(show) { printf("O"); }
          completed++;
        }
        else if(segments[seg].znode < 0) {
          if(show) { printf("X"); }
        }
        else {
          if(show) { printf("-"); }
        }
      }
      if(show) { printf("\n"); }
    }
    offset = ctable.next_chrom_table;
  }
  return (double)completed / (double)count;
}
double EEDB :: ZDX :: ZDXsegment :: calc_percent_completed ( ZDXdb * zdxdb , bool show ) { if ( ! zdxdb ) { return -1 ; } int zdxfd = zdxdb -> connect ( ZDXREAD ) ; if ( zdxfd == -1 ) { return -1 ; } EEDB :: ZDX :: zdx_chrom_table ctable ; int64_t offset = zdxdb -> subsystem_offset ( 2 ) ; long count = 0 ; long completed = 0 ; while ( 1 ) { if ( offset == 0 ) { break ; } lseek ( zdxfd , offset , SEEK_SET ) ; if ( read ( zdxfd , & ctable , sizeof ( EEDB :: ZDX :: zdx_chrom_table ) ) != sizeof ( EEDB :: ZDX :: zdx_chrom_table ) ) { zdxdb -> disconnect ( ) ; break ; } for ( int c_idx = 0 ; c_idx < 32 ; c_idx ++ ) { zdx_chrom * zchrom = & ( ctable . chroms [ c_idx ] ) ; if ( zchrom -> segments_offset == 0 ) { break ; } long num_segs = zchrom -> chrom_length / zchrom -> segment_size + 1 ; zdx_chrom_segment segments [ num_segs ] ; lseek ( zdxfd , zchrom -> segments_offset , SEEK_SET ) ; if ( read ( zdxfd , segments , sizeof ( zdx_chrom_segment ) * num_segs ) != ( unsigned ) sizeof ( zdx_chrom_segment ) * num_segs ) { fprintf ( stderr , " \n " ) ; return -1 ; } if ( show ) { printf ( " " , ctable . assembly_name , zchrom -> name , zchrom -> ncbi_accession , zchrom -> chrom_length ) ; } for ( long seg = 0 ; seg < num_segs ; seg ++ ) { count ++ ; if ( segments [ seg ] . znode > 0 ) { if ( show ) { printf ( " " ) ; } completed ++ ; } else if ( segments [ seg ] . znode < 0 ) { if ( show ) { printf ( " " ) ; } } else { if ( show ) { printf ( " " ) ; } } } if ( show ) { printf ( " \n " ) ; } } offset = ctable . next_chrom_table ; } return ( double ) completed / ( double ) count ; }
class level methods for getting statistics
class level methods for getting statistics
// check if assembly/chrom exists //chrom_tables are subsystem 2 //printf("read chrom_table at %ld\n", offset); //printf("chrom_table [%s]\n", ctable.assembly_name); //printf("%4d: [%s] %d bp, segsize=%d num=%ld\n", c_idx, zchrom->name, zchrom->chrom_length, zchrom->segment_size, num_segs); 