void pbwtDestroy (PBWT *p) { if (p->chrom) free (p->chrom) ; if (p->sites) arrayDestroy (p->sites) ; if (p->samples) arrayDestroy (p->samples) ; if (p->yz) arrayDestroy (p->yz) ; if (p->zz) arrayDestroy (p->zz) ; if (p->aFstart) free (p->aFstart) ; if (p->aFend) free (p->aFend) ; if (p->aRstart) free (p->aRstart) ; if (p->aRend) free (p->aRend) ; free (p) ; }
int main (int argc, char *argv[]) { GfrEntry *currGE; int count; int countRemoved; int i; if (argc != 3) { usage ("%s <offsetCutoff> <minNumUniqueReads>",argv[0]); } count = 0; countRemoved = 0; int offsetCutOff = atoi (argv[1]); int minNumUniqueReads = atoi (argv[2]); gfr_init ("-"); puts (gfr_writeHeader ()); while (currGE = gfr_nextEntry ()) { Array starts = arrayCreate( 100, int); for (i = 0; i < arrayMax( currGE->interReads ); i++) { int currStart = arrp(currGE->interReads, i, GfrInterRead)->readStart1 + arrp(currGE->interReads, i, GfrInterRead)->readStart2; array(starts, arrayMax(starts), int) = currStart; } arraySort( starts, (ARRAYORDERF) arrayIntcmp ); arrayUniq( starts, NULL, (ARRAYORDERF) arrayIntcmp ) ; int numUniqeOffsets = arrayMax( starts ); arrayDestroy( starts ); if (arrayMax( currGE->readsTranscript1 ) != arrayMax( currGE->readsTranscript2 ) ) die( "The two ends have a different number of reads"); Texta reads = textCreate(arrayMax(currGE->readsTranscript1)); for (i = 0; i < arrayMax(currGE->readsTranscript1); i++) { Stringa strA = stringCreate( strlen(textItem( currGE->readsTranscript1, i) ) * 2 + 1); stringAppendf( strA, textItem( currGE->readsTranscript1,i)); stringAppendf( strA, textItem( currGE->readsTranscript2,i)); textAdd( reads, string(strA)); stringDestroy( strA ); } textUniqKeepOrder( reads ); int numRemaining = arrayMax( reads ); textDestroy ( reads ); if (numRemaining <= minNumUniqueReads || numUniqeOffsets <= offsetCutOff) { countRemoved++; continue; } puts (gfr_writeGfrEntry (currGE)); count++; } gfr_deInit (); warn("%s_PCRFilter: offset=%d minNumUniqueReads=%d", argv[0],offsetCutOff, minNumUniqueReads); warn("%s_numRemoved: %d",argv[0],countRemoved); warn("%s_numGfrEntries: %d",argv[0],count); return 0; }
void hashDestroy (HASH hx) { TRUE_HASH *h = (TRUE_HASH*) hx ; free (h->keys) ; free (h->values) ; arrayDestroy (h->freeList) ; free (h) ; ++nDestroyed ; }
int main (int argc, char *argv[]) { GfrEntry *currGE; int count; int countRemoved; int i, j; int foundEST; if (argc != 2) { usage ("%s <EST.interval>",argv[0]); } intervalFind_addIntervalsToSearchSpace( argv[1], 0); // beginFiltering count = 0; countRemoved = 0; gfr_init ("-"); puts (gfr_writeHeader ()); while (currGE = gfr_nextEntry ()) { // reading the gfr foundEST = 0; if( strEqual( currGE->fusionType, "cis" ) ) { if( ! strEqual( currGE->chromosomeTranscript1, currGE->chromosomeTranscript2 ) ) die("The two genes are not on the same chromosomes: %s - %s", currGE->chromosomeTranscript1, currGE->chromosomeTranscript2 ); int start1, end1, start2, end2; findCoordinates( currGE, &start1, &end1, &start2, &end2 ); Array intervals1 = arrayCopy( intervalFind_getOverlappingIntervals( currGE->chromosomeTranscript1, start1, end1 ) ); Array intervals2 = intervalFind_getOverlappingIntervals( currGE->chromosomeTranscript2, start2, end2 ); for( i=0; i<arrayMax( intervals1 ); i++ ) { Interval* currInterval1 = arru( intervals1, i, Interval* ); for( j=0; j<arrayMax ( intervals2 ); j++ ) { Interval* currInterval2 = arru( intervals2, j, Interval* ); if( currInterval1==currInterval2 ) { foundEST = 1; i = arrayMax( intervals1 ); j = arrayMax( intervals2 ); } } } arrayDestroy( intervals1 ); } if( foundEST ) countRemoved++; else { puts (gfr_writeGfrEntry (currGE)); count++; } } gfr_deInit (); warn ("%s_EST_data: %s",argv[0], argv[1]); warn ("%s_numRemoved: %d",argv[0], countRemoved); warn ("%s_numGfrEntries: %d",argv[0],count); return 0; }
/** * \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; }
void pbwtDestroy (PBWT *p) { if (p->chrom) free (p->chrom) ; if (p->sites) arrayDestroy (p->sites) ; if (p->samples) arrayDestroy (p->samples) ; if (p->yz) arrayDestroy (p->yz) ; if (p->zz) arrayDestroy (p->zz) ; if (p->aFstart) free (p->aFstart) ; if (p->aFend) free (p->aFend) ; if (p->aRstart) free (p->aRstart) ; if (p->aRend) free (p->aRend) ; if (p->missingOffset) arrayDestroy (p->missingOffset) ; if (p->zMissing) arrayDestroy (p->zMissing) ; if (p->dosageOffset) arrayDestroy (p->dosageOffset) ; if (p->zDosage) arrayDestroy (p->zDosage) ; free (p) ; }
static void blastParser_freeQuery (BlastQuery *currBlastQuery) { int i; BlastEntry *currBlastEntry; if (currBlastQuery == NULL) { return; } hlr_free (currBlastQuery->qName); for (i = 0; i < arrayMax (currBlastQuery->entries); i++) { currBlastEntry = arrp (currBlastQuery->entries,i,BlastEntry); hlr_free (currBlastEntry->tName); } arrayDestroy (currBlastQuery->entries); freeMem (currBlastQuery); }
static char* getBreakPointSequence (char *tileCoordinate1, char *tileCoordinate2) { Stringa buffer; Stringa targetsFile; FILE *fp; Array targetSeqs; int i; Seq *currSeq; static Stringa sequence = NULL; buffer = stringCreate (100); targetsFile = stringCreate (100); stringPrintf (targetsFile,"targets_%d.txt",getpid ()); if (!(fp = fopen (string (targetsFile),"w")) ){ die ("Unable to open target file: %s",string (targetsFile)); } fprintf (fp,"%s\n%s",tileCoordinate1,tileCoordinate2); fclose (fp); stringPrintf (buffer,"%s %s/%s stdout -noMask -seqList=%s", confp_get(Conf, "BLAT_TWO_BIT_TO_FA"), confp_get(Conf, "BLAT_DATA_DIR"), confp_get(Conf, "BLAT_TWO_BIT_DATA_FILENAME"), string (targetsFile)); fasta_initFromPipe (string (buffer)); targetSeqs = fasta_readAllSequences (0); fasta_deInit (); if (arrayMax (targetSeqs) != 2) { die ("Expected only two target sequences"); } stringCreateClear (sequence,100); for (i = 0; i < arrayMax (targetSeqs); i++) { currSeq = arrp (targetSeqs,i,Seq); stringAppendf (sequence,"%s",currSeq->sequence); hlr_free (currSeq->name); hlr_free (currSeq->sequence); } arrayDestroy (targetSeqs); stringPrintf (buffer,"rm -rf %s",string (targetsFile)); hlr_system (string (buffer),0); stringDestroy (targetsFile); stringDestroy (buffer); return string (sequence); }
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[]) { 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; }
void updateMagneticField(const RenderContext* context) { static const Vector minCellPosRel = { -48, -48, -48 }; static const Vector maxCellPosRel = { 48, 48, 48 }; static const int cellStep = 8; Vector minCellPos = vectorSum(context->camera.position, minCellPosRel); Vector maxCellPos = vectorSum(context->camera.position, maxCellPosRel); size_t i, count; // remove points which is too far from camera for (i = 0, count = arrayGetLength(_fieldPoints); i < count; ++i) { pthread_mutex_lock(&_fieldPointsMutex); VectorFieldPoint* point = (VectorFieldPoint*) arrayGetAt(_fieldPoints, i); if (point->position.x < minCellPos.x + minCellPosRel.x || point->position.x > maxCellPos.x + maxCellPosRel.x || point->position.y < minCellPos.y + minCellPosRel.y || point->position.y > maxCellPos.y + maxCellPosRel.y || point->position.z < minCellPos.z + minCellPosRel.z || point->position.z > maxCellPos.z + maxCellPosRel.z) { arrayDestroy(_fieldPoints, i); --i; --count; } pthread_mutex_unlock(&_fieldPointsMutex); } // compute points int x, y, z; for (x = (int) (minCellPos.x / cellStep) * cellStep; x <= maxCellPos.x; x += cellStep) { for (y = (int) (minCellPos.y / cellStep) * cellStep; y <= maxCellPos.y; y += cellStep) { for (z = (int) (minCellPos.z / cellStep) * cellStep; z <= maxCellPos.z; z += cellStep) { const Vector position = { x, y, z }; // try to find int pointExists = 0; for (i = 0, count = arrayGetLength(_fieldPoints); i < count; ++i) { pthread_mutex_lock(&_fieldPointsMutex); VectorFieldPoint* point = (VectorFieldPoint*) arrayGetAt(_fieldPoints, i); if (point->position.x >= x && point->position.x <= x + cellStep && point->position.y >= y && point->position.y <= y + cellStep && point->position.z >= z && point->position.z <= z + cellStep) { pointExists = 1; pthread_mutex_unlock(&_fieldPointsMutex); break; } pthread_mutex_unlock(&_fieldPointsMutex); } if (pointExists) { continue; } // compute if not exist VectorFieldPoint* result = (VectorFieldPoint*) malloc(sizeof(VectorFieldPoint)); result->position = position; result->direction = vectorZero; for (i = 0, count = arrayGetLength(_conductors); i < count; ++i) { Conductor* conductor = (Conductor*) arrayGetAt(_conductors, i); result->direction = vectorSum( result->direction, calculateMagneticFieldPoint(conductor->I, conductor->permeability, conductor->l, vectorSubstract(position, conductor->position)) ); } pthread_mutex_lock(&_fieldPointsMutex); arrayAppend(_fieldPoints, result); pthread_mutex_unlock(&_fieldPointsMutex); } } } }
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; }