NTSTATUS HookModuleInit(PDRIVER_OBJECT DriverObject, PVOID Context) { NTSTATUS status = STATUS_UNSUCCESSFUL; DEBUG_ENTER_FUNCTION("DriverObject=0x%p; Context=0x%p", DriverObject, Context); UNREFERENCED_PARAMETER(DriverObject); UNREFERENCED_PARAMETER(Context); KeInitializeSpinLock(&_driverValidationTableLock); status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _DriverValidationCompareFunction, NULL, &_driverValidationTable); if (NT_SUCCESS(status)) { KeInitializeSpinLock(&_deviceValidationTableLock); status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _DeviceValidationCompareFunction, NULL, &_deviceValidationTable); if (NT_SUCCESS(status)) { KeInitializeSpinLock(&_driverTableLock); status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _DriverCompareFunction, _DriverFreeFunction, &_driverTable); if (!NT_SUCCESS(status)) HashTableDestroy(_deviceValidationTable); } if (!NT_SUCCESS(status)) HashTableDestroy(_driverValidationTable); } DEBUG_EXIT_FUNCTION("0x%x", status); return status; }
/* * Resizes a HashTable to have 'newsize' buckets. * This is called automatically when adding or removing items so that the * hash table keeps at a sensible scale. * * FIXME: Halving the size of the hash table is simply a matter of coaelescing * every other bucket. Instead we currently rehash (which is slower). * Doubling the size of the hash table currently requires rehashing, but this * too could be optimised by storing the full 32-bit hash of the key along * with the key itself. This then means that it's just a matter of seeing what * the next significant bit is. It's a memory vs speed tradeoff though and * re-hashing is pretty quick. * * Returns 0 for success * -1 for failure */ int HashTableResize(HashTable *h, int newsize) { HashTable *h2; int i; /* fprintf(stderr, "Resizing to %d\n", newsize); */ /* Create a new hash table and rehash everything into it */ h2 = HashTableCreate(newsize, h->options); for (i = 0; i < h->nbuckets; i++) { HashItem *hi, *next; for (hi = h->bucket[i]; hi; hi = next) { uint64_t hv = hash64(h2->options & HASH_FUNC_MASK, (uint8_t *)hi->key, hi->key_len) & h2->mask; next = hi->next; hi->next = h2->bucket[hv]; h2->bucket[hv] = hi; } } /* Swap the links over & free */ free(h->bucket); h->bucket = h2->bucket; h->nbuckets = h2->nbuckets; h->mask = h2->mask; free(h2); return 0; }
/* * Initialise results structure */ chksum_results_t *chksum_init_results(HASH_TYPE hash) { chksum_results_t *results = malloc(sizeof(chksum_results_t)); init_digest_line(hash, &(results->all)); results->rgHash = HashTableCreate(0, HASH_DYNAMIC_SIZE | HASH_FUNC_JENKINS); return results; }
HashTable *load_map(char *fn) { HashTable *h = HashTableCreate(65536, HASH_DYNAMIC_SIZE | HASH_POOL_ITEMS); FILE *fp; char line[8192]; if (NULL == (fp = fopen(fn, "r"))) { perror(fn); return NULL; } while(fgets(line, 8192, fp)) { char *cp, *from, *to; HashData hd; for (from = cp = line; *cp && !isspace(*cp); cp++); if (!*cp) { fprintf(stderr, "Malformed line '%s'\n", line); return NULL; } *cp++ = 0; for (to = cp; isprint(*cp); cp++); *cp++ = 0; hd.p = strdup(to); if (!HashTableAdd(h, from, strlen(from), hd, NULL)) return NULL; } close(fp); return h; }
static void createHashTables( void ) //********************************** { SymbolToTargetTable = HashTableCreate( SYMBOL_TO_TARGET_TABLE_SIZE, HASH_NUMBER, numberCmp ); if( !SymbolToTargetTable ) { SysError( ERR_OUT_OF_MEM, false ); } SymbolToExportTable = HashTableCreate( SYMBOL_TO_EXPORT_TABLE_SIZE, HASH_NUMBER, numberCmp ); if( !SymbolToExportTable ) { SysError( ERR_OUT_OF_MEM, false ); } SectionToSegmentTable = HashTableCreate( SECTION_TO_SEGMENT_TABLE_SIZE, HASH_NUMBER, numberCmp ); if( !SectionToSegmentTable ) { SysError( ERR_OUT_OF_MEM, false ); } }
NTSTATUS HandleTableCreate(EHashTableType HandleTableType, CHANDLE_TABLE_HANDLE_CREATED *HandleCreateProcedure, CHANDLE_TABLE_HANDLE_DELETED *HandleDeleteProcedure, CHANDLE_TABLE_HANDLE_TRANSLATED *HandleTranslateProcedure, PCHANDLE_TABLE *HandleTable) { POOL_TYPE poolType = (HandleTableType == httPassiveLevel) ? PagedPool : NonPagedPool; PCHANDLE_TABLE tmpHandleTable = NULL; NTSTATUS status = STATUS_UNSUCCESSFUL; DEBUG_ENTER_FUNCTION("HandleTableType=%u; HandleCreateProcedure=0x%p; HandleDeleteProcedure=0x%p; HandleTranslateProcedure=0x%p; HandleTable=0x%p", HandleTableType, HandleCreateProcedure, HandleDeleteProcedure, HandleTranslateProcedure, HandleTable); tmpHandleTable = (PCHANDLE_TABLE)HeapMemoryAllocNonPaged(sizeof(CHANDLE_TABLE)); if (tmpHandleTable != NULL) { tmpHandleTable->NextFreeHandle = 1; tmpHandleTable->HandleTableType = HandleTableType; tmpHandleTable->PoolType = poolType; tmpHandleTable->HandleCreateProcedure = HandleCreateProcedure; tmpHandleTable->HandleDeleteProcedure = HandleDeleteProcedure; tmpHandleTable->HandleTranslateProcedure = HandleTranslateProcedure; switch (tmpHandleTable->HandleTableType) { case httPassiveLevel: status = ExInitializeResourceLite(&tmpHandleTable->LockP); break; case httDispatchLevel: KeInitializeSpinLock(&tmpHandleTable->LockD); tmpHandleTable->ExclusiveLocker = NULL; status = STATUS_SUCCESS; break; case httNoSynchronization: status = STATUS_SUCCESS; break; default: status = STATUS_NOT_SUPPORTED; break; } if (NT_SUCCESS(status)) { status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _CompareFunction, _FreeFunction, &tmpHandleTable->HashTable); if (NT_SUCCESS(status)) *HandleTable = tmpHandleTable; if (!NT_SUCCESS(status)) { switch (tmpHandleTable->HandleTableType) { case httPassiveLevel: ExDeleteResourceLite(&tmpHandleTable->LockP); break; case httDispatchLevel: break; case httNoSynchronization: break; default: break; } } } if (!NT_SUCCESS(status)) HeapMemoryFree(tmpHandleTable); } else status = STATUS_INSUFFICIENT_RESOURCES; DEBUG_EXIT_FUNCTION("0x%x, *HandleTable=0x%p", status, *HandleTable); return status; }
/* * Removes some or all tags from some or all contigs. * If the contig list or tag list is blank it implies all contigs or all tags. * * Returns 0 on success * -1 on failure */ int delete_tags(GapIO *io, int ncontigs, contig_list_t *contigs, char *tag_list, int verbose) { HashTable *h = NULL; int ret = 0; /* Hash tag types */ if (tag_list && *tag_list) { int i; if (SetActiveTags(tag_list) == -1) { return -1; } h = HashTableCreate(32, 0); for (i = 0; i < number_of_active_tags; i++) { HashData hd; hd.i = 0; HashTableAdd(h, active_tag_types[i], 4, hd, NULL); } } /* Iterate over contig list or all contigs */ if (verbose) vfuncheader("Delete Tags"); if (ncontigs) { int i; for (i = 0; i < ncontigs; i++) { contig_t *c = cache_search(io, GT_Contig, contigs[i].contig); vmessage("Scanning contig %d of %d (%s)\n", i+1, ncontigs, c->name); ret |= delete_tag_single_contig(io, contigs[i].contig, h, verbose); UpdateTextOutput(); cache_flush(io); } } else { int i; tg_rec *order = ArrayBase(tg_rec, io->contig_order); for (i = 0; i < NumContigs(io); i++) { contig_t *c = cache_search(io, GT_Contig, order[i]); vmessage("Scanning contig %d of %d (%s)\n", i+1, NumContigs(io), c->name); ret |= delete_tag_single_contig(io, order[i], h, verbose); UpdateTextOutput(); cache_flush(io); } } SetActiveTags(""); if (h) HashTableDestroy(h, 0); return ret; }
static return_val createHashTables( void ) { HandleToSectionTable = HashTableCreate( HANDLE_TO_SECTION_TABLE_SIZE, HASH_NUMBER, NumberCmp ); if( HandleToSectionTable ) { HandleToLabelListTable = HashTableCreate( HANDLE_TO_LIST_TABLE_SIZE, HASH_NUMBER, NumberCmp ); if( HandleToLabelListTable ) { HandleToRefListTable = HashTableCreate( HANDLE_TO_LIST_TABLE_SIZE, HASH_NUMBER, NumberCmp ); if( HandleToRefListTable ) { SymbolToLabelTable = HashTableCreate( SYMBOL_TO_LABEL_TABLE_SIZE, HASH_NUMBER, NumberCmp ); if( SymbolToLabelTable ) { NameRecognitionTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING, (hash_table_comparison_func) stricmp ); if( !NameRecognitionTable ) { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); HashTableFree( HandleToRefListTable ); HashTableFree( SymbolToLabelTable ); return( OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); HashTableFree( HandleToRefListTable ); return( OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); return( OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); return( OUT_OF_MEMORY ); } } else { return( OUT_OF_MEMORY ); } return( OKAY ); }
static return_val createHashTables( void ) { HandleToSectionTable = HashTableCreate( HANDLE_TO_SECTION_TABLE_SIZE, HASH_HANDLE ); if( HandleToSectionTable != NULL ) { HandleToLabelListTable = HashTableCreate( HANDLE_TO_LIST_TABLE_SIZE, HASH_HANDLE ); if( HandleToLabelListTable != NULL ) { HandleToRefListTable = HashTableCreate( HANDLE_TO_LIST_TABLE_SIZE, HASH_HANDLE ); if( HandleToRefListTable != NULL ) { SymbolToLabelTable = HashTableCreate( SYMBOL_TO_LABEL_TABLE_SIZE, HASH_HANDLE ); if( SymbolToLabelTable != NULL ) { NameRecognitionTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING_IGNORECASE ); if( NameRecognitionTable == NULL ) { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); HashTableFree( HandleToRefListTable ); HashTableFree( SymbolToLabelTable ); return( RC_OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); HashTableFree( HandleToRefListTable ); return( RC_OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); HashTableFree( HandleToLabelListTable ); return( RC_OUT_OF_MEMORY ); } } else { HashTableFree( HandleToSectionTable ); return( RC_OUT_OF_MEMORY ); } } else { return( RC_OUT_OF_MEMORY ); } return( RC_OKAY ); }
HashTable *readSnpFile(char *snp_file) { FILE *fp; HashTable *snp_hash; static const int line_size = 8192; char line[line_size]; size_t count = 0; char last_chrom[100] = ""; display("reading snp file %s\n", snp_file); fp = fopen(snp_file, "rb"); if (NULL == fp) { die("ERROR: can't open known snp file %s: %s\n", snp_file, strerror(errno)); } if (NULL == (snp_hash = HashTableCreate(0, HASH_DYNAMIC_SIZE | HASH_FUNC_JENKINS3))) { die("ERROR: creating snp hash table\n"); } while (fgets(line, line_size, fp)) { char key[100]; HashData hd; int bin, start, end; char chrom[100]; if (4 != sscanf(line, "%d\t%s\t%d\t%d", &bin, chrom, &start, &end)) { die("ERROR: reading snp file\n%s\n", line); } /* N.B rod start is 0 based */ snprintf(key, sizeof(key), "%s:%d", chrom, start); hd.i = 0; if (NULL == HashTableAdd(snp_hash, key, strlen(key), hd, NULL)) { die("ERROR: building snp hash table\n"); } if (strcmp(chrom, last_chrom)) { strcpy(last_chrom, chrom); count = 0; } count++; } fclose(fp); return snp_hash; }
static NTSTATUS _DriverHookRecordCreate(PDRIVER_OBJECT DriverObject, PDRIVER_MONITOR_SETTINGS MonitorSettings, BOOLEAN MonitoringEnabled, PDRIVER_HOOK_RECORD *Record) { PDRIVER_HOOK_RECORD tmpRecord = NULL; NTSTATUS status = STATUS_UNSUCCESSFUL; DEBUG_ENTER_FUNCTION("DriverObject=0x%p; MonitorSettings=0x%p; MonitoringEnabled=%u; Record=0x%p", DriverObject, MonitorSettings, MonitoringEnabled, Record); tmpRecord = (PDRIVER_HOOK_RECORD)HeapMemoryAllocNonPaged(sizeof(DRIVER_HOOK_RECORD)); if (tmpRecord != NULL) { memset(tmpRecord, 0, sizeof(DRIVER_HOOK_RECORD)); tmpRecord->ReferenceCount = 1; status = _GetObjectName(DriverObject, &tmpRecord->DriverName); if (NT_SUCCESS(status)) { tmpRecord->DriverObject = DriverObject; tmpRecord->MonitoringEnabled = MonitoringEnabled; tmpRecord->MonitorNewDevices = MonitorSettings->MonitorNewDevices; tmpRecord->MonitorStartIo = MonitorSettings->MonitorStartIo; tmpRecord->MonitorAddDevice = MonitorSettings->MonitorAddDevice; tmpRecord->MonitorDriverUnload = MonitorSettings->MonitorUnload; tmpRecord->MonitorIRP = MonitorSettings->MonitorIRP; tmpRecord->MonitorIRPCompletion = MonitorSettings->MonitorIRPCompletion; tmpRecord->MonitorFastIo = MonitorSettings->MonitorFastIo; memcpy(tmpRecord->IRPSettings, MonitorSettings->IRPSettings, sizeof(tmpRecord->IRPSettings)); memcpy(tmpRecord->FastIoSettings, MonitorSettings->FastIoSettings, sizeof(tmpRecord->FastIoSettings)); KeInitializeSpinLock(&tmpRecord->SelectedDevicesLock); status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _DeviceCompareFunction, _DeviceFreeFunction, &tmpRecord->SelectedDevices); if (NT_SUCCESS(status)) *Record = tmpRecord; if (!NT_SUCCESS(status)) HeapMemoryFree(tmpRecord->DriverName.Buffer); } if (!NT_SUCCESS(status)) HeapMemoryFree(tmpRecord); } else status = STATUS_INSUFFICIENT_RESOURCES; DEBUG_EXIT_FUNCTION("0x%x, *Record=0x%p", status, *Record); return status; }
void cram_stats_add(cram_stats *st, int32_t val) { st->nsamp++; //assert(val >= 0); if (val < MAX_STAT_VAL && val >= 0) { st->freqs[val]++; } else { HashItem *hi; if (!st->h) { st->h = HashTableCreate(2048, HASH_DYNAMIC_SIZE|HASH_NONVOLATILE_KEYS|HASH_INT_KEYS); } if ((hi = HashTableSearch(st->h, (char *)(size_t)val, 4))) { hi->data.i++; } else { HashData hd; hd.i = 1; HashTableAdd(st->h, (char *)(size_t)val, 4, hd, NULL); } } }
/* * Main method. */ int main(int argc, char **argv) { int ifile, nfiles; char *input = NULL; int c; int errflg = 0; extern char *optarg; extern int optind, optopt; int level_mode = LEVEL_ALL; long read_count[NREADS]; char *read_str[] = {READ_GOOD_STR, READ_BAD_STR, READ_TOTAL_STR}; long chunk_count[NCHUNKS]; uint64_t chunk_size[NCHUNKS]; uint4 chunk_type[] = {CHUNK_BASE_TYPE, CHUNK_CNF1_TYPE, CHUNK_CNF4_TYPE, CHUNK_SAMP_TYPE, CHUNK_SMP4_TYPE, CHUNK_REGN_TYPE}; long key_count[NCHUNKS][NKEYS]; char *keys_str[] = {KEY_TYPE_STR, KEY_VALTYPE_STR, KEY_GROUP_STR, KEY_OFFS_STR, KEY_SCALE_STR, KEY_COORD_STR, KEY_NAME_STR}; long type_count[NCHUNKS][NTYPES]; char *types_str[] = {TYPE_PROC_STR, TYPE_SLXI_STR, TYPE_SLXN_STR, TYPE_0FAM_STR, TYPE_1CY3_STR, TYPE_2TXR_STR, TYPE_3CY5_STR}; int iread, ichunk, ikey, itype; while ((c = getopt(argc, argv, "l:")) != -1) { switch (c) { case 'l': if (1 != sscanf(optarg, "%d", &level_mode)) { fprintf(stderr, "Otion -%c requires an operand\n", optopt); errflg++; } break; case ':': /* -? without operand */ fprintf(stderr, "Option -%c requires an operand\n", optopt); errflg++; break; case '?': fprintf(stderr, "Unrecognised option: -%c\n", optopt); errflg++; } } if (errflg) { usage(1); } nfiles = (argc-optind); if( nfiles < 1 ){ fprintf(stderr, "Please specify input archive name(s).\n"); usage(1); } for (ifile=0; ifile<nfiles; ifile++) { HashTable *regn_hash; char bases[] = "ACGTN"; uint64_t base_count[5]; char type[5]; input = argv[optind+ifile]; printf("Reading archive %s.\n", input); for (iread=0; iread<NREADS; iread++) read_count[iread] = 0; for (ichunk=0; ichunk<NCHUNKS; ichunk++) { chunk_count[ichunk] = 0; chunk_size[ichunk] = 0; } for (ichunk=0; ichunk<NCHUNKS; ichunk++) for (ikey=0; ikey<NKEYS; ikey++) key_count[ichunk][ikey] = 0; for (ichunk=0; ichunk<NCHUNKS; ichunk++) for (itype=0; itype<NTYPES; itype++) type_count[ichunk][itype] = 0; if (NULL == (regn_hash = HashTableCreate(0, HASH_DYNAMIC_SIZE|HASH_FUNC_JENKINS3))) { return 1; } memset(base_count, 0, 5 * sizeof(uint64_t)); if( 0 == srf_info(input, level_mode, read_count, chunk_count, chunk_size, key_count, type_count, regn_hash, base_count) ){ /* read counts */ if( level_mode & LEVEL_READ ) { for (iread=0; iread<NREADS; iread++) { if( read_count[iread] ) printf("Reads: %s : %ld\n", read_str[iread], read_count[iread]); } } /* chunk, key and type counts */ if( level_mode & LEVEL_CHUNK ) { for (ichunk=0; ichunk<NCHUNKS; ichunk++) { if( chunk_count[ichunk] ) { printf("Chunk: %s : %ld %"PRId64"\n", ZTR_BE2STR(chunk_type[ichunk], type), chunk_count[ichunk], chunk_size[ichunk]); for (ikey=0; ikey<NKEYS; ikey++) { if(key_count[ichunk][ikey]) { printf(" Mdata key: %s : %ld\n", keys_str[ikey], key_count[ichunk][ikey]); if (ikey == KEY_TYPE && (ichunk == CHUNK_SAMP || ichunk == CHUNK_SMP4)) { for (itype=0; itype<NTYPES; itype++) if(type_count[ichunk][itype]) printf(" types: %s : %ld\n", types_str[itype], type_count[ichunk][itype]); } if (ikey == KEY_NAME && (ichunk == CHUNK_REGN)) { int ibucket; for (ibucket=0; ibucket<regn_hash->nbuckets; ibucket++) { HashItem *hi; for (hi = regn_hash->bucket[ibucket]; hi; hi = hi->next) { regn_t *regn = (regn_t *)hi->data.p; printf(" %s x%d\n", hi->key, regn->count); } } } } } } } } /* base counts */ if( level_mode & LEVEL_BASE ) { uint64_t total = 0; int i; for (i=0; i<5; i++) { if( base_count[i] ){ printf("Bases: %c: %"PRId64"\n", bases[i], base_count[i]); total += base_count[i]; } } printf("Bases: TOTAL: %"PRId64"\n", total); } } } return 0; }
int transfer_SAM_to_position_table(char * sam_file) { char linebuf[max(2*MAX_READ_LENGTH+300,3000)]; int allreads=0,mapped=0; char mate_chro[MAX_CHROMOSOME_NAME_LEN+1]; unsigned int mate_pos; int flags_mate; char cigar_mate[EXON_MAX_CIGAR_LEN+1]; gene_input_t input_file; HashTable * local_reassembly_pileup_files; HashTable * chromosome_size_table; chromosome_size_table = HashTableCreate(100); HashTableSetDeallocationFunctions(chromosome_size_table, NULL, NULL); HashTableSetKeyComparisonFunction(chromosome_size_table, my_strcmp); HashTableSetHashFunction(chromosome_size_table, HashTableStringHashFunction); local_reassembly_pileup_files = HashTableCreate(100); HashTableSetDeallocationFunctions(local_reassembly_pileup_files, NULL, NULL); HashTableSetKeyComparisonFunction(local_reassembly_pileup_files, my_strcmp); HashTableSetHashFunction(local_reassembly_pileup_files ,HashTableStringHashFunction); geinput_open_sam(sam_file, &input_file,0); while(1) { unsigned int read_pos =0xffffffff; char read_name[MAX_READ_NAME_LEN+1]; int flags; char chro_name[MAX_CHROMOSOME_NAME_LEN+1]; unsigned int pos, pair_dist; char cigar[EXON_MAX_CIGAR_LEN+1]; char read_text[MAX_READ_LENGTH+1]; char qual_text[MAX_READ_LENGTH+1]; int read_len, is_repeated, mapping_quality, is_anchor_certain=1; int pos_delta = 0; int is_paired_end_reads = 0; unsigned long long int file_offset = ftello(input_file.input_fp); if(feof(input_file.input_fp))break; read_text[0]=0; qual_text[0]=0; geinput_readline(&input_file, linebuf,0); int res = parse_SAM_line(linebuf, read_name,& flags, chro_name, & pos, cigar, & mapping_quality, & pair_dist, read_text , qual_text, & read_len, & is_repeated); int cigar_cursor = 0; int firstM = 1,xx=0; is_paired_end_reads = flags &1; if(res==0) { for(; cigar[cigar_cursor]; cigar_cursor++) { char nch = cigar[cigar_cursor]; if(nch>='0'&&nch<='9') { xx=xx*10+(nch-'0'); }else { if(nch=='M') firstM=0; else if(nch=='S') { if(firstM) pos_delta = xx; } xx=0; } } pos -= pos_delta; } if(res == 1) {chro_name[0]='*'; chro_name[1]=0;} //printf("MAPPED=%d\n", res); if(res == 0) // mapped { read_pos = pos - 1; mapped++; } else if(res == 1 && is_paired_end_reads) // unmapped { is_anchor_certain=0; if(mate_chro[0]) { if(mate_chro[0]!='*') { read_pos = mate_pos ; strcpy(chro_name, mate_chro); } //printf("RECOVERED 1: %u - %s ; LEN=%d ; YOU_ARE_FIRST=%d\n%s\n%s\n", read_anchor_position, read_name, read_len, flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR, read_text, qual_text); } else { char read_text_null[MAX_READ_LENGTH+1]; char qual_text_null[MAX_READ_LENGTH+1]; geinput_readline_back(&input_file, linebuf); res = parse_SAM_line(linebuf, read_name,& flags_mate, mate_chro, & mate_pos, cigar_mate, & mapping_quality, & pair_dist, read_text_null , qual_text_null, & read_len, & is_repeated); if(res==0) { read_pos = mate_pos - 1; strcpy(chro_name, mate_chro); } //printf("RECOVERED 2: %u - %s ; LEN=%d ; YOU_ARE_FIRST=%d\n%s\n%s\n", read_anchor_position, read_name, read_len, flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR, read_text, qual_text); } } if(read_pos<0xffff0000) { unsigned int read_span = calculate_read_span(cigar); write_read_pos(chro_name, read_pos, read_len, flags, file_offset, cigar, read_span, local_reassembly_pileup_files); unsigned int old_max_pos = HashTableGet(chromosome_size_table, chro_name) - NULL; if(old_max_pos==0) { char * chro_name_new = malloc(strlen(chro_name)+1); strcpy(chro_name_new , chro_name); HashTablePut(chromosome_size_table, chro_name_new, NULL+read_pos + read_span+1); } else if(read_pos + read_span +1 > old_max_pos ) HashTablePutReplace(chromosome_size_table, chro_name, NULL+read_pos + read_span+1, 0); } if(allreads %2==1) mate_chro[0] = 0; else { strcpy(mate_chro, chro_name); mate_pos = pos - 1; flags_mate = flags; } allreads++; } SUBREADprintf("Processed %d reads; %d mapped.\n", allreads, mapped); destroy_pileup_table(local_reassembly_pileup_files); finalise_sam_index(chromosome_size_table, sam_file); HashTableDestroy(chromosome_size_table); return 0; }
void WordFormInit() { WordFormHt = HashTableCreate(1009L); /* todo: Increase size? */ WordFormTrained = 0; }
int main(int argc, char ** argv) { char * junc_table_file; HashTable * junc_table = HashTableCreate(337); HashTable * junc_table_l = HashTableCreate(337); HashTable * junc_table_r = HashTableCreate(337); HashTable * bin_table = HashTableCreate(9337); if(argc<2) { printf("Usage cat my.SAM | filterJunc junc.table | featureCounts -i STDIN -a myAnnot.txt \n"); return -1; } junc_table_file = argv[1]; if(load_junc_table(junc_table_file, junc_table, junc_table_l, junc_table_r, bin_table)) { printf("Junction table not found!\n"); return -1; } char * linebuf=malloc(5001); char * linebuf2=malloc(5001); while(1) { int support_found = 0, ii, jj, alternative_found = 0; char * new_line = fgets(linebuf, 5000, stdin); if(!new_line) break; if(new_line[0]=='@') { fputs(new_line, stdout); continue; } char * new_line2 = fgets(linebuf2, 5000, stdin); for(ii=0;ii<2;ii++) { int flag=0; char chro[20]; unsigned int pos=0; char cigar[50]; unsigned int start_points[6]; unsigned short section_lengths[6]; parse_line(ii?new_line2:new_line, &flag, chro, &pos, cigar); int sections = RSubread_parse_CIGAR_string(cigar, start_points, section_lengths); for(jj=0; jj<sections-1; jj++) { unsigned int edge1 = start_points[jj] + pos + section_lengths[jj]; unsigned int edge2 = start_points[jj+1] + pos - 1; unsigned long long int junc_table_key = (edge1*1LLU) <<32 | edge2; char * junc_chro=HashTableGet(junc_table, (void *)junc_table_key); if(junc_chro && strcmp(junc_chro, chro)==0) { support_found = 1; } else { char * junc_chro_l=HashTableGet(junc_table_l, NULL+edge1); char * junc_chro_2=HashTableGet(junc_table_r, NULL+edge2); if( (junc_chro_l && strcmp(junc_chro_l, chro)==0) || (junc_chro_2 && strcmp(junc_chro_2, chro)==0)) alternative_found = 1; } } //if(support_found) break; if(!support_found && !alternative_found) for(jj=0; jj<sections; jj++) { unsigned int edge2 = start_points[jj] + pos + section_lengths[jj]; unsigned int edge1 = start_points[jj] + pos; unsigned int real_edge1 = HashTableGet(bin_table, NULL+edge1/50)-NULL; unsigned int real_edge2 = HashTableGet(bin_table, NULL+edge2/50)-NULL; if(real_edge1) { long long int diff = real_edge1; diff -= edge1; if(abs(diff)<section_lengths[jj]) alternative_found=1; // this section should contain the read_edge, but it does not! (it was a section as a whole) } if(real_edge2) { long long int diff = real_edge2; diff -= edge1; if(abs(diff)<section_lengths[jj]) alternative_found=1; // this section should contain the read_edge, but it does not! (it was a section as a whole) } } } if(alternative_found) //if(support_found) { fputs( new_line, stdout); fputs( new_line2, stdout); } //printf("READ: (%d) %s,%u %s\n\n", flag2, chro2, pos2, cigar2); } free(linebuf); free(linebuf2); }
return_val Init( void ) { return_val error; const char * const *list; const char *name; hash_entry_data key_entry; error = RC_OKAY; OutputDest = STDOUT_FILENO; ChangePrintDest( OutputDest ); relocSections.first = NULL; relocSections.last = NULL; if( !MsgInit() ) { // MsgInit does its own error message printing return( RC_ERROR ); } MemOpen(); error = HandleArgs(); if( error != RC_OKAY ) { return( error ); } openFiles(); initGlobals(); error = initHashTables(); if( error != RC_OKAY ) { PrintErrorMsg( error, WHERE_INIT_HASH_TABLES ); return( error ); } error = initServicesUsed(); if( error != RC_OKAY ) { // initServicesUsed does its own error message printing return( error ); } error = initSectionTables(); if( error != RC_OKAY ) { PrintErrorMsg( error, WHERE_CREATE_SEC_TABLES ); return( error ); } if( Options & PRINT_PUBLICS ) { CreatePublicsArray(); } if( IsMasmOutput() ) { CommentString = MASM_COMMENT_STRING; } if( IsIntelx86() ) { SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING_IGNORECASE ); if( SkipRefTable != NULL ) { for( list = intelSkipRefList; (name = *list) != NULL; ++list ) { key_entry.key.u.string = name; key_entry.data.u.string = *list; error = HashTableInsert( SkipRefTable, &key_entry ); if( error != RC_OKAY ) { break; } } } } if( LabelChar == 0 ) { if( IsMasmOutput() ) { LabelChar = 'L'; } else { LabelChar = 'X'; } } return( error ); }
void Init( void ) { char cmd_line[ CMD_LINE_LEN ]; return_val error; char **list; OutputDest = STDOUT_FILENO; ChangePrintDest( OutputDest ); relocSections.first = NULL; relocSections.last = NULL; if( !MsgInit() ) { // MsgInit does its own error message printing exit( -1 ); } MemOpen(); getcmd( cmd_line ); HandleArgs( cmd_line ); openFiles(); initGlobals(); error = initHashTables(); if( error == OKAY ) { error = initServicesUsed(); if( error == OKAY ) { error = initSectionTables(); if( error != OKAY ) { // free hash tables and services MemClose(); LeaveProgram( error, WHERE_CREATE_SEC_TABLES ); } } else { // free hash tables CloseFiles(); FreeHashTables(); // initServicesUsed does its own error message printing exit( error ); } } else { CloseFiles(); MemClose(); LeaveProgram( error, WHERE_INIT_HASH_TABLES ); } if( Options & PRINT_PUBLICS ) { CreatePublicsArray(); } if( IsMasmOutput() ) { CommentString = MASM_COMMENT_STRING; } if( IsIntelx86() ) { SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING, (hash_table_comparison_func) stricmp ); if( SkipRefTable ) { list = intelSkipRefList; while( *list ) { error = HashTableInsert( SkipRefTable, (hash_value) *list, (hash_data) *list ); if( error != OKAY ) break; list++; } } } if( !LabelChar ) { if( IsMasmOutput() ) { LabelChar = 'L'; } else { LabelChar = 'X'; } } }
NTSTATUS GnttabInitialize( IN PXENBUS_FDO Fdo, OUT PXENBUS_GNTTAB_CONTEXT *Context ) { NTSTATUS status; Trace("====>\n"); *Context = __GnttabAllocate(sizeof (XENBUS_GNTTAB_CONTEXT)); status = STATUS_NO_MEMORY; if (*Context == NULL) goto fail1; status = RangeSetGetInterface(FdoGetRangeSetContext(Fdo), XENBUS_RANGE_SET_INTERFACE_VERSION_MAX, (PINTERFACE)&(*Context)->RangeSetInterface, sizeof ((*Context)->RangeSetInterface)); ASSERT(NT_SUCCESS(status)); ASSERT((*Context)->RangeSetInterface.Interface.Context != NULL); status = CacheGetInterface(FdoGetCacheContext(Fdo), XENBUS_CACHE_INTERFACE_VERSION_MAX, (PINTERFACE)&(*Context)->CacheInterface, sizeof ((*Context)->CacheInterface)); ASSERT(NT_SUCCESS(status)); ASSERT((*Context)->CacheInterface.Interface.Context != NULL); status = SuspendGetInterface(FdoGetSuspendContext(Fdo), XENBUS_SUSPEND_INTERFACE_VERSION_MAX, (PINTERFACE)&(*Context)->SuspendInterface, sizeof ((*Context)->SuspendInterface)); ASSERT(NT_SUCCESS(status)); ASSERT((*Context)->SuspendInterface.Interface.Context != NULL); status = DebugGetInterface(FdoGetDebugContext(Fdo), XENBUS_DEBUG_INTERFACE_VERSION_MAX, (PINTERFACE)&(*Context)->DebugInterface, sizeof ((*Context)->DebugInterface)); ASSERT(NT_SUCCESS(status)); ASSERT((*Context)->DebugInterface.Interface.Context != NULL); InitializeListHead(&(*Context)->List); KeInitializeSpinLock(&(*Context)->Lock); status = HashTableCreate(&(*Context)->MapTable); if (!NT_SUCCESS(status)) goto fail2; (*Context)->Fdo = Fdo; Trace("<====\n"); return STATUS_SUCCESS; fail2: Error("fail2\n"); fail1: Error("fail1 (%08x)\n", status); return status; }
/*********************************************************************************** Function Name : InitContext Inputs : gc, psShareContext, psMode Outputs : - Returns : Success Description : Initialises a context - may setup shared name tables from a sharecontext. Also sets up default framebuffer ************************************************************************************/ static IMG_BOOL InitContext(GLES2Context *gc, GLES2Context *psShareContext, EGLcontextMode *psMode) { #if defined(GLES2_EXTENSION_VERTEX_ARRAY_OBJECT) GLES2NameType aeNameType[GLES2_MAX_UNSHAREABLE_NAMETYPE] = { GLES2_NAMETYPE_VERARROBJ }; #endif /* defined(GLES2_EXTENSION_VERTEX_ARRAY_OBJECT) */ IMG_UINT32 i, j; GLES_ASSERT(gc); GetApplicationHints(&gc->sAppHints, psMode); #if defined(FIX_HW_BRN_26922) if(!AllocateBRN26922Mem(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: AllocateBRN26922Mem failed")); goto FAILED_AllocateBRN26922Mem; } #endif /* defined(FIX_HW_BRN_26922) */ if(!CreateSharedState(gc, psShareContext)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateSharedState failed")); goto FAILED_CreateSharedState; } #if defined(GLES2_EXTENSION_VERTEX_ARRAY_OBJECT) /* Initialize the unshareable names arrays */ for (i = 0; i < GLES2_MAX_UNSHAREABLE_NAMETYPE; i++) { gc->apsNamesArray[i] = CreateNamesArray(gc, aeNameType[i], (PVRSRV_MUTEX_HANDLE)0); if(!gc->apsNamesArray[i]) { PVR_DPF((PVR_DBG_ERROR,"InitContext: Couldn't create unshareable names array %d", i)); DestroyNamesArray(gc, gc->apsNamesArray[i]); return IMG_FALSE; } } #endif /* defined(GLES2_EXTENSION_VERTEX_ARRAY_OBJECT) */ if(GLES2ALLOCDEVICEMEM(gc->ps3DDevData, gc->psSysContext->hSyncInfoHeap, PVRSRV_MEM_WRITE | PVRSRV_MEM_READ | PVRSRV_MEM_NO_SYNCOBJ | PVRSRV_MEM_CACHE_CONSISTENT, 4, 0, &gc->sKRMTAStatusUpdate.psMemInfo) != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "InitContext: Failed to create TA sync object")); goto FAILED_TASync; } gc->sKRMTAStatusUpdate.ui32StatusValue = 1; PVRSRVMemSet(gc->sKRMTAStatusUpdate.psMemInfo->pvLinAddr, 0, 4); if(!HashTableCreate(gc, &gc->sProgram.sPDSFragmentVariantHashTable, STATEHASH_LOG2TABLESIZE, STATEHASH_MAXNUMENTRIES, DestroyHashedPDSVariant)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: HashTableCreate failed")); goto FAILED_CreateHashTable; } if(!CreateTextureState(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateTextureState failed")); goto FAILED_CreateTextureState; } if(!CreateProgramState(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateProgramState failed")); goto FAILED_CreateProgramState; } if(!CreateBufObjState(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateBufObjState failed")); goto FAILED_CreateBufObjState; } if(!CreateFrameBufferState(gc, psMode)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateRenderBufferState failed")); goto FAILED_CreateFrameBufferState; } if(!CreateVertexArrayObjectState(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: CreateVertexArrayObjectState failed")); goto FAILED_CreateVertexArrayObjectState; } /* Initialise the TA kick VAO manager */ if(!KRM_Initialize(&gc->sVAOKRM, KRM_TYPE_TA, IMG_FALSE, 0, /* PVRSRV_MUTEX_HANDLE */ gc->ps3DDevData, gc->psSysContext->sHWInfo.sMiscInfo.hOSGlobalEvent, ReclaimVAOMemKRM, IMG_TRUE, DestroyVAOGhostKRM)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: Couldn't initialise the TA kick VAO manager")); goto FAILED_CreateVertexArrayObjectState; } if(!InitSpecialUSECodeBlocks(gc)) { PVR_DPF((PVR_DBG_ERROR,"InitContext: InitSpecialUSECodeBlocks failed")); goto FAILED_InitSpecialUSECodeBlocks; } gc->sState.sRaster.ui32ColorMask = GLES2_COLORMASK_ALL; gc->sState.sRaster.sClearColor.fRed = GLES2_Zero; gc->sState.sRaster.sClearColor.fGreen = GLES2_Zero; gc->sState.sRaster.sClearColor.fBlue = GLES2_Zero; gc->sState.sRaster.sClearColor.fAlpha = GLES2_Zero; gc->sState.sRaster.ui32BlendFactor = ((GLES2_BLENDFACTOR_ONE << GLES2_BLENDFACTOR_RGBSRC_SHIFT) | (GLES2_BLENDFACTOR_ONE << GLES2_BLENDFACTOR_ALPHASRC_SHIFT) | (GLES2_BLENDFACTOR_ZERO << GLES2_BLENDFACTOR_RGBDST_SHIFT) | (GLES2_BLENDFACTOR_ZERO << GLES2_BLENDFACTOR_ALPHADST_SHIFT)); gc->sState.sRaster.ui32BlendEquation = (GLES2_BLENDFUNC_ADD << GLES2_BLENDFUNC_RGB_SHIFT) | (GLES2_BLENDFUNC_ADD << GLES2_BLENDFUNC_ALPHA_SHIFT); gc->sState.sRaster.sBlendColor.fRed = GLES2_Zero; gc->sState.sRaster.sBlendColor.fGreen = GLES2_Zero; gc->sState.sRaster.sBlendColor.fBlue = GLES2_Zero; gc->sState.sRaster.sBlendColor.fAlpha = GLES2_Zero; gc->sState.sLine.fWidth = GLES2_One; gc->sState.sPolygon.eCullMode = GL_BACK; gc->sState.sPolygon.eFrontFaceDirection = GL_CCW; gc->sState.sPolygon.factor.fVal = GLES2_Zero; gc->sState.sPolygon.fUnits = GLES2_Zero; gc->sState.sStencil.ui32FFStencil = EURASIA_ISPC_SCMP_ALWAYS | EURASIA_ISPC_SOP1_KEEP | EURASIA_ISPC_SOP2_KEEP | EURASIA_ISPC_SOP3_KEEP | (GLES2_MAX_STENCIL_VALUE << EURASIA_ISPC_SCMPMASK_SHIFT) | (GLES2_MAX_STENCIL_VALUE << EURASIA_ISPC_SWMASK_SHIFT); gc->sState.sStencil.ui32BFStencil = EURASIA_ISPC_SCMP_ALWAYS | EURASIA_ISPC_SOP1_KEEP | EURASIA_ISPC_SOP2_KEEP | EURASIA_ISPC_SOP3_KEEP | (GLES2_MAX_STENCIL_VALUE << EURASIA_ISPC_SCMPMASK_SHIFT) | (GLES2_MAX_STENCIL_VALUE << EURASIA_ISPC_SWMASK_SHIFT); gc->sState.sStencil.ui32FFStencilRef = (0 << EURASIA_ISPA_SREF_SHIFT); gc->sState.sStencil.ui32BFStencilRef = (0 << EURASIA_ISPA_SREF_SHIFT); gc->sState.sStencil.ui32Clear = 0; gc->sState.sStencil.ui32FFStencilCompareMaskIn = GLES2_MAX_STENCIL_VALUE; gc->sState.sStencil.ui32BFStencilCompareMaskIn = GLES2_MAX_STENCIL_VALUE; gc->sState.sStencil.ui32FFStencilWriteMaskIn = GLES2_MAX_STENCIL_VALUE; gc->sState.sStencil.ui32BFStencilWriteMaskIn = GLES2_MAX_STENCIL_VALUE; gc->sState.sStencil.i32FFStencilRefIn = 0; gc->sState.sStencil.i32BFStencilRefIn = 0; gc->sState.sStencil.ui32MaxFBOStencilVal = GLES2_MAX_STENCIL_VALUE; gc->sState.sMultisample.bSampleCoverageInvert = IMG_FALSE; gc->sState.sMultisample.fSampleCoverageValue = GLES2_One; gc->sState.sDepth.ui32TestFunc = EURASIA_ISPA_DCMPMODE_LT; gc->sState.sDepth.fClear = GLES2_One; gc->ui32Enables = GLES2_DITHER_ENABLE; gc->sState.sClientPixel.ui32UnpackAlignment = 4; gc->sState.sClientPixel.ui32PackAlignment = 4; gc->ui32DirtyState = GLES2_DIRTYFLAG_ALL; gc->ui32EmitMask = GLES2_EMITSTATE_ALL; /* * Set up attrib array default values */ for (i=0; i < GLES2_MAX_VERTEX_ATTRIBS; ++i) { GLES2AttribArrayPointerState *psAPState = &(gc->sVAOMachine.sDefaultVAO.asVAOState[AP_VERTEX_ATTRIB0 + i]); psAPState->ui32StreamTypeSize = GLES2_STREAMTYPE_FLOAT | (4 << GLES2_STREAMSIZE_SHIFT); gc->sVAOMachine.asAttribPointer[AP_VERTEX_ATTRIB0 + i].psState = psAPState; gc->sVAOMachine.asAttribPointer[AP_VERTEX_ATTRIB0 + i].ui32Size = 16; gc->sVAOMachine.asAttribPointer[AP_VERTEX_ATTRIB0 + i].ui32Stride = 16; gc->sVAOMachine.asCurrentAttrib[AP_VERTEX_ATTRIB0 + i].fX = GLES2_Zero; gc->sVAOMachine.asCurrentAttrib[AP_VERTEX_ATTRIB0 + i].fY = GLES2_Zero; gc->sVAOMachine.asCurrentAttrib[AP_VERTEX_ATTRIB0 + i].fZ = GLES2_Zero; gc->sVAOMachine.asCurrentAttrib[AP_VERTEX_ATTRIB0 + i].fW = GLES2_One; } for(i=0; i < GLES2_HINT_NUMHINTS; i++) { gc->sState.sHints.eHint[i] = GL_DONT_CARE; } j = 0; for(i=0; i < CBUF_NUM_TA_BUFFERS; i++) { IMG_UINT32 ui32Size; IMG_HANDLE hMemHeap; switch(i) { case CBUF_TYPE_PDS_VERT_BUFFER: { hMemHeap = gc->psSysContext->hPDSVertexHeap; ui32Size = gc->sAppHints.ui32DefaultPDSVertBufferSize; break; } case CBUF_TYPE_VERTEX_DATA_BUFFER: { hMemHeap = gc->psSysContext->hGeneralHeap; ui32Size = gc->sAppHints.ui32DefaultVertexBufferSize; break; } case CBUF_TYPE_INDEX_DATA_BUFFER: { hMemHeap = gc->psSysContext->hGeneralHeap; ui32Size = gc->sAppHints.ui32DefaultIndexBufferSize; break; } case CBUF_TYPE_VDM_CTRL_BUFFER: { hMemHeap = gc->psSysContext->hGeneralHeap; ui32Size = gc->sAppHints.ui32DefaultVDMBufferSize; break; } case CBUF_TYPE_PDS_VERT_SECONDARY_PREGEN_BUFFER: { PVR_DPF((PVR_DBG_MESSAGE,"InitContext: ignoring buffer type CBUF_TYPE_PDS_VERT_SECONDARY_PREGEN_BUFFER")); hMemHeap = gc->psSysContext->hPDSVertexHeap; ui32Size = 4; break; } case CBUF_TYPE_MTE_COPY_PREGEN_BUFFER: { hMemHeap = gc->psSysContext->hPDSVertexHeap; if(gc->sAppHints.bEnableStaticMTECopy) { ui32Size = ((gc->sAppHints.ui32DefaultPregenMTECopyBufferSize / GLES2_ALIGNED_MTE_COPY_PROG_SIZE) * GLES2_ALIGNED_MTE_COPY_PROG_SIZE); } else { PVR_DPF((PVR_DBG_WARNING,"InitContext: ignoring buffer type CBUF_TYPE_MTE_COPY_PREGEN_BUFFER")); ui32Size = 4; } break; } case CBUF_TYPE_PDS_AUXILIARY_PREGEN_BUFFER: { /* Unused */ gc->apsBuffers[i] = IMG_NULL; continue; } default: { PVR_DPF((PVR_DBG_ERROR,"InitContext: Invalid buffer type")); goto FAILED_CBUF_CreateBuffer; } } gc->apsBuffers[i] = CBUF_CreateBuffer(gc->ps3DDevData, i, hMemHeap, gc->psSysContext->hSyncInfoHeap, gc->psSysContext->sHWInfo.sMiscInfo.hOSGlobalEvent, ui32Size); if(!gc->apsBuffers[i]) { PVR_DPF((PVR_DBG_ERROR,"InitContext: Failed to create buffer %u",i)); goto FAILED_CBUF_CreateBuffer; } /* Point the TA Kick status update to the device memory reserved for status updates in the buffer */ gc->sKickTA.asTAStatusUpdate[j].hKernelMemInfo = gc->apsBuffers[i]->psStatusUpdateMemInfo->hKernelMemInfo; gc->sKickTA.asTAStatusUpdate[j].sCtlStatus.sStatusDevAddr.uiAddr = gc->apsBuffers[i]->psStatusUpdateMemInfo->sDevVAddr.uiAddr; /* set the read offset pointer in the buffer */ gc->apsBuffers[i]->pui32ReadOffset = (IMG_UINT32*)gc->apsBuffers[i]->psStatusUpdateMemInfo->pvLinAddr; j++; if(i == CBUF_TYPE_MTE_COPY_PREGEN_BUFFER) { if(gc->sAppHints.bEnableStaticMTECopy) { if(SetupMTEPregenBuffer(gc) != GLES2_NO_ERROR) { PVR_DPF((PVR_DBG_ERROR,"InitContext: Failed to fill pregen buffer %u",i)); goto FAILED_CBUF_CreateBuffer; } } } } gc->sKickTA.sKickTACommon.ui32NumTAStatusVals = j; /* Setup 3D status val sync */ gc->sKickTA.sKickTACommon.ui32Num3DStatusVals = 2; if(BuildExtensionString(gc) != IMG_TRUE) { goto FAILED_BuildExtensionString; } #if defined(SGX_FEATURE_SW_VDM_CONTEXT_SWITCH) gc->sSmallKickTA.ui32NumIndicesThisTA = 0; gc->sSmallKickTA.ui32NumPrimitivesThisTA = 0; gc->sSmallKickTA.ui32NumIndicesThisFrame = 0; gc->sSmallKickTA.ui32NumPrimitivesThisFrame = 0; /* Default value to ensure no TA splitting on the first frame */ gc->sSmallKickTA.ui32KickThreshold = 0xFFFFFFFF; #endif #if defined(DEBUG) if(gc->sAppHints.bDumpShaderAnalysis) { gc->pShaderAnalysisHandle = OpenShaderAnalysisFile(); } #endif /* defined(DEBUG) */ PDUMP_STRING_CONTINUOUS((gc, "PDump from OpenGL ES 2.0 driver, version %s. HW variant %s, %d\n",PVRVERSION_STRING, pszRenderer, SGX_CORE_REV)); return IMG_TRUE; /* Clean up any memory */ FAILED_BuildExtensionString: FAILED_CBUF_CreateBuffer: for(i=0; i < CBUF_NUM_TA_BUFFERS; i++) { if(gc->apsBuffers[i]) { CBUF_DestroyBuffer(gc->ps3DDevData, gc->apsBuffers[i]); } } FAILED_InitSpecialUSECodeBlocks: FreeVertexArrayObjectState(gc); FAILED_CreateVertexArrayObjectState: FreeFrameBufferState(gc); FAILED_CreateFrameBufferState: FreeBufObjState(gc); FAILED_CreateBufObjState: FreeProgramState(gc); FAILED_CreateProgramState: FreeTextureState(gc); FAILED_CreateTextureState: HashTableDestroy(gc, &gc->sProgram.sPDSFragmentVariantHashTable); FAILED_CreateHashTable: GLES2FREEDEVICEMEM(gc->ps3DDevData, gc->sKRMTAStatusUpdate.psMemInfo); FAILED_TASync: FreeContextSharedState(gc); FAILED_CreateSharedState: #if defined(FIX_HW_BRN_26922) FreeBRN26922Mem(gc); FAILED_AllocateBRN26922Mem: #endif /* defined(FIX_HW_BRN_26922) */ return IMG_FALSE; }
int transfer_SAM_to_assembly(global_context_t * global_context) { char linebuf[max(2*MAX_READ_LENGTH+300,3000)]; int allreads=0,mapped=0; char mate_chro[MAX_CHROMOSOME_NAME_LEN+1]; unsigned int mate_pos; int flags_mate; char cigar_mate[EXON_MAX_CIGAR_LEN+1]; int is_warning_shown = 0; HashTable * local_reassembly_pileup_files; print_in_box(80,0,0,"Transforming the sam file into: %s", global_context->config.temp_file_prefix); local_reassembly_pileup_files = HashTableCreate(100); HashTableSetDeallocationFunctions(local_reassembly_pileup_files, NULL, NULL); HashTableSetKeyComparisonFunction(local_reassembly_pileup_files, my_strcmp); HashTableSetHashFunction(local_reassembly_pileup_files ,HashTableStringHashFunction); while(1) { unsigned int read_anchor_position =0xffffffff; char read_name[MAX_READ_NAME_LEN+1]; int flags; char chro_name[MAX_CHROMOSOME_NAME_LEN+1]; unsigned int pos, pair_dist; char cigar[EXON_MAX_CIGAR_LEN+1]; char read_text[MAX_READ_LENGTH+1]; char qual_text[MAX_READ_LENGTH+1]; int read_len, is_repeated, mapping_quality, is_anchor_certain=1; int pos_delta = 0; if(feof(global_context -> input_reads.first_read_file.input_fp))break; read_text[0]=0; qual_text[0]=0; geinput_readline(&global_context -> input_reads.first_read_file, linebuf,0); int res = parse_SAM_line(linebuf, read_name,& flags, chro_name, & pos, cigar, & mapping_quality, & pair_dist, read_text , qual_text, & read_len, & is_repeated); int cigar_cursor = 0; int firstM = 1,xx=0; if(res == 0&& (flags &1) && (!global_context -> input_reads.is_paired_end_reads)) { if(!is_warning_shown) { SUBREADprintf("Warning: the input seems to be paired end. You may like to specify '-p' option.\n"); is_warning_shown=1; } } if(res==0) { for(; cigar[cigar_cursor]; cigar_cursor++) { char nch = cigar[cigar_cursor]; if(nch>='0'&&nch<='9') { xx=xx*10+(nch-'0'); }else { if(nch=='M') firstM=0; else if(nch=='S') { if(firstM) pos_delta = xx; } xx=0; } } pos -= pos_delta; } if(res == 1) {chro_name[0]='*'; chro_name[1]=0;} //printf("RES=%d\tMAPPED=%s,%u\n", res, chro_name, pos); if(res == 0) // mapped { read_anchor_position = linear_gene_position(&global_context->chromosome_table , chro_name, pos) - 1; //printf("MAPPED_LINEAR=%u\n", read_anchor_position); mapped++; } else if(res == 1 && global_context -> input_reads.is_paired_end_reads) // unmapped { is_anchor_certain=0; if(mate_chro[0]) { if(mate_chro[0]!='*') { unsigned int mate_linear_pos = linear_gene_position(&global_context->chromosome_table , mate_chro, mate_pos) - 1; read_anchor_position = mate_linear_pos + global_context -> config.expected_pair_distance * ((((flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR) && (flags_mate & SAM_FLAG_REVERSE_STRAND_MATCHED))|| ((flags_mate & SAM_FLAG_SECOND_READ_IN_PAIR)&& (flags_mate & SAM_FLAG_REVERSE_STRAND_MATCHED))) ?-1:1); } //printf("RECOVERED 1: %u - %s ; LEN=%d ; YOU_ARE_FIRST=%d\n%s\n%s\n", read_anchor_position, read_name, read_len, flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR, read_text, qual_text); } else { char read_text_null[MAX_READ_LENGTH+1]; char qual_text_null[MAX_READ_LENGTH+1]; int X_read_len=0; geinput_readline_back(&global_context -> input_reads.first_read_file, linebuf); res = parse_SAM_line(linebuf, read_name,& flags_mate, mate_chro, & mate_pos, cigar_mate, & mapping_quality, & pair_dist, read_text_null , qual_text_null, & X_read_len, & is_repeated); if(res==0) { unsigned int mate_linear_pos = linear_gene_position(&global_context->chromosome_table , mate_chro, mate_pos) - 1; read_anchor_position = mate_linear_pos + global_context -> config.expected_pair_distance * ((((flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR) && (flags_mate & SAM_FLAG_REVERSE_STRAND_MATCHED))|| ((flags_mate & SAM_FLAG_SECOND_READ_IN_PAIR)&& (flags_mate & SAM_FLAG_REVERSE_STRAND_MATCHED))) ?-1:1); } //printf("RECOVERED 2: %u - %s ; LEN=%d ; YOU_ARE_FIRST=%d\n%s\n%s\n", read_anchor_position, read_name, read_len, flags_mate & SAM_FLAG_FIRST_READ_IN_PAIR, read_text, qual_text); //read_anchor_position += (global_context -> config.expected_pair_distance/3) *((1.0*(read_anchor_position % 3751) - 3751/2) / 3751.); } if(read_anchor_position<0xffff0000) { if((flags_mate & SAM_FLAG_REVERSE_STRAND_MATCHED) == (flags & SAM_FLAG_REVERSE_STRAND_MATCHED)) { reverse_read(read_text, read_len, global_context->config.space_type); reverse_quality(qual_text, read_len); } } } //printf("R=%s; RL=%d; anchor=%u\n", read_name, read_len, read_anchor_position); if(read_anchor_position<0xffff0000 && read_len >=2) { //if(!is_anchor_certain)printf("Uncertain Anchor at %u = %s\n", read_anchor_position, read_name); //printf("INSERT LOCAL: %u\n", read_anchor_position); write_local_reassembly(global_context, local_reassembly_pileup_files, read_anchor_position, read_name , read_text , qual_text , read_len, is_anchor_certain); } if(allreads %2==1) mate_chro[0] = 0; else { strcpy(mate_chro, chro_name); mate_pos = pos ; flags_mate = flags; } allreads++; } print_in_box(80,0,0,"Processed %d reads; %d mapped.\n", allreads, mapped); destroy_pileup_table(local_reassembly_pileup_files); return 0; }
int handle_http_propfind(http_req * req, http_rsp * rsp) { int ret = OK; HashElement * e = NULL; int depth = -1; HashHandle props = NULL_HANDLE; CacheHandle cache = NULL_HANDLE; char * propxml = NULL; int contentlen = 0; char * vpath = req->uri; struct stat buf; WEBLOG_API(); #ifdef WEBCFG_SUPPORT_AUTH /* Authentication has a very high priority. */ if (OK != CheckAuthorization(req, rsp)) { return handle_http_error(401, req, rsp); } #endif if(OK != Webdav_CheckPath(req->uri)) { WEBLOG_ERROR("<%s> PROPFIND is not allowed for non-webdav path [%s].\n", __FUNCTION__, req->uri); handle_http_error(403, req, rsp); ret = NG; goto __error_out; } if(0 == strlen(vpath)) { strcat(vpath, "/"); WEBLOG_VERBOSE("<%s> redirect to root path. [%s].\n", __FUNCTION__, vpath); } WEBLOG_INFO("<%s> stat the file \"%s\".\n", __FUNCTION__, vpath); ret = stat(vpath, &buf); /* Check if statistics are valid: */ if(ret != 0) { WEBLOG_ERROR("<%s> fail to stat the file \"%s\".\n", __FUNCTION__, vpath); switch (errno) { case ENOENT: WEBLOG_ERROR("<%s> File %s not found.\n", __FUNCTION__, vpath); handle_http_error(404, req, rsp); ret = NG; goto __error_out; case EINVAL: /* no break */ default: /* Should never be reached. */ WEBLOG_ERROR("<%s> Unexpected error in _stat.\n", __FUNCTION__); handle_http_error(500, req, rsp); ret = NG; goto __error_out; } } props = HashTableCreate(64); ASSERT(props != NULL_HANDLE); /* get depth. */ e = HashLookup(req->headOptions, "Depth"); if(!e) depth = -1; else if(e->value.data.string[0] == '0') depth = 0; else if(e->value.data.string[0] == '1') depth = 1; else depth = -1; if(depth == -1 && TRUE == Webdav_isFolder(vpath)) { WEBLOG_ERROR("<%s> PROPFIND a collection with infinite depth is not allowed.\n", __FUNCTION__); handle_http_error(403, req, rsp); ret = NG; goto __error_out; } #ifdef WEBCFG_MINIMIZE_SERVER #else e = HashLookup(req->headOptions, "Content-Type"); if(e && strstr(e->value.data.string, "xml")) { char * xmlsockbuf = NULL; char strbuf[128] = {0}; char *end, *p, *q; HashValue eeee = HashString("", FALSE); // empty value! WEBLOG_INFO("<%s> Client request props in a xml body.\n", __FUNCTION__); e = HashLookup(req->headOptions, "Content-Length"); if(!e) { /* RFC2616, 14.23. */ WEBLOG_ERROR("<%s> Missing \"Content-Length\" for xml body.\n", __FUNCTION__); handle_http_error(400, req, rsp); ret = NG; goto __error_out; } contentlen = atoi(e->value.data.string); xmlsockbuf = (char *)webmalloc(contentlen+1); memset(xmlsockbuf, 0, contentlen+1); if(req->datalen > 0) // data left in head buffer. { memcpy(xmlsockbuf, req->sockbuf, req->datalen); WEBLOG_VERBOSE("<%s> previous buffered %d/%d bytes consumed.\n", __FUNCTION__, req->datalen, contentlen); } /* if there's more data in socket.... */ if (req->datalen < contentlen) { /* read rest of data from socket. */ p = xmlsockbuf + req->datalen; req->datalen = recv(req->sock, p, contentlen-req->datalen, 0); WEBLOG_VERBOSE("<%s> %d/%d bytes read from socket.\n", __FUNCTION__, req->datalen, contentlen); dumpText(xmlsockbuf, contentlen); } p = strstr(xmlsockbuf, "<prop>") + 6; end = strstr(xmlsockbuf, "</prop>"); if(strstr(xmlsockbuf, "<allprop/>")) { WEBLOG_INFO("<%s> client request all props.\n", __FUNCTION__); } else { ASSERT(p<end); *end = '\0'; /* good for str api. */ /* Possible Value: WinXP: <propname/> Cadaver: <propname xmlns="DAV:"/> */ do { p = strchr(p, '<'); if(!p) break; else p++; q = strstr(p, "/>"); ASSERT(q && (q-p < sizeof(strbuf))); strncpy(strbuf, p, q-p); p = strchr(strbuf, ' '); if(p) *p = '\0'; p = strtrim(strbuf); WEBLOG_INFO("<%s> client request prop: <%s>\n", __FUNCTION__, p); HashAdd(props, p, eeee); p = q + 2; } while(p<end); /* <xxx/>\r\n</prop> */ } } #endif cache = CacheCreate(); Webdav_Props(props, cache, vpath, depth); contentlen = CacheGetData(cache, &propxml); ASSERT(propxml); dumpText(propxml, contentlen); WEBLOG_INFO("<%s> response xml ready. len %d.\n", __FUNCTION__, contentlen); rsp->code = 207; rsp->body = propxml; http_add_rspoption(rsp, "Content-Type", "text/xml"); http_send_response(rsp); __error_out: if (props != NULL_HANDLE) HashTableDestroy(props); if (cache != NULL_HANDLE) CacheDestroy(cache); return ret; }
/* * Complements a scaffold; both complementing each contig within it and * reversing the order of contigs in the scaffold. * * Returns 0 on success * -1 on failure */ int complement_scaffold(GapIO *io, tg_rec srec) { scaffold_t *f; int i, j, nc = ArrayMax(io->contig_order); scaffold_member_t *contigs; tg_rec *crecs; HashTable *h; reg_order ro; reg_buffer_start rs; reg_buffer_end re; if (!(f = cache_search(io, GT_Scaffold, srec))) return -1; if (!(f = cache_rw(io, f))) return -1; cache_incr(io, f); /* Complement contigs */ contigs = ArrayBase(scaffold_member_t, f->contig); for (i = 0; i < ArrayMax(f->contig); i++) { complement_contig(io, contigs[i].rec); } /* Reverse the order of the contigs in the scaffold array */ for (i = 0, j = ArrayMax(f->contig)-1; i < j; i++, j--) { scaffold_member_t cr1 = contigs[i]; contigs[i] = contigs[j]; contigs[j] = cr1; } /* * Reverse the order of contigs in the contig_order array too. * This is the part that really matters. It's also hard as the contigs * in the contig order array could be in any order and not adjacent. * For our purposes we'll just ensure the contigs in this scaffold in * the contig order array match our freshly complemented scaffold * ordering. * * We initially build a hash table of contigs in this scaffold, and * then iterate through contig_order copying out the new contigs whenever * one matches. */ h = HashTableCreate(nc, 0); for (i = 0; i < ArrayMax(f->contig); i++) { HashData hd; hd.i = 0; HashTableAdd(h, (char *)&contigs[i].rec, sizeof(tg_rec), hd, NULL); } /* Replace any contig matching the scaffold with the new order */ crecs = ArrayBase(tg_rec, io->contig_order); for (i = j = 0; i < nc; i++) { HashItem *hi; if (!(hi = HashTableSearch(h, (char *)&crecs[i], sizeof(tg_rec)))) continue; crecs[i] = contigs[j++].rec; } /* Send event messages around */ rs.job = REG_BUFFER_START; for (i = 0; i < nc; i++) { HashItem *hi; if (!(hi = HashTableSearch(h, (char *)&crecs[i], sizeof(tg_rec)))) continue; contig_notify(io, crecs[i], (reg_data *)&rs); } ro.job = REG_ORDER; for (i = 0; i < nc; i++) { HashItem *hi; if (!(hi = HashTableSearch(h, (char *)&crecs[i], sizeof(tg_rec)))) continue; ro.pos = i+1; contig_notify(io, crecs[i], (reg_data *)&ro); } /* Notify the end of our updates */ re.job = REG_BUFFER_END; for (i = 0; i < nc; i++) { HashItem *hi; if (!(hi = HashTableSearch(h, (char *)&crecs[i], sizeof(tg_rec)))) continue; contig_notify(io, crecs[i], (reg_data *)&re); } HashTableDestroy(h, 0); cache_decr(io, f); return 0; }
void StringQuarksCreate(void) { quarks = HashTableCreate(HASH_STRING, NULL); }