PBWT *pbwtSubRange (PBWT *pOld, int start, int end) { int M = pOld->M ; PBWT *pNew = pbwtCreate (M) ; int i, j, k ; uchar *x ; PbwtCursor *uOld = pbwtCursorCreate (pOld, TRUE, TRUE) ; pNew->yz = arrayCreate (pNew->N*8, uchar) ; PbwtCursor *uNew = pbwtCursorCreate (pNew, TRUE, TRUE) ; if (!pOld || !pOld->yz) die ("subrange without an existing pbwt") ; if (start < 0 || end > pOld->N || end <= start) die ("subrange invalid start %d, end %d", start, end) ; x = myalloc (M, uchar) ; if (pOld->sites) pNew->sites = arrayCreate (4096, Site) ; for (i = 0 ; i < end ; ++i) { if (i >= start) { for (j = 0 ; j < M ; ++j) x[uOld->a[j]] = uOld->y[j] ; for (j = 0 ; j < M ; ++j) uNew->y[j] = x[uNew->a[j]] ; pbwtCursorWriteForwards (uNew) ; if (pOld->sites) array(pNew->sites, pNew->N, Site) = arr(pOld->sites, i, Site) ; ++pNew->N ; } pbwtCursorForwardsRead (uOld) ; } pNew->aFend = myalloc (pNew->M, int) ; memcpy (pNew->aFend, uNew->a, pNew->M*sizeof(int)) ; pbwtDestroy (pOld) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ; free(x) ; return pNew ; }
void *initMemcacheData() { struct memcacheProcData *data = wmalloc(sizeof(struct memcacheProcData)); if (!data) return NULL; memset(data, 0, sizeof(*data)); data->command = wstrNewLen(NULL, 8); data->key = wstrNewLen(NULL, 64); data->keys = arrayCreate(sizeof(wstr), 1); data->vals = arrayCreate(sizeof(struct slice), 2); data->stage = SW_START; data->type = UNKNOWN; return data; }
static void obtainPairCounts (GfrEntry *currGE) { GfrPairCount *currPC; GfrInterRead *currGIR,*nextGIR; int i,j; currGE->pairCounts = arrayCreate (100,GfrPairCount); arraySort (currGE->interReads,(ARRAYORDERF)sortGfrInterReads); i = 0; while (i < arrayMax (currGE->interReads)) { currGIR = arrp (currGE->interReads,i,GfrInterRead); currPC = arrayp (currGE->pairCounts,arrayMax (currGE->pairCounts),GfrPairCount); currPC->number1 = currGIR->number1; currPC->number2 = currGIR->number2; currPC->pairType = currGIR->pairType; currPC->count = 1; j = i + 1; while (j < arrayMax (currGE->interReads)) { nextGIR = arrp (currGE->interReads,j,GfrInterRead); if (currGIR->pairType == nextGIR->pairType && currGIR->number1==nextGIR->number1 && currGIR->number2==nextGIR->number2) { currPC->count++; } else { break; } j++; } i = j; } }
/** * Returns an Array of FASTQ sequences. * @param[in] truncateName If truncateName > 0, leading spaces of the name are skipped. Furthermore, the name is truncated after the first white space. If truncateName == 0, the name is stored as is. * @note The memory belongs to this routine. */ Array fastq_readAllSequences (int truncateName) { Array seqs; Fastq *currFQ; seqs = arrayCreate (100000,Fastq); while (currFQ = fastq_processNextSequence (0,truncateName)) { array (seqs,arrayMax (seqs),Fastq) = *currFQ; } return seqs; }
void checkPseudogeneOverlap( BlatQuery* blQ ) { PslEntry* blE; int i; Array intervals=arrayCreate(2, Interval); for( i=0; i<arrayMax(blQ->entries); i++) { blE = arrp( blQ->entries, i, PslEntry ); intervals = intervalFind_getOverlappingIntervals ( blE->tName, blE->tStart, blE->tEnd); if( arrayMax(intervals)>0) arrayRemoveD( blQ->entries, i ); } }
static void seqspecsInitClear (void) { int i; if (seqspecs != NULL) { i = arrayMax (seqspecs); while (i--) seqspec_destroy (arru (seqspecs,i,Seqspec)); arrayClear (seqspecs); } else seqspecs = arrayCreate (10,Seqspec); }
PBWT *pbwtSubSites (PBWT *pOld, double fmin, double frac) { int M = pOld->M ; PBWT *pNew = pbwtCreate (M) ; int i, j, k, thresh = M*(1-fmin) ; double bit = 0.0 ; uchar *x ; PbwtCursor *uOld = pbwtCursorCreate (pOld, TRUE, TRUE) ; pNew->yz = arrayCreate (pNew->N*8, uchar) ; PbwtCursor *uNew = pbwtCursorCreate (pNew, TRUE, TRUE) ; if (!pOld || !pOld->yz) die ("subsites without an existing pbwt") ; if (fmin < 0 || fmin >= 1 || frac <= 0 || frac > 1) die ("fmin %f, frac %f for subsites out of range\n", fmin, frac) ; x = myalloc (M, uchar) ; if (pOld->sites) pNew->sites = arrayCreate (4096, Site) ; for (i = 0 ; i < pOld->N ; ++i) { if ((uOld->c < thresh) && ((bit += frac) > 1.0)) { for (j = 0 ; j < M ; ++j) x[uOld->a[j]] = uOld->y[j] ; for (j = 0 ; j < M ; ++j) uNew->y[j] = x[uNew->a[j]] ; pbwtCursorWriteForwards (uNew) ; if (pOld->sites) array(pNew->sites, pNew->N, Site) = arr(pOld->sites, i, Site) ; ++pNew->N ; bit -= 1.0 ; } pbwtCursorForwardsRead (uOld) ; } fprintf (stderr, "subsites with fmin %f, frac %f leaves %d sites\n", fmin, frac, pNew->N) ; pNew->chrom = pOld->chrom ; pOld->chrom = 0 ; pNew->samples = pOld->samples ; pOld->samples = 0 ; pNew->aFend = myalloc (pNew->M, int) ; memcpy (pNew->aFend, uNew->a, pNew->M*sizeof(int)) ; pbwtDestroy (pOld) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ; free(x) ; return pNew ; }
int main (int argc, char *argv[]) { int i,j,groupNumber; MrfEntry *currEntry; GffEntry *currGffEntry,*nextGffEntry; Array gffEntries; FILE *fp; Stringa buffer; short int paired; if (argc != 2) { usage ("%s <prefix>",argv[0]); } buffer = stringCreate (1000); groupNumber = 0; mrf_init ("-"); gffEntries = arrayCreate (100000,GffEntry); while (currEntry = mrf_nextEntry ()) { processRead (gffEntries, currEntry, &groupNumber); } mrf_deInit (); arraySort (gffEntries,(ARRAYORDERF)sortGffEntriesByTargetNameAndGroupNumber); i = 0; while (i < arrayMax (gffEntries)) { currGffEntry = arrp (gffEntries,i,GffEntry); stringPrintf (buffer,"%s_%s.gff",argv[1],currGffEntry->targetName); fp = fopen (string (buffer),"w"); if (fp == NULL) { die ("Unable to open file: %s",string (buffer)); } fprintf (fp,"browser hide all\n"); fprintf (fp,"track name=\"%s_%s\" visibility=2\n",argv[1],currGffEntry->targetName); fprintf (fp,"%s\n",currGffEntry->line); j = i + 1; while (j < arrayMax (gffEntries)) { nextGffEntry = arrp (gffEntries,j,GffEntry); if (!strEqual (currGffEntry->targetName,nextGffEntry->targetName)) { break; } fprintf (fp,"%s\n",nextGffEntry->line); j++; } i = j; fclose (fp); } stringDestroy (buffer); return 0; }
struct conn *connGet(struct client *client) { if (client->pending) { ASSERT(client->pending->client); return client->pending; } struct conn *c = wmalloc(sizeof(*c)); c->client = client; c->protocol_data = client->protocol->initProtocolData(); c->app = c->app_private_data = NULL; appendToListTail(client->conns, c); c->ready_send = 0; c->send_queue = createList(); listSetFree(c->send_queue, (void(*)(void*))freeSendPacket); c->cleanup = arrayCreate(sizeof(struct callback), 2); return c; }
/** * Get the next BlastQuery. * @pre The module has been initialized using blastParser_init(). */ BlastQuery* blastParser_nextQuery (void) { char *line,*pos; static char *queryName = NULL; static char *prevBlastQueryName = NULL; static BlastQuery *currBlastQuery = NULL; int first; if (!ls_isEof (ls)) { blastParser_freeQuery (currBlastQuery); currBlastQuery = NULL; AllocVar (currBlastQuery); currBlastQuery->entries = arrayCreate (5,BlastEntry); first = 1; while (line = ls_nextLine (ls)) { if (line[0] == '\0') { continue; } pos = strchr (line,'\t'); *pos = '\0'; strReplace (&queryName,line); if (first == 1 || strEqual (prevBlastQueryName,queryName)) { blastParser_processLine (pos + 1,currBlastQuery); } else { ls_back (ls,1); return currBlastQuery; } if (first == 1) { currBlastQuery->qName = hlr_strdup (queryName); first = 0; } strReplace(&prevBlastQueryName,queryName); } if (first == 1) { return NULL; } else { return currBlastQuery; } } blastParser_freeQuery (currBlastQuery); currBlastQuery = NULL; return NULL; }
Selector* selectorCreate(void) { Selector* selector = calloc(1, sizeof(Selector)); if (selector == NULL) { LOG_ALWAYS_FATAL("malloc() error."); } selector->selectableFds = arrayCreate(); // Set up wake-up pipe. if (pipe(selector->wakeupPipe) < 0) { LOG_ALWAYS_FATAL("pipe() error: %s", strerror(errno)); } LOGD("Wakeup fd: %d", selector->wakeupPipe[0]); SelectableFd* wakeupFd = selectorAdd(selector, selector->wakeupPipe[0]); if (wakeupFd == NULL) { LOG_ALWAYS_FATAL("malloc() error."); } wakeupFd->onReadable = &eatWakeupData; pthread_mutex_init(&selector->inSelectLock, NULL); return selector; }
PBWT *pbwtSubRange (PBWT *pOld, int start, int end) { int M = pOld->M ; PBWT *pNew = pbwtCreate (M, 0) ; int i, j, k ; uchar *x ; PbwtCursor *uOld = pbwtCursorCreate (pOld, TRUE, TRUE) ; PbwtCursor *uNew = pbwtCursorCreate (pNew, TRUE, TRUE) ; if (!pOld || !pOld->yz) die ("subrange without an existing pbwt") ; if (start < 0 || end > pOld->N || end <= start) die ("subrange invalid start %d, end %d", start, end) ; x = myalloc (M, uchar) ; if (pOld->sites) pNew->sites = arrayCreate (4096, Site) ; for (i = 0 ; i < end ; ++i) { if (i >= start) { for (j = 0 ; j < M ; ++j) x[uOld->a[j]] = uOld->y[j] ; for (j = 0 ; j < M ; ++j) uNew->y[j] = x[uNew->a[j]] ; pbwtCursorWriteForwards (uNew) ; if (pOld->sites) array(pNew->sites, pNew->N, Site) = arr(pOld->sites, i, Site) ; ++pNew->N ; } pbwtCursorForwardsRead (uOld) ; } pbwtCursorToAFend (uNew, pNew) ; pNew->chrom = pOld->chrom ; pOld->chrom = 0 ; pNew->samples = pOld->samples ; pOld->samples = 0 ; pNew->missingOffset = pOld->missingOffset ; pOld->missingOffset = 0 ; pNew->zMissing = pOld->zMissing ; pOld->zMissing = 0 ; pbwtDestroy (pOld) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ; free(x) ; return pNew ; }
/** * \file bgrQuantifier <annotation.interval>. * \pre: it requires a BedGraph file from STDIN normalized by the number of mapped nucleotides */ int main( int argc, char* argv[] ) { Array bgrs; Array intervals; Array entries; int i, j, length; double value; if( argc < 2 ) { usage("%s <annotation.interval>\n%s requires a BedGraph from STDIN", argv[0], argv[0]); } bgrs = arrayCreate( 1000, BedGraph ); bgrParser_initFromFile ( "-" ); bgrs = bgrParser_getAllEntries (); bgrParser_deInit(); arraySort( bgrs, (ARRAYORDERF) bgrParser_sort ); intervalFind_addIntervalsToSearchSpace ( argv[1], 0 ); intervals = intervalFind_getAllIntervals (); for( i=0; i<arrayMax(intervals); i++ ) { Interval *currInterval = arrp( intervals, i, Interval ); length = currInterval->end - currInterval->start; entries = bgrParser_getValuesForRegion( bgrs, currInterval->chromosome, currInterval->start, currInterval->end); value = 0.0; for( j=0; j<arrayMax( entries ); j++) value += arru( entries, j, double ); printf("%s\t%s:%d-%d\t%f\n", currInterval->name, currInterval->chromosome, currInterval->start+1, currInterval->end, value /= length / 1000.0 ); arrayDestroy( entries ); } arrayDestroy( intervals ); return 0; }
int main (int argc, char *argv[]) { Array intervals; Interval *currInterval; SubInterval *currSubInterval; int refLength,altLength,offset; int h,i,j; Stringa buffer; Array geneTranscriptEntries; Texta geneTranscriptIds; Array alterations; Alteration *currAlteration,*nextAlteration; int numTranscripts; Stringa transcripts; VcfEntry *currVcfEntry; int position; Texta alternateAlleles; int flag1,flag2; VcfGenotype *currVcfGenotype; if (argc != 3) { usage ("%s <annotation.interval> <nameFeature>",argv[0]); } intervalFind_addIntervalsToSearchSpace (argv[1],0); geneTranscriptEntries = util_getGeneTranscriptEntries (intervalFind_getAllIntervals ()); buffer = stringCreate (100); transcripts = stringCreate (100); alterations = arrayCreate (100,Alteration); vcf_init ("-"); stringPrintf (buffer,"##INFO=<ID=VA,Number=.,Type=String,Description=\"Variant Annotation, %s, %s\">",argv[1],argv[2]); vcf_addComment (string (buffer)); puts (vcf_writeMetaData ()); puts (vcf_writeColumnHeaders ()); while (currVcfEntry = vcf_nextEntry ()) { if (vcf_isInvalidEntry (currVcfEntry)) { continue; } flag1 = 0; flag2 = 0; position = currVcfEntry->position - 1; // make zero-based alternateAlleles = vcf_getAlternateAlleles (currVcfEntry); for (h = 0; h < arrayMax (alternateAlleles); h++) { refLength = strlen (currVcfEntry->referenceAllele); altLength = strlen (textItem (alternateAlleles,h)); offset = MAX (refLength,altLength) - 1; util_clearAlterations (alterations); intervals = intervalFind_getOverlappingIntervals (currVcfEntry->chromosome,position,position + offset); for (i = 0; i < arrayMax (intervals); i++) { currInterval = arru (intervals,i,Interval*); j = 0; while (j < arrayMax (currInterval->subIntervals)) { currSubInterval = arrp (currInterval->subIntervals,j,SubInterval); if (currSubInterval->start <= position && (position + offset) < currSubInterval->end) { break; } j++; } if (j == arrayMax (currInterval->subIntervals)) { continue; } util_addAlteration (arrayp (alterations,arrayMax (alterations),Alteration),currInterval->name,argv[2],currInterval,position,0); } if (arrayMax (alterations) == 0) { continue; } arraySort (alterations,(ARRAYORDERF)util_sortAlterationsByGeneIdAndType); stringClear (buffer); i = 0; while (i < arrayMax (alterations)) { currAlteration = arrp (alterations,i,Alteration); stringAppendf (buffer,"%s%d:%s:%s:%c:%s",stringLen (buffer) == 0 ? "" : "|",h + 1,currAlteration->geneName,currAlteration->geneId,currAlteration->strand,currAlteration->type); stringClear (transcripts); stringAppendf (transcripts,"%s:%s:%d_%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition); numTranscripts = 1; j = i + 1; while (j < arrayMax (alterations)) { nextAlteration = arrp (alterations,j,Alteration); if (strEqual (currAlteration->geneId,nextAlteration->geneId) && strEqual (currAlteration->type,nextAlteration->type)) { stringAppendf (transcripts,":%s:%s:%d_%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition); numTranscripts++; } else { break; } j++; } i = j; geneTranscriptIds = util_getTranscriptIdsForGeneId (geneTranscriptEntries,currAlteration->geneId); stringAppendf (buffer,":%d/%d:%s",numTranscripts,arrayMax (geneTranscriptIds),string (transcripts)); } if (flag1 == 0) { printf ("%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s;VA=", currVcfEntry->chromosome,currVcfEntry->position,currVcfEntry->id, currVcfEntry->referenceAllele,currVcfEntry->alternateAllele, currVcfEntry->quality,currVcfEntry->filter,currVcfEntry->info); flag1 = 1; } printf ("%s%s",flag2 == 1 ? "," : "",string (buffer)); flag2 = 1; } if (flag1 == 1) { for (i = 0; i < arrayMax (currVcfEntry->genotypes); i++) { currVcfGenotype = arrp (currVcfEntry->genotypes,i,VcfGenotype); if (i == 0) { printf ("\t%s\t",currVcfEntry->genotypeFormat); } printf ("%s%s%s%s",currVcfGenotype->genotype, currVcfGenotype->details[0] != '\0' ? ":" : "", currVcfGenotype->details[0] != '\0' ? currVcfGenotype->details : "", i < arrayMax (currVcfEntry->genotypes) - 1 ? "\t" : ""); } puts (""); } } vcf_deInit (); return 0; }
void fileHelperLoad(FileHelper fileHelper) { FileHelperInternal *m = (FileHelperInternal *) fileHelper; fileHelperCheckCreate(m->filePath); int sizeOfInt = sizeof(int); struct direct **schemasIds = {0}; struct direct *schenaId; int size = scandir(m->filePath, &schemasIds, 0, alphasort); // loop all schemas int i; for (i = 0; i < size; i++) { schenaId = (struct direct *) schemasIds[i]; char *schemaIdString = schenaId->d_name; int schemaId = atoi(schemaIdString); if (schemaId != 0) { printf("schema %s\n", schenaId->d_name); struct direct **pagesIds = {0}; struct direct *pageStruct; char endOdString = '\0'; int pageDirLength = strlen(m->filePath); int schemaIdStringLength = strlen(schemaIdString); char slesh = '/'; char *pageDir = (char *) memoryAlloc(pageDirLength + 1 + schemaIdStringLength + 1); memcpy(pageDir, m->filePath, pageDirLength); memcpy(pageDir + pageDirLength, &slesh, 1); memcpy(pageDir + pageDirLength + 1, schemaIdString, schemaIdStringLength); memcpy(pageDir + pageDirLength + 1 + schemaIdStringLength, &endOdString, 1); // cleanBuffer(pageDir); // strcat(pageDir,m->filePath); // strcat(pageDir,"/"); // strcat(pageDir,schemaIdString); HashMap childrenRelations = hashmapCreate(SMALL_CONTAINER_SIZE); Registry registry = registryCreate(); hashmapPut(m->registryMap, schemaId, registry); PageManager pageManager = pageManagerCreate(schemaId, pageDir); hashmapPut(m->managers, schemaId, pageManager); int size = scandir(pageDir, &pagesIds, 0, alphasort); int h; //loop pages for (h = 0; h < size; h++) { //scandir (pageDir, &pagesIds, 0, alphasort); pageStruct = (struct direct *) pagesIds[h]; char *pageString = pageStruct->d_name; int pageId = atoi(pageString); if (pageId != 0) { printf("page %s\n", pageStruct->d_name); // create file path. //int i=0; int pageDirLength = strlen(pageDir); int pageStringLength = strlen(pageString); char slesh = '/'; char *filePath = (char *) memoryAlloc(pageDirLength + 1 + pageStringLength + 1); memcpy(filePath, pageDir, pageDirLength); memcpy(filePath + pageDirLength, &slesh, 1); memcpy(filePath + pageDirLength + 1, pageString, pageStringLength); memcpy(filePath + pageDirLength + 1 + pageStringLength, &endOdString, 1); FILE *fp; long len; // Create pointer to file. fp = fopen(filePath, "rb"); if (fp == NULL) { printf("couldn't open the properties file"); } fseek(fp, 0, SEEK_END); // Go to end len = ftell(fp); // Get position at end (length) // Read data to buffer char *buffer = memoryAlloc(sizeof(char) * len); // Create buffer char *pointerToFreeBuffer = buffer; fseek(fp, 0, SEEK_SET); // Go to the beginning. int result = fread(buffer, len, 1, fp); // Read into buffer if (result < 0) { printf("Fail to read file : %s", buffer); } fclose(fp); int order = 0; long index = 0; long step = 0; while (index < len) { char *start = buffer; int id; int schemaId; int numberOfAttributes; int childrenSize; int attributeSize; memcpy(&schemaId, buffer + SIZE_OF_INT * 0, SIZE_OF_INT); memcpy(&id, buffer + SIZE_OF_INT * 1, SIZE_OF_INT); memcpy(&numberOfAttributes, buffer + SIZE_OF_INT * 2, SIZE_OF_INT); buffer += SIZE_OF_INT * 3; Node node; nodeCreate(registry, id, schemaId, FALSE, &node); int h; for (h = 0; h < numberOfAttributes; h++) { memcpy(&attributeSize, buffer, SIZE_OF_INT); Attribute attribute = attributeDeserializeLocal(buffer); buffer += attributeSize; stringHashmapPut(node->attributes, attribute->name, attribute->nameLength, attribute); } memcpy(&childrenSize, buffer, SIZE_OF_INT); Array children = arrayCreate(childrenSize); hashmapPut(childrenRelations, id, children); int i; buffer += SIZE_OF_INT; int childrenIdBuffer; for (i = 0; i < childrenSize; i++) { memcpy(&childrenIdBuffer, buffer + SIZE_OF_INT, SIZE_OF_INT); void *bufferElement = memoryAlloc(childrenIdBuffer + SIZE_OF_INT * 2); memcpy(bufferElement, buffer, SIZE_OF_INT * 2 + childrenIdBuffer); arrayInsertObject(children, bufferElement); buffer += SIZE_OF_INT * 2 + childrenIdBuffer; } step = buffer - start; index += step; pageManagerRegister(pageManager, pageId, id, index - step, index, order, filePath); order++; } // Free the file buffer memoryFree(pointerToFreeBuffer); } } if (size > 0) { while (size) { size = size - 1; free(pagesIds[size]); } free(pagesIds); } hashmapIterate(childrenRelations, &updateChildren, registry); hashmapFree(childrenRelations); } } if (size > 0) { while (size) { size = size - 1; free(schemasIds[size]); } free(schemasIds); } }
static void testGet() { DataValue value; bool boolean; int8_t int8; uint8_t uint8; int16_t int16; uint16_t uint16; int32_t int32; uint32_t uint32; int64_t int64; uint64_t uint64; float float32; double float64; fixed16_16 fixed; void * pointer; const char * string; size_t length; const void * blob; HashTable * hashTable, * hashTableResult; DataArray * array, * arrayResult; AssociativeArray * assArray, * assArrayResult; value = valueCreateBoolean(false); boolean = valueGetBoolean(&value); TestCase_assert(!boolean, "Expected false but got true"); valueDispose(&value); value = valueCreateBoolean(true); boolean = valueGetBoolean(&value); TestCase_assert(boolean, "Expected true but got false"); valueDispose(&value); value = valueCreateInt8(0); int8 = valueGetInt8(&value); TestCase_assert(int8 == 0, "Expected 0 but got %d", int8); valueDispose(&value); value = valueCreateInt8(INT8_MIN); int8 = valueGetInt8(&value); TestCase_assert(int8 == INT8_MIN, "Expected -128 but got %d", int8); valueDispose(&value); value = valueCreateUInt8(0); uint8 = valueGetUInt8(&value); TestCase_assert(uint8 == 0, "Expected 0 but got %u", uint8); valueDispose(&value); value = valueCreateUInt8(UINT8_MAX); uint8 = valueGetUInt8(&value); TestCase_assert(uint8 == UINT8_MAX, "Expected 255 but got %u", uint8); valueDispose(&value); value = valueCreateInt16(0); int16 = valueGetInt16(&value); TestCase_assert(int16 == 0, "Expected 0 but got %d", int16); valueDispose(&value); value = valueCreateInt16(INT16_MIN); int16 = valueGetInt16(&value); TestCase_assert(int16 == INT16_MIN, "Expected -32768 but got %d", int16); valueDispose(&value); value = valueCreateUInt16(0); uint16 = valueGetUInt16(&value); TestCase_assert(uint16 == 0, "Expected 0 but got %u", uint16); valueDispose(&value); value = valueCreateUInt16(UINT16_MAX); uint16 = valueGetUInt16(&value); TestCase_assert(uint16 == UINT16_MAX, "Expected 65535 but got %u", uint16); valueDispose(&value); value = valueCreateInt32(0); int32 = valueGetInt32(&value); TestCase_assert(int32 == 0, "Expected 0 but got %d", int32); valueDispose(&value); value = valueCreateInt32(INT32_MIN); int32 = valueGetInt32(&value); TestCase_assert(int32 == INT32_MIN, "Expected -214783648 but got %d", int32); valueDispose(&value); value = valueCreateUInt32(0); uint32 = valueGetUInt32(&value); TestCase_assert(uint32 == 0, "Expected 0 but got %u", uint32); valueDispose(&value); value = valueCreateUInt32(UINT32_MAX); uint32 = valueGetUInt32(&value); TestCase_assert(uint32 == UINT32_MAX, "Expected 4294967295 but got %u", uint32); valueDispose(&value); value = valueCreateInt64(0); int64 = valueGetInt64(&value); TestCase_assert(int64 == 0, "Expected 0 but got " INT64_FORMAT, int64); valueDispose(&value); value = valueCreateInt64(INT64_MIN); int64 = valueGetInt64(&value); TestCase_assert(int64 == INT64_MIN, "Expected -9223372036854775808 but got " INT64_FORMAT, int64); valueDispose(&value); value = valueCreateUInt64(0); uint64 = valueGetUInt64(&value); TestCase_assert(uint64 == 0, "Expected 0 but got " UINT64_FORMAT, uint64); valueDispose(&value); value = valueCreateUInt64(UINT64_MAX); uint64 = valueGetUInt64(&value); TestCase_assert(uint64 == UINT64_MAX, "Expected 18446744073709551615 but got " UINT64_FORMAT, uint64); valueDispose(&value); value = valueCreateFloat(0.0f); float32 = valueGetFloat(&value); TestCase_assert(float32 == 0.0f, "Expected 0.0 but got %f", float32); valueDispose(&value); value = valueCreateFloat(FLT_MAX); float32 = valueGetFloat(&value); TestCase_assert(float32 == FLT_MAX, "Expected %f but got %f", FLT_MAX, float32); valueDispose(&value); value = valueCreateDouble(0.0); float64 = valueGetDouble(&value); TestCase_assert(float64 == 0.0, "Expected 0.0 but got %f", float64); valueDispose(&value); value = valueCreateDouble(DBL_MAX); float64 = valueGetDouble(&value); TestCase_assert(float64 == DBL_MAX, "Expected %f but got %f", DBL_MAX, float64); valueDispose(&value); value = valueCreateFixed16_16(0x00000); fixed = valueGetFixed16_16(&value); TestCase_assert(fixed == 0x00000, "Expected 0x00000 but got 0x%05X", fixed); valueDispose(&value); value = valueCreateFixed16_16(FIXED_16_16_MIN); fixed = valueGetFixed16_16(&value); TestCase_assert(fixed == FIXED_16_16_MIN, "Expected 0x%05X but got 0x%05X", FIXED_16_16_MIN, fixed); valueDispose(&value); value = valueCreatePointer(NULL); pointer = valueGetPointer(&value); TestCase_assert(pointer == NULL, "Expected NULL but got %p", pointer); valueDispose(&value); value = valueCreatePointer((void *) 0xFFFFFFFF); pointer = valueGetPointer(&value); TestCase_assert(pointer == (void *) 0xFFFFFFFF, "Expected 0xffffffff but got %p", pointer); valueDispose(&value); value = valueCreateString("", DATA_USE_STRLEN, false, false); string = valueGetString(&value); TestCase_assert(string != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(string, ""), "Expected \"\" but got \"%s\"", string); valueDispose(&value); value = valueCreateString("abc", DATA_USE_STRLEN, false, false); string = valueGetString(&value); TestCase_assert(string != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(string, "abc"), "Expected \"abc\" but got \"%s\"", string); valueDispose(&value); value = valueCreateBlob("", 0, false, false); blob = valueGetBlob(&value, &length); TestCase_assert(blob != NULL, "Expected non-NULL but got NULL"); TestCase_assert(length == 0, "Expected 0 but got " SIZE_T_FORMAT, length); valueDispose(&value); value = valueCreateBlob("\x00\xFF", 2, false, false); blob = valueGetBlob(&value, &length); TestCase_assert(blob != NULL, "Expected non-NULL but got NULL"); TestCase_assert(length == 2, "Expected 2 but got " SIZE_T_FORMAT, length); TestCase_assert(!memcmp(blob, "\x00\xFF", 2), "Expected {0x00, 0xFF} but got {0x%02X, 0x%02X}", ((char *) blob)[0], ((char *) blob)[1]); valueDispose(&value); value = valueCreateHashTable(hashTable = hashCreate(), true, false); hashTableResult = valueGetHashTable(&value); TestCase_assert(hashTableResult == hashTable, "Expected %p but got %p", hashTable, hashTableResult); valueDispose(&value); value = valueCreateArray(array = arrayCreate(), true, false); arrayResult = valueGetArray(&value); TestCase_assert(arrayResult == array, "Expected %p but got %p", array, arrayResult); valueDispose(&value); value = valueCreateAssociativeArray(assArray = associativeArrayCreate(), true, false); assArrayResult = valueGetAssociativeArray(&value); TestCase_assert(assArrayResult == assArray, "Expected %p but got %p", assArray, assArrayResult); valueDispose(&value); }
static void testCopy() { DataValue value, copy; HashTable * hashTable; DataArray * array; AssociativeArray * assArray; value = valueCreateBoolean(false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, copy.type); TestCase_assert(!copy.value.boolean, "Expected false but got true"); valueDispose(&value); valueDispose(©); value = valueCreateBoolean(true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, copy.type); TestCase_assert(copy.value.boolean, "Expected true but got false"); valueDispose(&value); valueDispose(©); value = valueCreateInt8(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT8, "Expected %d but got %d", DATA_TYPE_INT8, copy.type); TestCase_assert(copy.value.int8 == 0, "Expected 0 but got %d", copy.value.int8); valueDispose(&value); valueDispose(©); value = valueCreateInt8(INT8_MIN); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT8, "Expected %d but got %d", DATA_TYPE_INT8, copy.type); TestCase_assert(copy.value.int8 == INT8_MIN, "Expected -128 but got %d", copy.value.int8); valueDispose(&value); valueDispose(©); value = valueCreateUInt8(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT8, "Expected %d but got %d", DATA_TYPE_UINT8, copy.type); TestCase_assert(copy.value.uint8 == 0, "Expected 0 but got %u", copy.value.uint8); valueDispose(&value); valueDispose(©); value = valueCreateUInt8(UINT8_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT8, "Expected %d but got %d", DATA_TYPE_UINT8, copy.type); TestCase_assert(copy.value.uint8 == UINT8_MAX, "Expected 255 but got %u", copy.value.uint8); valueDispose(&value); valueDispose(©); value = valueCreateInt16(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT16, "Expected %d but got %d", DATA_TYPE_INT16, copy.type); TestCase_assert(copy.value.int16 == 0, "Expected 0 but got %d", copy.value.int16); valueDispose(&value); valueDispose(©); value = valueCreateInt16(INT16_MIN); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT16, "Expected %d but got %d", DATA_TYPE_INT16, copy.type); TestCase_assert(copy.value.int16 == INT16_MIN, "Expected -32768 but got %d", copy.value.int16); valueDispose(&value); valueDispose(©); value = valueCreateUInt16(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT16, "Expected %d but got %d", DATA_TYPE_UINT16, copy.type); TestCase_assert(copy.value.uint16 == 0, "Expected 0 but got %u", copy.value.uint16); valueDispose(&value); valueDispose(©); value = valueCreateUInt16(UINT16_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT16, "Expected %d but got %d", DATA_TYPE_UINT16, copy.type); TestCase_assert(copy.value.uint16 == UINT16_MAX, "Expected 65535 but got %u", copy.value.uint16); valueDispose(&value); valueDispose(©); value = valueCreateInt32(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT32, "Expected %d but got %d", DATA_TYPE_INT32, copy.type); TestCase_assert(copy.value.int32 == 0, "Expected 0 but got %d", copy.value.int32); valueDispose(&value); valueDispose(©); value = valueCreateInt32(INT32_MIN); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT32, "Expected %d but got %d", DATA_TYPE_INT32, copy.type); TestCase_assert(copy.value.int32 == INT32_MIN, "Expected -214783648 but got %d", copy.value.int32); valueDispose(&value); valueDispose(©); value = valueCreateUInt32(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT32, "Expected %d but got %d", DATA_TYPE_UINT32, copy.type); TestCase_assert(copy.value.uint32 == 0, "Expected 0 but got %u", copy.value.uint32); valueDispose(&value); valueDispose(©); value = valueCreateUInt32(UINT32_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT32, "Expected %d but got %d", DATA_TYPE_UINT32, copy.type); TestCase_assert(copy.value.uint32 == UINT32_MAX, "Expected 4294967295 but got %u", copy.value.uint32); valueDispose(&value); valueDispose(©); value = valueCreateInt64(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT64, "Expected %d but got %d", DATA_TYPE_INT64, copy.type); TestCase_assert(copy.value.int64 == 0, "Expected 0 but got " INT64_FORMAT, copy.value.int64); valueDispose(&value); valueDispose(©); value = valueCreateInt64(INT64_MIN); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_INT64, "Expected %d but got %d", DATA_TYPE_INT64, copy.type); TestCase_assert(copy.value.int64 == INT64_MIN, "Expected -9223372036854775808 but got " INT64_FORMAT, copy.value.int64); valueDispose(&value); valueDispose(©); value = valueCreateUInt64(0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT64, "Expected %d but got %d", DATA_TYPE_UINT64, copy.type); TestCase_assert(copy.value.uint64 == 0, "Expected 0 but got " UINT64_FORMAT, copy.value.uint64); valueDispose(&value); valueDispose(©); value = valueCreateUInt64(UINT64_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_UINT64, "Expected %d but got %d", DATA_TYPE_UINT64, copy.type); TestCase_assert(copy.value.uint64 == UINT64_MAX, "Expected 18446744073709551615 but got " UINT64_FORMAT, copy.value.uint64); valueDispose(&value); valueDispose(©); value = valueCreateFloat(0.0f); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_FLOAT, "Expected %d but got %d", DATA_TYPE_FLOAT, copy.type); TestCase_assert(copy.value.float32 == 0.0f, "Expected 0.0 but got %f", copy.value.float32); valueDispose(&value); valueDispose(©); value = valueCreateFloat(FLT_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_FLOAT, "Expected %d but got %d", DATA_TYPE_FLOAT, copy.type); TestCase_assert(copy.value.float32 == FLT_MAX, "Expected %f but got %f", FLT_MAX, copy.value.float32); valueDispose(&value); valueDispose(©); value = valueCreateDouble(0.0); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_DOUBLE, "Expected %d but got %d", DATA_TYPE_DOUBLE, copy.type); TestCase_assert(copy.value.float64 == 0.0, "Expected 0.0 but got %f", copy.value.float64); valueDispose(&value); valueDispose(©); value = valueCreateDouble(DBL_MAX); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_DOUBLE, "Expected %d but got %d", DATA_TYPE_DOUBLE, copy.type); TestCase_assert(copy.value.float64 == DBL_MAX, "Expected %f but got %f", DBL_MAX, copy.value.float64); valueDispose(&value); valueDispose(©); value = valueCreateFixed16_16(0x00000); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_FIXED_16_16, "Expected %d but got %d", DATA_TYPE_FIXED_16_16, copy.type); TestCase_assert(copy.value.fixed == 0.0, "Expected 0.0 but got %f", copy.value.fixed); valueDispose(&value); valueDispose(©); value = valueCreateFixed16_16(FIXED_16_16_MIN); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_FIXED_16_16, "Expected %d but got %d", DATA_TYPE_FIXED_16_16, copy.type); TestCase_assert(copy.value.fixed == FIXED_16_16_MIN, "Expected 0x%05X but got 0x%05X", FIXED_16_16_MIN, copy.value.fixed); valueDispose(&value); valueDispose(©); value = valueCreatePointer(NULL); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_POINTER, "Expected %d but got %d", DATA_TYPE_POINTER, copy.type); TestCase_assert(copy.value.pointer == NULL, "Expected NULL but got %p", copy.value.pointer); valueDispose(&value); valueDispose(©); value = valueCreatePointer((void *) 0xFFFFFFFF); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_POINTER, "Expected %d but got %d", DATA_TYPE_POINTER, copy.type); TestCase_assert(copy.value.pointer == (void *) 0xFFFFFFFF, "Expected 0xffffffff but got %p", copy.value.pointer); valueDispose(&value); valueDispose(©); value = valueCreateString("", DATA_USE_STRLEN, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_STRING, "Expected %d but got %d", DATA_TYPE_STRING, copy.type); TestCase_assert(copy.value.string != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(copy.value.string, ""), "Expected \"\" but got \"%s\"", copy.value.string); valueDispose(&value); valueDispose(©); value = valueCreateString("abc", DATA_USE_STRLEN, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_STRING, "Expected %d but got %d", DATA_TYPE_STRING, copy.type); TestCase_assert(copy.value.string != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(copy.value.string, "abc"), "Expected \"abc\" but got \"%s\"", copy.value.string); TestCase_assert(copy.value.string == value.value.string, "Expected %p but got %p", value.value.string, copy.value.string); valueDispose(&value); valueDispose(©); value = valueCreateString("abc", DATA_USE_STRLEN, true, true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_STRING, "Expected %d but got %d", DATA_TYPE_STRING, copy.type); TestCase_assert(copy.value.string != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(copy.value.string, "abc"), "Expected \"abc\" but got \"%s\"", copy.value.string); TestCase_assert(copy.value.string != value.value.string, "Expected pointers to differ, but both are %p", copy.value.string); valueDispose(&value); valueDispose(©); value = valueCreateBlob("", 0, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_BLOB, "Expected %d but got %d", DATA_TYPE_BLOB, copy.type); TestCase_assert(copy.value.blob.bytes != NULL, "Expected non-NULL but got NULL"); TestCase_assert(copy.value.blob.length == 0, "Expected 0 but got " SIZE_T_FORMAT, copy.value.blob.length); valueDispose(&value); valueDispose(©); value = valueCreateBlob("\x00\xFF", 2, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_BLOB, "Expected %d but got %d", DATA_TYPE_BLOB, copy.type); TestCase_assert(copy.value.blob.bytes != NULL, "Expected non-NULL but got NULL"); TestCase_assert(copy.value.blob.length == 2, "Expected 2 but got " SIZE_T_FORMAT, copy.value.blob.length); TestCase_assert(!memcmp(copy.value.blob.bytes, "\x00\xFF", 2), "Expected {0x00, 0xFF} but got {0x%02X, 0x%02X}", ((char *) copy.value.blob.bytes)[0], ((char *) copy.value.blob.bytes)[1]); TestCase_assert(copy.value.blob.bytes == value.value.blob.bytes, "Expected %p but got %p", value.value.blob.bytes, copy.value.blob.bytes); valueDispose(&value); valueDispose(©); value = valueCreateBlob("\x00\xFF", 2, true, true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_BLOB, "Expected %d but got %d", DATA_TYPE_BLOB, copy.type); TestCase_assert(copy.value.blob.bytes != NULL, "Expected non-NULL but got NULL"); TestCase_assert(copy.value.blob.length == 2, "Expected 2 but got " SIZE_T_FORMAT, copy.value.blob.length); TestCase_assert(!memcmp(copy.value.blob.bytes, "\x00\xFF", 2), "Expected {0x00, 0xFF} but got {0x%02X, 0x%02X}", ((char *) copy.value.blob.bytes)[0], ((char *) copy.value.blob.bytes)[1]); TestCase_assert(copy.value.blob.bytes != value.value.blob.bytes, "Expected pointers to differ, but both are %p", copy.value.blob.bytes); valueDispose(&value); valueDispose(©); hashTable = hashCreate(); hashSet(hashTable, "a", valueCreateBoolean(false)); value = valueCreateHashTable(hashTable, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_HASH_TABLE, "Expected %d but got %d", DATA_TYPE_HASH_TABLE, copy.type); TestCase_assert(copy.value.hashTable == value.value.hashTable, "Expected %p but got %p", value.value.hashTable, copy.value.hashTable); valueDispose(&value); valueDispose(©); value = valueCreateHashTable(hashTable, true, true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_HASH_TABLE, "Expected %d but got %d", DATA_TYPE_HASH_TABLE, copy.type); TestCase_assert(copy.value.hashTable->count == 1, "Expected 1 but got " SIZE_T_FORMAT, copy.value.hashTable->count); TestCase_assert(copy.value.hashTable != value.value.hashTable, "Expected pointers to differ, but both are %p", copy.value.hashTable); valueDispose(&value); valueDispose(©); hashDispose(hashTable); array = arrayCreate(); arrayAppend(array, valueCreateBoolean(false)); value = valueCreateArray(array, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_ARRAY, "Expected %d but got %d", DATA_TYPE_ARRAY, copy.type); TestCase_assert(copy.value.array == value.value.array, "Expected %p but got %p", value.value.array, copy.value.array); valueDispose(&value); valueDispose(©); value = valueCreateArray(array, true, true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_ARRAY, "Expected %d but got %d", DATA_TYPE_ARRAY, copy.type); TestCase_assert(copy.value.array->count == 1, "Expected 1 but got " SIZE_T_FORMAT, copy.value.array->count); TestCase_assert(copy.value.array != value.value.array, "Expected pointers to differ, but both are %p", copy.value.array); valueDispose(&value); valueDispose(©); arrayDispose(array); assArray = associativeArrayCreate(); associativeArrayAppend(assArray, "a", valueCreateBoolean(false)); value = valueCreateAssociativeArray(assArray, false, false); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_ASSOCIATIVE_ARRAY, "Expected %d but got %d", DATA_TYPE_ASSOCIATIVE_ARRAY, copy.type); TestCase_assert(copy.value.associativeArray == value.value.associativeArray, "Expected %p but got %p", value.value.associativeArray, copy.value.associativeArray); valueDispose(&value); valueDispose(©); value = valueCreateAssociativeArray(assArray, true, true); copy = valueCopy(&value); TestCase_assert(copy.type == DATA_TYPE_ASSOCIATIVE_ARRAY, "Expected %d but got %d", DATA_TYPE_ASSOCIATIVE_ARRAY, copy.type); TestCase_assert(copy.value.associativeArray->count == 1, "Expected 1 but got " SIZE_T_FORMAT, copy.value.associativeArray->count); TestCase_assert(copy.value.associativeArray != value.value.associativeArray, "Expected pointers to differ, but both are %p", copy.value.associativeArray); valueDispose(&value); valueDispose(©); associativeArrayDispose(assArray); }
void initWorkerProcess(struct workerProcess *worker, char *worker_name) { struct configuration *conf; int i; struct app *app; struct moduleAttr *module; if (Server.stat_fd != 0) close(Server.stat_fd); setProctitle(worker_name); worker->pid = getpid(); worker->ppid = getppid(); worker->alive = 1; worker->start_time = Server.cron_time; worker->worker = spotWorker(worker_name); worker->master_stat_fd = 0; ASSERT(worker->worker); worker->stats = NULL; initWorkerSignals(); worker->center = eventcenterInit(WHEAT_CLIENT_MAX); if (!worker->center) { wheatLog(WHEAT_WARNING, "eventcenter_init failed"); halt(1); } if (createEvent(worker->center, Server.ipfd, EVENT_READABLE, acceptClient, NULL) == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "createEvent failed"); halt(1); } // It may nonblock after fork??? if (wheatNonBlock(Server.neterr, Server.ipfd) == NET_WRONG) { wheatLog(WHEAT_WARNING, "Set nonblock %d failed: %s", Server.ipfd, Server.neterr); halt(1); } module = NULL; conf = getConfiguration("protocol"); if (conf->target.ptr) { module = getModule(PROTOCOL, conf->target.ptr); if (module && getProtocol(module)->initProtocol() == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "init protocol failed"); halt(1); } } if (!module) { wheatLog(WHEAT_WARNING, "find protocol %s failed", conf->target.ptr); halt(1); } worker->protocol = getProtocol(module); StatTotalClient = getStatItemByName("Total client"); gettimeofday(&Server.cron_time, NULL); if (worker->worker->setup) worker->worker->setup(); WorkerProcess->refresh_time = Server.cron_time.tv_sec; FreeClients = createAndFillPool(); Clients = createList(); StatBufferSize = getStatItemByName("Max buffer size"); StatTotalRequest = getStatItemByName("Total request"); StatFailedRequest = getStatItemByName("Total failed request"); StatRunTime = getStatItemByName("Worker run time"); worker->apps = arrayCreate(sizeof(struct app*), 3); if (!worker->apps) { wheatLog(WHEAT_WARNING, "array create failed"); halt(1); } getAppsByProtocol(worker->apps, worker->protocol); for (i = 0; i < narray(worker->apps); i++) { app = *(struct app**)arrayIndex(worker->apps, i); if (app->initApp(worker->protocol) == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "init app failed %s", getModuleName(APP, app)); halt(1); } } sendStatPacket(WorkerProcess); }
static void testConversions() { DataValue value; bool boolean; int8_t int8; uint8_t uint8; int16_t int16; uint16_t uint16; int32_t int32; uint32_t uint32; int64_t int64; uint64_t uint64; float float32; double float64; fixed16_16 fixed; void * pointer; const char * string; const void * blob; HashTable * hashTable; DataArray * array; AssociativeArray * assArray; value = valueCreateBoolean(false); getAllValues(value); assertAllTypes(0, 0, 0.0, 0x00000, NULL); value = valueCreateBoolean(true); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateInt8(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateInt8(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateUInt8(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateUInt8(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateInt16(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateInt16(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateUInt16(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateUInt16(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateInt32(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateInt32(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateUInt32(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateUInt32(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateInt64(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateInt64(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateUInt64(0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateUInt64(1); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateFloat(0.0f); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateFloat(1.0f); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateFloat(1.25f); getAllValues(value); assertAllTypes(true, 1, 1.25, 0x14000, NULL); value = valueCreateDouble(0.0); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateDouble(1.0); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateDouble(1.25); getAllValues(value); assertAllTypes(true, 1, 1.25, 0x14000, NULL); value = valueCreateFixed16_16(0x00000); getAllValues(value); assertAllTypes(false, 0, 0.0, 0x00000, NULL); value = valueCreateFixed16_16(0x10000); getAllValues(value); assertAllTypes(true, 1, 1.0, 0x10000, NULL); value = valueCreateFixed16_16(0x14000); getAllValues(value); assertAllTypes(true, 1, 1.25, 0x14000, NULL); value = valueCreatePointer(NULL); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreatePointer((void *) 0x1); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate((void *) 0x1, NULL, NULL, NULL, NULL, NULL); value = valueCreateString(NULL, 0, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreateString("abcd", 4, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate(value.value.string, value.value.string, value.value.string, NULL, NULL, NULL); value = valueCreateBlob(NULL, 0, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreateBlob("abcd", 4, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate(value.value.blob.bytes, NULL, value.value.blob.bytes, NULL, NULL, NULL); value = valueCreateHashTable(NULL, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreateHashTable(hashCreate(), true, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate(value.value.hashTable, NULL, NULL, value.value.hashTable, NULL, NULL); valueDispose(&value); value = valueCreateArray(NULL, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreateArray(arrayCreate(), true, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate(value.value.array, NULL, NULL, NULL, value.value.array, NULL); valueDispose(&value); value = valueCreateAssociativeArray(NULL, false, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypes(NULL); value = valueCreateAssociativeArray(associativeArrayCreate(), true, false); getAllValues(value); assertAllPrimitiveTypes(false, 0, 0.0, 0x00000); assertAllPointerTypesSeparate(value.value.associativeArray, NULL, NULL, NULL, NULL, value.value.associativeArray); valueDispose(&value); }
static void testCreate() { DataValue value; char * string1 = "abc", * string2 = "foo"; char blob1[] = {0x00, 0x01}, blob2[] = {0x03, 0x05, 0x07}; HashTable * hashTable1, * hashTable2; DataArray * array1, * array2; AssociativeArray * assArray1, * assArray2; value = valueCreateBoolean(false); TestCase_assert(value.type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, value.type); TestCase_assert(!value.value.boolean, "Expected false but got true"); valueDispose(&value); value = valueCreateBoolean(true); TestCase_assert(value.type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, value.type); TestCase_assert(value.value.boolean, "Expected true but got false"); valueDispose(&value); value = valueCreateInt8(0); TestCase_assert(value.type == DATA_TYPE_INT8, "Expected %d but got %d", DATA_TYPE_INT8, value.type); TestCase_assert(value.value.int8 == 0, "Expected 0 but got %d", value.value.int8); valueDispose(&value); value = valueCreateInt8(1); TestCase_assert(value.type == DATA_TYPE_INT8, "Expected %d but got %d", DATA_TYPE_INT8, value.type); TestCase_assert(value.value.int8 == 1, "Expected 1 but got %d", value.value.int8); valueDispose(&value); value = valueCreateUInt8(0); TestCase_assert(value.type == DATA_TYPE_UINT8, "Expected %d but got %d", DATA_TYPE_UINT8, value.type); TestCase_assert(value.value.uint8 == 0, "Expected 0 but got %d", value.value.uint8); valueDispose(&value); value = valueCreateUInt8(1); TestCase_assert(value.type == DATA_TYPE_UINT8, "Expected %d but got %d", DATA_TYPE_UINT8, value.type); TestCase_assert(value.value.uint8 == 1, "Expected 1 but got %d", value.value.uint8); valueDispose(&value); value = valueCreateInt16(0); TestCase_assert(value.type == DATA_TYPE_INT16, "Expected %d but got %d", DATA_TYPE_INT16, value.type); TestCase_assert(value.value.int16 == 0, "Expected 0 but got %d", value.value.int16); valueDispose(&value); value = valueCreateInt16(1); TestCase_assert(value.type == DATA_TYPE_INT16, "Expected %d but got %d", DATA_TYPE_INT16, value.type); TestCase_assert(value.value.int16 == 1, "Expected 1 but got %d", value.value.int16); valueDispose(&value); value = valueCreateUInt16(0); TestCase_assert(value.type == DATA_TYPE_UINT16, "Expected %d but got %d", DATA_TYPE_UINT16, value.type); TestCase_assert(value.value.uint16 == 0, "Expected 0 but got %d", value.value.uint16); valueDispose(&value); value = valueCreateUInt16(1); TestCase_assert(value.type == DATA_TYPE_UINT16, "Expected %d but got %d", DATA_TYPE_UINT16, value.type); TestCase_assert(value.value.uint16 == 1, "Expected 1 but got %d", value.value.uint16); valueDispose(&value); value = valueCreateInt32(0); TestCase_assert(value.type == DATA_TYPE_INT32, "Expected %d but got %d", DATA_TYPE_INT32, value.type); TestCase_assert(value.value.int32 == 0, "Expected 0 but got %d", value.value.int32); valueDispose(&value); value = valueCreateInt32(1); TestCase_assert(value.type == DATA_TYPE_INT32, "Expected %d but got %d", DATA_TYPE_INT32, value.type); TestCase_assert(value.value.int32 == 1, "Expected 1 but got %d", value.value.int32); valueDispose(&value); value = valueCreateUInt32(0); TestCase_assert(value.type == DATA_TYPE_UINT32, "Expected %d but got %d", DATA_TYPE_UINT32, value.type); TestCase_assert(value.value.uint32 == 0, "Expected 0 but got %d", value.value.uint32); valueDispose(&value); value = valueCreateUInt32(1); TestCase_assert(value.type == DATA_TYPE_UINT32, "Expected %d but got %d", DATA_TYPE_UINT32, value.type); TestCase_assert(value.value.uint32 == 1, "Expected 1 but got %d", value.value.uint32); valueDispose(&value); value = valueCreateInt64(0); TestCase_assert(value.type == DATA_TYPE_INT64, "Expected %d but got %d", DATA_TYPE_INT64, value.type); TestCase_assert(value.value.int64 == 0, "Expected 0 but got " INT64_FORMAT, value.value.int64); valueDispose(&value); value = valueCreateInt64(1); TestCase_assert(value.type == DATA_TYPE_INT64, "Expected %d but got %d", DATA_TYPE_INT64, value.type); TestCase_assert(value.value.int64 == 1, "Expected 1 but got " INT64_FORMAT, value.value.int64); valueDispose(&value); value = valueCreateUInt64(0); TestCase_assert(value.type == DATA_TYPE_UINT64, "Expected %d but got %d", DATA_TYPE_UINT64, value.type); TestCase_assert(value.value.uint64 == 0, "Expected 0 but got " UINT64_FORMAT, value.value.uint64); valueDispose(&value); value = valueCreateUInt64(1); TestCase_assert(value.type == DATA_TYPE_UINT64, "Expected %d but got %d", DATA_TYPE_UINT64, value.type); TestCase_assert(value.value.uint64 == 1, "Expected 1 but got " UINT64_FORMAT, value.value.uint64); valueDispose(&value); value = valueCreateFloat(0.0f); TestCase_assert(value.type == DATA_TYPE_FLOAT, "Expected %d but got %d", DATA_TYPE_FLOAT, value.type); TestCase_assert(value.value.float32 == 0.0f, "Expected 0.0 but got %f", value.value.float32); valueDispose(&value); value = valueCreateFloat(1.0f); TestCase_assert(value.type == DATA_TYPE_FLOAT, "Expected %d but got %d", DATA_TYPE_FLOAT, value.type); TestCase_assert(value.value.float32 == 1.0f, "Expected 1.0 but got %f", value.value.float32); valueDispose(&value); value = valueCreateDouble(0.0); TestCase_assert(value.type == DATA_TYPE_DOUBLE, "Expected %d but got %d", DATA_TYPE_DOUBLE, value.type); TestCase_assert(value.value.float64 == 0.0, "Expected 0.0 but got %f", value.value.float64); valueDispose(&value); value = valueCreateDouble(1.0); TestCase_assert(value.type == DATA_TYPE_DOUBLE, "Expected %d but got %d", DATA_TYPE_DOUBLE, value.type); TestCase_assert(value.value.float64 == 1.0, "Expected 1.0 but got %f", value.value.float64); valueDispose(&value); value = valueCreateFixed16_16(0x00000); TestCase_assert(value.type == DATA_TYPE_FIXED_16_16, "Expected %d but got %d", DATA_TYPE_FIXED_16_16, value.type); TestCase_assert(value.value.fixed == 0x00000, "Expected 0x00000 but got 0x%05X", value.value.fixed); valueDispose(&value); value = valueCreateFixed16_16(0x10000); TestCase_assert(value.type == DATA_TYPE_FIXED_16_16, "Expected %d but got %d", DATA_TYPE_FIXED_16_16, value.type); TestCase_assert(value.value.fixed == 0x10000, "Expected 0x10000 but got 0x%05X", value.value.fixed); valueDispose(&value); value = valueCreatePointer((void *) 0x0); TestCase_assert(value.type == DATA_TYPE_POINTER, "Expected %d but got %d", DATA_TYPE_POINTER, value.type); TestCase_assert(value.value.pointer == (void *) 0x0, "Expected 0x0 but got %p", value.value.pointer); valueDispose(&value); value = valueCreatePointer((void *) 0x1); TestCase_assert(value.type == DATA_TYPE_POINTER, "Expected %d but got %d", DATA_TYPE_POINTER, value.type); TestCase_assert(value.value.pointer == (void *) 0x1, "Expected 0x1 but got %p", value.value.pointer); valueDispose(&value); value = valueCreateString(string1, 2, true, true); TestCase_assert(value.type == DATA_TYPE_STRING, "Expected %d but got %d", DATA_TYPE_STRING, value.type); TestCase_assert(!strcmp(value.value.string, "ab"), "Expected \"ab\" but got \"%s\"", value.value.string); TestCase_assert(value.value.string != string1, "Expected differing pointers, but both are %p", string1); valueDispose(&value); value = valueCreateString(string2, DATA_USE_STRLEN, false, false); TestCase_assert(value.type == DATA_TYPE_STRING, "Expected %d but got %d", DATA_TYPE_STRING, value.type); TestCase_assert(value.value.string == string2, "Expected %p but got %p", string2, value.value.string); valueDispose(&value); value = valueCreateBlob(blob1, sizeof(blob1), true, true); TestCase_assert(value.type == DATA_TYPE_BLOB, "Expected %d but got %d", DATA_TYPE_BLOB, value.type); TestCase_assert(value.value.blob.length == 2, "Expected 2 but got " SIZE_T_FORMAT, value.value.blob.length); TestCase_assert(!memcmp(value.value.blob.bytes, blob1, sizeof(blob1)), "Expected {0x%02X, 0x%02X} but got {0x%02X, 0x%02X}", blob1[0], blob1[1], ((char *) value.value.blob.bytes)[0], ((char *) value.value.blob.bytes)[1]); TestCase_assert(value.value.blob.bytes != blob1, "Expected differing pointers, but both are %p", blob1); valueDispose(&value); value = valueCreateBlob(blob2, sizeof(blob2), false, false); TestCase_assert(value.type == DATA_TYPE_BLOB, "Expected %d but got %d", DATA_TYPE_BLOB, value.type); TestCase_assert(value.value.blob.length == 3, "Expected 3 but got " SIZE_T_FORMAT, value.value.blob.length); TestCase_assert(value.value.blob.bytes == blob2, "Expected %p but got %p", blob2, value.value.blob.bytes); valueDispose(&value); hashTable1 = hashCreate(); hashSet(hashTable1, "a", valueCreateBoolean(false)); hashTable2 = hashCreate(); value = valueCreateHashTable(hashTable1, true, true); TestCase_assert(value.type == DATA_TYPE_HASH_TABLE, "Expected %d but got %d", DATA_TYPE_HASH_TABLE, value.type); TestCase_assert(value.value.hashTable != hashTable1, "Expected differing pointers, but both are %p", hashTable1); TestCase_assert(value.value.hashTable->count == hashTable1->count, "Expected " SIZE_T_FORMAT " but got " SIZE_T_FORMAT, hashTable1->count, value.value.hashTable->count); TestCase_assert(hashGet(value.value.hashTable, "a") != NULL, "Expected non-NULL but got NULL"); TestCase_assert(hashGet(value.value.hashTable, "a")->type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, hashGet(value.value.hashTable, "a")->type); TestCase_assert(!hashGet(value.value.hashTable, "a")->value.boolean, "Expected false but got true"); valueDispose(&value); value = valueCreateHashTable(hashTable2, true, false); TestCase_assert(value.type == DATA_TYPE_HASH_TABLE, "Expected %d but got %d", DATA_TYPE_HASH_TABLE, value.type); TestCase_assert(value.value.hashTable == hashTable2, "Expected %p but got %p", hashTable2, value.value.hashTable); valueDispose(&value); array1 = arrayCreate(); arrayAppend(array1, valueCreateBoolean(false)); array2 = arrayCreate(); value = valueCreateArray(array1, true, true); TestCase_assert(value.type == DATA_TYPE_ARRAY, "Expected %d but got %d", DATA_TYPE_ARRAY, value.type); TestCase_assert(value.value.array != array1, "Expected differing pointers, but both are %p", array1); TestCase_assert(value.value.array->count == array1->count, "Expected " SIZE_T_FORMAT " but got " SIZE_T_FORMAT, array1->count, value.value.array->count); TestCase_assert(arrayGet(value.value.array, 0) != NULL, "Expected non-NULL but got NULL"); TestCase_assert(arrayGet(value.value.array, 0)->type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, arrayGet(value.value.array, 0)->type); TestCase_assert(!arrayGet(value.value.array, 0)->value.boolean, "Expected false but got true"); valueDispose(&value); value = valueCreateArray(array2, true, false); TestCase_assert(value.type == DATA_TYPE_ARRAY, "Expected %d but got %d", DATA_TYPE_ARRAY, value.type); TestCase_assert(value.value.array == array2, "Expected %p but got %p", array2, value.value.array); valueDispose(&value); assArray1 = associativeArrayCreate(); associativeArrayAppend(assArray1, "a", valueCreateBoolean(false)); assArray2 = associativeArrayCreate(); value = valueCreateAssociativeArray(assArray1, true, true); TestCase_assert(value.type == DATA_TYPE_ASSOCIATIVE_ARRAY, "Expected %d but got %d", DATA_TYPE_ASSOCIATIVE_ARRAY, value.type); TestCase_assert(value.value.associativeArray != assArray1, "Expected differing pointers, but both are %p", assArray1); TestCase_assert(value.value.associativeArray->count == assArray1->count, "Expected " SIZE_T_FORMAT " but got " SIZE_T_FORMAT, assArray1->count, value.value.associativeArray->count); TestCase_assert(associativeArrayGetValueAtIndex(value.value.associativeArray, 0) != NULL, "Expected non-NULL but got NULL"); TestCase_assert(associativeArrayGetValueAtIndex(value.value.associativeArray, 0)->type == DATA_TYPE_BOOLEAN, "Expected %d but got %d", DATA_TYPE_BOOLEAN, associativeArrayGetValueAtIndex(value.value.associativeArray, 0)->type); TestCase_assert(!associativeArrayGetValueAtIndex(value.value.associativeArray, 0)->value.boolean, "Expected false but got true"); TestCase_assert(!strcmp(associativeArrayGetKeyAtIndex(value.value.associativeArray, 0), "a"), "Expected \"a\" but got \"%s\"", associativeArrayGetKeyAtIndex(value.value.associativeArray, 0)); valueDispose(&value); value = valueCreateAssociativeArray(assArray2, true, false); TestCase_assert(value.type == DATA_TYPE_ASSOCIATIVE_ARRAY, "Expected %d but got %d", DATA_TYPE_ASSOCIATIVE_ARRAY, value.type); TestCase_assert(value.value.associativeArray == assArray2, "Expected %p but got %p", assArray2, value.value.associativeArray); valueDispose(&value); }
static void deserializeContainer(DataValue * container, DeserializationContext * context) { size_t index, count; const char * key = NULL; enum DataValueType type; DataValue value; const void * blob; size_t length = 0; count = context->beginArray(context, NULL); if (context->status != SERIALIZATION_ERROR_OK) { return; } for (index = 0; index < count; index++) { if (container->type == DATA_TYPE_HASH_TABLE || container->type == DATA_TYPE_ASSOCIATIVE_ARRAY) { key = context->readString(context, NULL); if (context->status != SERIALIZATION_ERROR_OK) { return; } index++; } type = context->readEnumeration(context, NULL, ALL_DATA_TYPE_ENUM_KEYS_AND_VALUES, NULL); if (context->status != SERIALIZATION_ERROR_OK) { return; } index++; switch (type) { case DATA_TYPE_BOOLEAN: value = valueCreateBoolean(context->readBoolean(context, NULL)); break; case DATA_TYPE_INT8: value = valueCreateInt8(context->readInt8(context, NULL)); break; case DATA_TYPE_UINT8: value = valueCreateUInt8(context->readUInt8(context, NULL)); break; case DATA_TYPE_INT16: value = valueCreateInt16(context->readInt16(context, NULL)); break; case DATA_TYPE_UINT16: value = valueCreateUInt16(context->readUInt16(context, NULL)); break; case DATA_TYPE_INT32: value = valueCreateInt32(context->readInt32(context, NULL)); break; case DATA_TYPE_UINT32: value = valueCreateUInt32(context->readUInt32(context, NULL)); break; case DATA_TYPE_INT64: value = valueCreateInt64(context->readInt64(context, NULL)); break; case DATA_TYPE_UINT64: value = valueCreateUInt64(context->readUInt64(context, NULL)); break; case DATA_TYPE_FLOAT: value = valueCreateFloat(context->readFloat(context, NULL)); break; case DATA_TYPE_DOUBLE: value = valueCreateDouble(context->readDouble(context, NULL)); break; case DATA_TYPE_FIXED_16_16: value = valueCreateFixed16_16(context->readFixed16_16(context, NULL)); break; case DATA_TYPE_STRING: value = valueCreateString(context->readString(context, NULL), DATA_USE_STRLEN, true, true); break; case DATA_TYPE_BLOB: blob = context->readBlob(context, NULL, &length); if (context->status != SERIALIZATION_ERROR_OK) { return; } value = valueCreateBlob(blob, length, true, true); break; case DATA_TYPE_ARRAY: value.type = DATA_TYPE_ARRAY; value.value.array = arrayCreate(); deserializeContainer(&value, context); break; case DATA_TYPE_HASH_TABLE: value.type = DATA_TYPE_HASH_TABLE; value.value.hashTable = hashCreate(); deserializeContainer(&value, context); break; case DATA_TYPE_ASSOCIATIVE_ARRAY: value.type = DATA_TYPE_ASSOCIATIVE_ARRAY; value.value.associativeArray = associativeArrayCreate(); deserializeContainer(&value, context); break; case DATA_TYPE_POINTER: break; } if (context->status != SERIALIZATION_ERROR_OK) { return; } switch (container->type) { case DATA_TYPE_ARRAY: arrayAppend(container->value.array, value); break; case DATA_TYPE_HASH_TABLE: hashSet(container->value.hashTable, key, value); break; case DATA_TYPE_ASSOCIATIVE_ARRAY: associativeArrayAppend(container->value.associativeArray, key, value); break; default: break; } } context->endArray(context); }
PBWT *pbwtMerge(const char **fnames, int nfiles) { pbwt_reader_t *reader = pbwt_reader_init(fnames, nfiles); int nhaps = 0, i; for (i=0; i<nfiles; i++) nhaps += reader->pbwt[i]->M; PBWT *out_pbwt = pbwtCreate(nhaps, 0); PbwtCursor *cursor = pbwtNakedCursorCreate(nhaps, 0); uchar *yseq = myalloc(nhaps, uchar); out_pbwt->yz = arrayCreate (1<<20, uchar) ; out_pbwt->sites = arrayReCreate(out_pbwt->sites, reader->pbwt[0]->N, Site); out_pbwt->chrom = strdup(reader->pbwt[0]->chrom); int pos, j; while ( (pos=pbwt_reader_next(reader, nfiles)) ) { // Merge only records shared by all files for (i=0; i<nfiles; i++) { PBWT *p = reader->pbwt[i]; Site *site = arrp(p->sites, reader->cpos[i], Site); // Both position and alleles must match. This requires that the records are sorted by alleles. if ( site->x!=pos ) break; char *als = dictName(variationDict, site->varD); if ( strcmp(als,reader->mals) ) break; } if ( i!=nfiles ) { // intersection: skip records which are not present in all files for (i=0; i<nfiles; i++) { PBWT *p = reader->pbwt[i]; Site *site = arrp(p->sites, reader->cpos[i], Site); if ( site->x!=pos ) continue; char *als = dictName(variationDict, site->varD); if ( strcmp(als,reader->mals) ) continue; PbwtCursor *c = reader->cursor[i]; reader->unpacked[i] += unpack3(arrp(p->yz,reader->unpacked[i],uchar), p->M, c->y, 0); pbwtCursorForwardsA(c); } continue; } // read and merge int ihap = 0; for (i=0; i<nfiles; i++) { PbwtCursor *c = reader->cursor[i]; PBWT *p = reader->pbwt[i]; Site *site = arrp(p->sites, reader->cpos[i], Site); reader->unpacked[i] += unpack3(arrp(p->yz,reader->unpacked[i],uchar), p->M, c->y, 0); for (j=0; j<p->M; j++) yseq[ihap + c->a[j]] = c->y[j]; pbwtCursorForwardsA(c); ihap += p->M; } // pack merged haplotypes for (j=0; j<nhaps; j++) cursor->y[j] = yseq[cursor->a[j]]; pack3arrayAdd(cursor->y, out_pbwt->M, out_pbwt->yz); pbwtCursorForwardsA(cursor); // insert new site arrayExtend(out_pbwt->sites, out_pbwt->N+1); Site *site = arrayp(out_pbwt->sites, out_pbwt->N, Site); site->x = pos; dictAdd(variationDict, reader->mals, &site->varD); out_pbwt->N++; } pbwtCursorToAFend (cursor, out_pbwt) ; free(yseq); pbwtCursorDestroy(cursor); pbwt_reader_destroy(reader); return out_pbwt; }
int callRamcloud(struct conn *c, void *arg) { enum memcacheCommand command = getMemcacheCommand(c->protocol_data); struct RejectRules rule; struct ramcloudData *d = c->app_private_data; int owner = c->client->owner; uint64_t table_id; ASSERT(owner); if (getTableId(owner, &table_id) < 0) { sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); sendMemcacheResponse(c, &d->storage_response); return WHEAT_OK; } d->table_id = table_id; memset(&rule, 0, sizeof(rule)); switch (command) { case REQ_MC_GET: case REQ_MC_GETS: d->retrievals = arrayCreate(sizeof(wstr), 1); d->retrievals_keys = arrayCreate(sizeof(struct slice), 1); d->retrievals_vals = arrayCreate(sizeof(struct slice), 1); d->retrievals_flags = arrayCreate(FLAG_SIZE, 1); d->retrievals_versions = arrayCreate(sizeof(uint64_t), 1); arrayEach2(getMemcacheKeys(c->protocol_data), ramcloudRead, d); buildRetrievalResponse(d, command == REQ_MC_GETS ? 1 : 0); sliceTo(&d->storage_response, (uint8_t*)d->retrieval_response, wstrlen(d->retrieval_response)); break; case REQ_MC_DELETE: rule.doesntExist = 1; ramcloudDelete(d, getMemcacheKey(c->protocol_data), &rule); break; case REQ_MC_ADD: rule.exists = 1; ramcloudSet(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), &rule); break; case REQ_MC_REPLACE: rule.doesntExist = 1; ramcloudSet(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), &rule); break; case REQ_MC_CAS: rule.givenVersion = getMemcacheCas(c->protocol_data); rule.versionNeGiven = 1; rule.doesntExist = 1; ramcloudSet(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), &rule); break; case REQ_MC_SET: ramcloudSet(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), &rule); break; case REQ_MC_INCR: ramcloudIncr(d, getMemcacheKey(c->protocol_data), getMemcacheNum(c->protocol_data), 1); break; case REQ_MC_DECR: ramcloudIncr(d, getMemcacheKey(c->protocol_data), getMemcacheNum(c->protocol_data), 0); break; case REQ_MC_APPEND: ramcloudAppend(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), 1); break; case REQ_MC_PREPEND: ramcloudAppend(d, getMemcacheKey(c->protocol_data), getMemcacheVal(c->protocol_data), getMemcacheValLen(c->protocol_data), getMemcacheFlag(c->protocol_data), 0); break; default: ASSERT(0); } sendMemcacheResponse(c, &d->storage_response); return WHEAT_OK; }
int main (int argc, char *argv[]) { GfrEntry *currGE; BLEntry *currBLE; BLEntry currQuery; FILE *fp; char *line; int count; int countRemoved; int index; WordIter w; Array blackList = arrayCreate(20, BLEntry); if (argc != 2) { usage ("%s <blackList.txt>",argv[0]); } fp = fopen( argv[1], "r" ); if( !fp ) die("Unable to open file: %s", argv[1]); // reading blacklist file LineStream ls = ls_createFromFile( argv[1] ); while( line = ls_nextLine(ls) ) { w = wordIterCreate( line, "\t", 1); currBLE = arrayp( blackList, arrayMax(blackList), BLEntry); currBLE->gene1 = hlr_strdup ( wordNext(w) ); currBLE->gene2 = hlr_strdup ( wordNext(w) ); wordIterDestroy(w); } fclose(fp); arraySort( blackList, (ARRAYORDERF) sortBlackListByName1); // beginFiltering count = 0; countRemoved = 0; gfr_init ("-"); puts (gfr_writeHeader ()); while (currGE = gfr_nextEntry ()) { // reading the gfr // creating a new query to the black list currQuery.gene1 = currGE->geneSymbolTranscript1; currQuery.gene2 = currGE->geneSymbolTranscript2; // searching against read_1/read_2 int res = arrayFind( blackList, &currQuery, &index, (ARRAYORDERF) sortBlackListByName1); if( !res ) { // not found, then searching against read_2/read_1 currQuery.gene1 = currGE->geneSymbolTranscript2; currQuery.gene2 = currGE->geneSymbolTranscript1; res = arrayFind( blackList, &currQuery, &index, (ARRAYORDERF) sortBlackListByName1 ); if( !res ) { // not found, write the instance to stdout, update the counts puts (gfr_writeGfrEntry (currGE)); count++; } else { // found: read2/read1 countRemoved++; } } else { //found: read1/read2 countRemoved++; } } gfr_deInit (); arrayDestroy( blackList ); warn ("%s_BlackListFilter: %s",argv[0], argv[1]); warn ("%s_numRemoved: %d",argv[0],countRemoved); warn ("%s_numGfrEntries: %d",argv[0],count); return 0; }
int main (int argc, char *argv[]) { GfrEntry *currGE; BLEntry *currBLE; BLEntry currQuery; FILE *fp; char *line; int count; int countRemoved; int index; WordIter w; Array blackList = arrayCreate(20, BLEntry); config *Conf; if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL) { die("%s:\tCannot find .fusionseqrc: %s", argv[0], getenv("FUSIONSEQ_CONFPATH")); return EXIT_FAILURE; } if( confp_get( Conf, "ANNOTATION_DIR")==NULL ) { die("%s:\tCannot find ANNOTATION_DIR in the configuration file: %s)", argv[0], getenv("FUSIONSEQ_CONFPATH") ); return EXIT_FAILURE; } if( confp_get( Conf, "BLACKLIST_FILENAME")==NULL ) { die("%s:\tCannot find BLACKLIST_FILENAME in the configuration file: %s)", argv[0], getenv("FUSIONSEQ_CONFPATH") ); return EXIT_FAILURE; } Stringa buffer=stringCreate( 100 ); stringPrintf( buffer, "%s/%s", confp_get( Conf, "ANNOTATION_DIR"), confp_get( Conf, "BLACKLIST_FILENAME") ); /* fp = fopen( string( buffer ), "r" ); if( !fp ) die("Unable to open file: %s", string(buffer)); stringDestroy( buffer ); */ // reading blacklist file LineStream ls = ls_createFromFile( string(buffer) ); while( line = ls_nextLine(ls) ) { w = wordIterCreate( line, "\t", 1); currBLE = arrayp( blackList, arrayMax(blackList), BLEntry); currBLE->gene1 = hlr_strdup ( wordNext(w) ); currBLE->gene2 = hlr_strdup ( wordNext(w) ); wordIterDestroy(w); } //fclose(fp); ls_destroy( ls ); stringDestroy( buffer ); arraySort( blackList, (ARRAYORDERF) sortBlackListByName1); // beginFiltering count = 0; countRemoved = 0; gfr_init ("-"); puts (gfr_writeHeader ()); while (currGE = gfr_nextEntry ()) { // reading the gfr if( currGE->geneSymbolTranscript1 == NULL ) { die("Gene symbols are not present in the GFR file. Please run gfrAddInfo before gfrBlackListFilter."); return EXIT_FAILURE; } // creating a new query to the black list currQuery.gene1 = currGE->geneSymbolTranscript1; currQuery.gene2 = currGE->geneSymbolTranscript2; if( strEqual( currQuery.gene1 , currQuery.gene2 ) ) { countRemoved++; continue; } // searching against read_1/read_2 int res = arrayFind( blackList, &currQuery, &index, (ARRAYORDERF) sortBlackListByName1); if( !res ) { // not found, then searching against read_2/read_1 currQuery.gene1 = currGE->geneSymbolTranscript2; currQuery.gene2 = currGE->geneSymbolTranscript1; res = arrayFind( blackList, &currQuery, &index, (ARRAYORDERF) sortBlackListByName1 ); if( !res ) { // not found, write the instance to stdout, update the counts puts (gfr_writeGfrEntry (currGE)); count++; } else { // found: read2/read1 countRemoved++; } } else { //found: read1/read2 countRemoved++; } } gfr_deInit (); arrayDestroy( blackList ); warn ("%s_BlackListFilter: %s",argv[0], confp_get( Conf, "BLACKLIST_FILENAME")); warn ("%s_numRemoved: %d",argv[0],countRemoved); warn ("%s_numGfrEntries: %d",argv[0],count); confp_close( Conf); return 0; }
SEXP c_read_biokit_exprs (SEXP filename) { LineStream ls; char* line; const int MAND_NCOL=7; // the first column is the row name, and column 2-7 are mandatory int add_ncol=0; Texta it; Texta rnames=textCreate(128); Array mrpkms=arrayCreate(128, double); Array mreads=arrayCreate(128, int); Array srpkms=arrayCreate(128, double); Array sreads=arrayCreate(128, int); Array mprop=arrayCreate(128, double); Array allmap = arrayCreate(128, int); Array annos=arrayCreate(128, Texta); Texta anno=NULL; // must have a NULL assigned; otherwise textCreateClear leads to memory error Stringa str=stringCreate(8); SEXP R_rnames, R_mrpkms, R_mreads, R_srpkms, R_sreads, R_mprop, R_allmap, R_res; SEXP R_colnames, R_class; int nprot=0; int i=0; int j=0; int nrow=0; const char* fn=CHAR(STRING_ELT(filename, 0)); ls = ls_createFromFile(strdup(fn)); ls_nextLine(ls); // skip the first header line while(line = ls_nextLine(ls)) { it = textFieldtokP(line, "\t"); if(arrayMax(it)<MAND_NCOL) error("Input file must contain no less than %d columns", MAND_NCOL); textAdd(rnames, textItem(it, 0)); array(mrpkms, arrayMax(mrpkms), double)=atof(textItem(it, 1)); array(mreads, arrayMax(mreads), int)=atoi(textItem(it, 2)); array(srpkms, arrayMax(srpkms), double)=atof(textItem(it, 3)); array(sreads, arrayMax(sreads), int)=atoi(textItem(it, 4)); array(mprop, arrayMax(mprop), double)=atof(textItem(it, 5)); array(allmap, arrayMax(allmap), int)=atoi(textItem(it, 6)); add_ncol = max(arrayMax(it)-MAND_NCOL, add_ncol); textCreateClear(anno, arrayMax(it)-MAND_NCOL); for(i=MAND_NCOL; i<arrayMax(it); ++i) { textAdd(anno, textItem(it, i)); } array(annos, arrayMax(annos), Texta)=textClone(anno); nrow++; } R_rnames=PROTECT(allocVector(STRSXP, nrow)); nprot++; R_mrpkms=PROTECT(allocVector(REALSXP, nrow)); nprot++; R_mreads=PROTECT(allocVector(INTSXP, nrow)); nprot++; R_srpkms=PROTECT(allocVector(REALSXP, nrow)); nprot++; R_sreads=PROTECT(allocVector(INTSXP, nrow)); nprot++; R_mprop=PROTECT(allocVector(REALSXP, nrow)); nprot++; R_allmap=PROTECT(allocVector(INTSXP, nrow)); nprot++; for(i=0; i<nrow; ++i) { SET_STRING_ELT(R_rnames, i, mkChar(textItem(rnames, i))); REAL(R_mrpkms)[i]=arru(mrpkms, i, double); INTEGER(R_mreads)[i]=arru(mreads, i, int); REAL(R_srpkms)[i]=arru(srpkms, i, double); INTEGER(R_sreads)[i]=arru(sreads, i, int); REAL(R_mprop)[i]=arru(mprop, i, double); INTEGER(R_allmap)[i]=arru(allmap, i, int); } R_res=PROTECT(allocVector(VECSXP, MAND_NCOL+add_ncol-1)); nprot++; SET_VECTOR_ELT(R_res, 0, R_mrpkms); SET_VECTOR_ELT(R_res, 1, R_mreads); SET_VECTOR_ELT(R_res, 2, R_srpkms); SET_VECTOR_ELT(R_res, 3, R_sreads); SET_VECTOR_ELT(R_res, 4, R_mprop); SET_VECTOR_ELT(R_res, 5, R_allmap); for(i=0; i<add_ncol; ++i) { SEXP R_anno=NULL; R_anno=PROTECT(allocVector(STRSXP, nrow)); for(j=0; j<nrow; ++j) { anno=array(annos, j, Texta); if(arrayMax(anno)>i) { SET_STRING_ELT(R_anno, j, mkChar(textItem(anno, i))); } else { SET_STRING_ELT(R_anno, j, R_NaString); } } SET_VECTOR_ELT(R_res, i+MAND_NCOL-1, R_anno); // -1 because the first column is row name UNPROTECT(1); } PROTECT(R_colnames=allocVector(STRSXP, MAND_NCOL+add_ncol-1)); nprot++; PROTECT(R_class=allocVector(STRSXP, 1)); nprot++; SET_STRING_ELT(R_colnames, 0, mkChar("RPKM_MultiMap")); SET_STRING_ELT(R_colnames, 1, mkChar("ReadCount_MultiMap")); SET_STRING_ELT(R_colnames, 2, mkChar("RPKM_UniqMap")); SET_STRING_ELT(R_colnames, 3, mkChar("ReadCount_UniqMap")); SET_STRING_ELT(R_colnames, 4, mkChar("MultiProp")); SET_STRING_ELT(R_colnames, 5, mkChar("AllMappingReads")); for(i=0; i<add_ncol; ++i) { stringPrintf(str, "Annotation%d", i+1); SET_STRING_ELT(R_colnames, i+MAND_NCOL-1, mkChar(string(str))); } SET_STRING_ELT(R_class, 0, mkChar("data.frame")); setAttrib(R_res, install("names"), R_colnames); setAttrib(R_res, install("row.names"), R_rnames); setAttrib(R_res, install("class"), R_class); for(i=0; i<nrow; ++i) { textDestroy(array(annos, i, Texta)); } arrayDestroy(annos); arrayDestroy(rnames); arrayDestroy(mrpkms); arrayDestroy(mreads); arrayDestroy(srpkms); arrayDestroy(sreads); arrayDestroy(mprop); arrayDestroy(allmap); stringDestroy(str); ls_destroy(ls); UNPROTECT(nprot); return(R_res); }
int main (int argc, char *argv[]) { Array intervals; Interval *currInterval; SubInterval *currSubInterval; int h,i,j; Array seqs; Seq *currSeq,testSeq; int index; Stringa buffer; Array geneTranscriptEntries; Texta geneTranscriptIds; Array alterations; Alteration *currAlteration,*nextAlteration; char *proteinSequenceBeforeIndel; char *proteinSequenceAfterIndel; int numDisabledTranscripts; Stringa disabledTranscripts; int seqLength,refLength,altLength; char *sequenceBeforeIndel = NULL; int overlapMode; int numOverlaps; int sizeIndel,indelOffset; int overlap; Array coordinates; VcfEntry *currVcfEntry; VcfGenotype *currVcfGenotype; int position; Texta alternateAlleles; int flag1,flag2; if (argc != 3) { usage ("%s <annotation.interval> <annotation.fa>",argv[0]); } intervalFind_addIntervalsToSearchSpace (argv[1],0); geneTranscriptEntries = util_getGeneTranscriptEntries (intervalFind_getAllIntervals ()); seq_init (); fasta_initFromFile (argv[2]); seqs = fasta_readAllSequences (0); fasta_deInit (); arraySort (seqs,(ARRAYORDERF)util_sortSequencesByName); buffer = stringCreate (100); disabledTranscripts = stringCreate (100); alterations = arrayCreate (100,Alteration); vcf_init ("-"); stringPrintf (buffer,"##INFO=<ID=VA,Number=.,Type=String,Description=\"Variant Annotation, %s\">",argv[1]); vcf_addComment (string (buffer)); puts (vcf_writeMetaData ()); puts (vcf_writeColumnHeaders ()); while (currVcfEntry = vcf_nextEntry ()) { if (vcf_isInvalidEntry (currVcfEntry)) { continue; } flag1 = 0; flag2 = 0; position = currVcfEntry->position - 1; // make zero-based alternateAlleles = vcf_getAlternateAlleles (currVcfEntry); for (h = 0; h < arrayMax (alternateAlleles); h++) { refLength = strlen (currVcfEntry->referenceAllele); altLength = strlen (textItem (alternateAlleles,h)); sizeIndel = abs (refLength - altLength); indelOffset = MAX (refLength,altLength) - 1; util_clearAlterations (alterations); intervals = intervalFind_getOverlappingIntervals (currVcfEntry->chromosome,position,position + indelOffset); for (i = 0; i < arrayMax (intervals); i++) { currInterval = arru (intervals,i,Interval*); overlapMode = OVERLAP_NONE; numOverlaps = 0; for (j = 0; j < arrayMax (currInterval->subIntervals); j++) { currSubInterval = arrp (currInterval->subIntervals,j,SubInterval); overlap = rangeIntersection (position,position + indelOffset,currSubInterval->start,currSubInterval->end); if (currSubInterval->start <= position && (position + indelOffset) < currSubInterval->end) { overlapMode = OVERLAP_FULLY_CONTAINED; numOverlaps++; } else if (j == 0 && overlap > 0 && position < currSubInterval->start) { overlapMode = OVERLAP_START; numOverlaps++; } else if (j == (arrayMax (currInterval->subIntervals) - 1) && overlap > 0 && (position + indelOffset) >= currSubInterval->end) { overlapMode = OVERLAP_END; numOverlaps++; } else if (overlap > 0 && overlap <= indelOffset) { overlapMode = OVERLAP_SPLICE; numOverlaps++; } } if (overlapMode == OVERLAP_NONE) { continue; } currAlteration = arrayp (alterations,arrayMax (alterations),Alteration); if (numOverlaps > 1) { util_addAlteration (currAlteration,currInterval->name,"multiExonHit",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_SPLICE) { util_addAlteration (currAlteration,currInterval->name,"spliceOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_START) { util_addAlteration (currAlteration,currInterval->name,"startOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_END) { util_addAlteration (currAlteration,currInterval->name,"endOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength > refLength) { if ((sizeIndel % 3) == 0) { util_addAlteration (currAlteration,currInterval->name,"insertionNFS",currInterval,position,0); } else { util_addAlteration (currAlteration,currInterval->name,"insertionFS",currInterval,position,0); } } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength < refLength) { if ((sizeIndel % 3) == 0) { util_addAlteration (currAlteration,currInterval->name,"deletionNFS",currInterval,position,0); } else { util_addAlteration (currAlteration,currInterval->name,"deletionFS",currInterval,position,0); } } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength == refLength) { util_addAlteration (currAlteration,currInterval->name,"substitution",currInterval,position,0); } else { die ("Unexpected type: %d %s %s %s", currVcfEntry->position,currVcfEntry->chromosome, currVcfEntry->referenceAllele,currVcfEntry->alternateAllele); } if ((sizeIndel % 3) != 0 && altLength != refLength) { continue; } // Only run the remaining block of code if the indel is fully contained (insertion or deletion) AND does not cause a frameshift OR // if it is a substitution that is fully contained in the coding sequence stringPrintf (buffer,"%s|%s|%c|",currInterval->name,currInterval->chromosome,currInterval->strand); for (j = 0; j < arrayMax (currInterval->subIntervals); j++) { currSubInterval = arrp (currInterval->subIntervals,j,SubInterval); stringAppendf (buffer,"%d|%d%s",currSubInterval->start,currSubInterval->end,j < arrayMax (currInterval->subIntervals) - 1 ? "|" : ""); } testSeq.name = hlr_strdup (string (buffer)); if (!arrayFind (seqs,&testSeq,&index,(ARRAYORDERF)util_sortSequencesByName)) { die ("Expected to find %s in seqs",string (buffer)); } hlr_free (testSeq.name); currSeq = arrp (seqs,index,Seq); strReplace (&sequenceBeforeIndel,currSeq->sequence); seqLength = strlen (sequenceBeforeIndel); coordinates = util_getCoordinates (currInterval); // arraySort (coordinates,(ARRAYORDERF)util_sortCoordinatesByChromosomeAndTranscriptPosition); Array is already sorted by definition j = 0; stringClear (buffer); while (j < seqLength) { if (util_getGenomicCoordinate (coordinates,j,currVcfEntry->chromosome) == position) { if (altLength > refLength) { stringCat (buffer,textItem (alternateAlleles,h)); j++; continue; } else if (altLength < refLength) { stringCatChar (buffer,sequenceBeforeIndel[j]); j = j + refLength - altLength + 1; continue; } else { stringCat (buffer,textItem (alternateAlleles,h)); j = j + altLength; continue; } } stringCatChar (buffer,sequenceBeforeIndel[j]); j++; } util_destroyCoordinates (coordinates); proteinSequenceBeforeIndel = hlr_strdup (util_translate (currInterval,sequenceBeforeIndel)); proteinSequenceAfterIndel = hlr_strdup (util_translate (currInterval,string (buffer))); addSubstitution (currAlteration,proteinSequenceBeforeIndel,proteinSequenceAfterIndel,indelOffset); hlr_free (proteinSequenceBeforeIndel); hlr_free (proteinSequenceAfterIndel); } if (arrayMax (alterations) == 0) { continue; } arraySort (alterations,(ARRAYORDERF)util_sortAlterationsByGeneIdAndType); stringClear (buffer); i = 0; while (i < arrayMax (alterations)) { currAlteration = arrp (alterations,i,Alteration); stringAppendf (buffer,"%s%d:%s:%s:%c:%s",stringLen (buffer) == 0 ? "" : ",",h + 1,currAlteration->geneName,currAlteration->geneId,currAlteration->strand,currAlteration->type); stringClear (disabledTranscripts); if (currAlteration->substitution[0] != '\0') { stringAppendf (disabledTranscripts,"%s:%s:%d_%d_%s",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition,currAlteration->substitution); } else if (strEqual (currAlteration->type,"multiExonHit") || strEqual (currAlteration->type,"spliceOverlap") || strEqual (currAlteration->type,"startOverlap") || strEqual (currAlteration->type,"endOverlap")) { stringAppendf (disabledTranscripts,"%s:%s:%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength); } else { stringAppendf (disabledTranscripts,"%s:%s:%d_%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition); } numDisabledTranscripts = 1; j = i + 1; while (j < arrayMax (alterations)) { nextAlteration = arrp (alterations,j,Alteration); if (strEqual (currAlteration->geneId,nextAlteration->geneId) && strEqual (currAlteration->type,nextAlteration->type)) { if (nextAlteration->substitution[0] != '\0') { stringAppendf (disabledTranscripts,":%s:%s:%d_%d_%s",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition,nextAlteration->substitution); } else if (strEqual (nextAlteration->type,"multiExonHit") || strEqual (nextAlteration->type,"spliceOverlap") || strEqual (nextAlteration->type,"startOverlap") || strEqual (nextAlteration->type,"endOverlap")) { stringAppendf (disabledTranscripts,":%s:%s:%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength); } else { stringAppendf (disabledTranscripts,":%s:%s:%d_%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition); } numDisabledTranscripts++; } else { break; } j++; } i = j; geneTranscriptIds = util_getTranscriptIdsForGeneId (geneTranscriptEntries,currAlteration->geneId); stringAppendf (buffer,":%d/%d:%s",numDisabledTranscripts,arrayMax (geneTranscriptIds),string (disabledTranscripts)); } if (flag1 == 0) { printf ("%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s;VA=", currVcfEntry->chromosome,currVcfEntry->position,currVcfEntry->id, currVcfEntry->referenceAllele,currVcfEntry->alternateAllele, currVcfEntry->quality,currVcfEntry->filter,currVcfEntry->info); flag1 = 1; } printf ("%s%s",flag2 == 1 ? "," : "",string (buffer)); flag2 = 1; } if (flag1 == 1) { for (i = 0; i < arrayMax (currVcfEntry->genotypes); i++) { currVcfGenotype = arrp (currVcfEntry->genotypes,i,VcfGenotype); if (i == 0) { printf ("\t%s\t",currVcfEntry->genotypeFormat); } printf ("%s%s%s%s",currVcfGenotype->genotype, currVcfGenotype->details[0] != '\0' ? ":" : "", currVcfGenotype->details[0] != '\0' ? currVcfGenotype->details : "", i < arrayMax (currVcfEntry->genotypes) - 1 ? "\t" : ""); } puts (""); } } vcf_deInit (); return 0; }