void Sound::bgPlay(const char *base, const char *ext, SoundType type, int count) { if (!_bgatmos) return; debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\" (%d)", base, count); _bgatmos->stopBA(); _bgatmos->queueClear(); int length = strlen(base) + 7; char *fileName = new char[length]; SoundDesc *sndDesc; for (int i = 1; i <= count; i++) { snprintf(fileName, length, "%s%02d.%s", base, i, ext); sndDesc = new SoundDesc; if (sampleLoad(sndDesc, type, fileName)) _bgatmos->queueSample(*sndDesc); else delete sndDesc; } _bgatmos->playBA(); }
float aveSScoreForRegion(char *db, char *chrom, int chromStart, int chromEnd) { float currentSum = 0; int count = 0; float ave = 0; int sPos = 0; struct sample *sList=NULL, *s = NULL; char *tableName = optionVal("sampleTable", "hg15Mm3L"); struct sqlConnection *conn = hAllocConn(db); struct sqlResult *sr=NULL; char **row; char buff[256]; int rowOffset=0; safef(buff,sizeof(buff),"%s_%s",chrom, tableName); if(hTableExists(db, buff)) { sr = hRangeQuery(conn, tableName, chrom, chromStart, chromEnd, NULL, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { s = sampleLoad(row + rowOffset); slAddHead(&sList, s); } for(s = sList; s != NULL; s = s->next) { int i=0; for(i=0; i<s->sampleCount; i++) { sPos = s->chromStart + s->samplePosition[i]; if(sPos >= chromStart && sPos <= chromEnd) { currentSum += ((float) s->sampleHeight[i]) / 1000 * 8.0; count++; } } } sqlFreeResult(&sr); slFreeList(&sList); } hFreeConn(&conn); if(count > 0) ave = currentSum / count; else ave = -1; return ave; }
void Sound::bgPlay(const char *file, SoundType type) { if (!_bgatmos) return; debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\"", file); _bgatmos->stopBA(); _bgatmos->queueClear(); SoundDesc *sndDesc = new SoundDesc; if (!sampleLoad(sndDesc, type, file)) { delete sndDesc; return; } _bgatmos->queueSample(*sndDesc); _bgatmos->playBA(); }
void Sound::bgPlay(const char *base, const char *ext, SoundType type, int count) { if (!_bgatmos) return; debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\" (%d)", base, count); _bgatmos->stopBA(); _bgatmos->queueClear(); SoundDesc *sndDesc; for (int i = 1; i <= count; i++) { Common::String fileName = Common::String::format("%s%02d.%s", base, i, ext); sndDesc = new SoundDesc; if (sampleLoad(sndDesc, type, fileName.c_str())) _bgatmos->queueSample(*sndDesc); else delete sndDesc; } _bgatmos->playBA(); }
void loadAffyTranscriptome(struct track *tg) /* Convert sample info in window to linked feature. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; int rowOffset; struct sample *sample; struct linkedFeatures *lfList = NULL, *lf; char *hasDense = NULL; char *where = NULL; char query[256]; char tableName[256]; int zoom1 = 23924, zoom2 = 2991; /* bp per data point */ float pixPerBase = 0; /* Set it up so we don't have linear interpretation.. */ char *noLinearInterpString = wiggleEnumToString(wiggleNoInterpolation); cartSetString(cart, "affyTranscriptome.linear.interp", noLinearInterpString); if(tl.picWidth == 0) errAbort("hgTracks.c::loadAffyTranscriptome() - can't have pixel width of 0"); pixPerBase = (winEnd - winStart)/ tl.picWidth; /* Determine zoom level. */ if(pixPerBase >= zoom1) safef(tableName, sizeof(tableName), "%s_%s", "zoom1", tg->table); else if(pixPerBase >= zoom2) safef(tableName, sizeof(tableName), "%s_%s", "zoom2", tg->table); else safef(tableName, sizeof(tableName), "%s", tg->table); /*see if we have a summary table*/ if(hTableExists(database, tableName)) safef(query, sizeof(query), "select name from %s where name = '%s' limit 1", tableName, tg->shortLabel); else { warn("<p>Couldn't find table %s<br><br>", tableName); safef(query, sizeof(query), "select name from %s where name = '%s' limit 1", tg->table, tg->shortLabel); safef(tableName, sizeof(tableName), "%s", tg->table); } hasDense = sqlQuickQuery(conn, query, query, sizeof(query)); /* If we're in dense mode and have a summary table load it. */ if(tg->visibility == tvDense) { if(hasDense != NULL) { safef(query, sizeof(query), " name = '%s' ", tg->shortLabel); where = cloneString(query); } } sr = hRangeQuery(conn, tableName, chromName, winStart, winEnd, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { sample = sampleLoad(row+rowOffset); lf = lfFromSample(sample); slAddHead(&lfList, lf); sampleFree(&sample); } if(where != NULL) freez(&where); sqlFreeResult(&sr); hFreeConn(&conn); slReverse(&lfList); /* sort to bring items with common names to the same line but only for tracks with a summary table (with name=shortLabel) in dense mode*/ if( hasDense != NULL ) { sortGroupList = tg; /* used to put track name at top of sorted list. */ slSort(&lfList, lfNamePositionCmp); sortGroupList = NULL; } tg->items = lfList; }
void loadSampleZoo(struct track *tg) /* Convert sample info in window to linked feature. */ { int maxWiggleTrackHeight = 2500; struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; int rowOffset; struct sample *sample; struct linkedFeatures *lfList = NULL, *lf; char *hasDense = NULL; char *where = NULL; char query[256]; char option[64]; zooSpeciesHashInit(); /*see if we have a summary table*/ safef(query, sizeof(query), "select name from %s where name = '%s' limit 1", tg->table, tg->shortLabel); //errAbort( "%s", query ); hasDense = sqlQuickQuery(conn, query, query, sizeof(query)); /* If we're in dense mode and have a summary table load it. */ if(tg->visibility == tvDense) { if(hasDense != NULL) { safef(query, sizeof(query), " name = '%s' ", tg->shortLabel); where = cloneString(query); } } sr = hRangeQuery(conn, tg->table, chromName, winStart, winEnd, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { sample = sampleLoad(row + rowOffset); lf = lfFromSample(sample); safef( option, sizeof(option), "zooSpecies.%s", sample->name ); if( cartUsualBoolean(cart, option, TRUE )) slAddHead(&lfList, lf); sampleFree(&sample); } if(where != NULL) freez(&where); sqlFreeResult(&sr); hFreeConn(&conn); slReverse(&lfList); /* sort to bring items with common names to the same line * but only for tracks with a summary table * (with name=shortLabel) in dense mode */ if( hasDense != NULL ) { sortGroupList = tg; /* used to put track name at top of sorted list. */ slSort(&lfList, lfNamePositionCmp); sortGroupList = NULL; } /* Sort in species phylogenetic order */ slSort(&lfList, lfZooCmp); tg->items = lfList; /*turn off full mode if there are too many rows or each row is too * large. A total of maxWiggleTrackHeight is allowed for number of * rows times the rowHeight*/ if( tg->visibility == tvFull && sampleTotalHeight( tg, tvFull ) > maxWiggleTrackHeight ) { tg->limitedVisSet = TRUE; tg->limitedVis = tvDense; } }
void loadHumMusL(struct track *tg) /* Load humMusL track with 2 zoom levels and one normal level. * Also used for loading the musHumL track (called Human Cons) * on the mouse browser. It decides which of 4 tables to * load based on how large of a window the user is looking at*/ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; int rowOffset; struct sample *sample; struct linkedFeatures *lfList = NULL, *lf; char *hasDense = NULL; char *where = NULL; char tableName[256]; int z; float pixPerBase = 0; if(tl.picWidth == 0) errAbort("hgTracks.c::loadHumMusL() - can't have pixel width of 0"); pixPerBase = (winEnd - winStart)/ tl.picWidth; /* Determine zoom level. */ if (!strstr(tg->table,"HMRConservation")) z = humMusZoomLevel(); else z=0; if(z == 1 ) safef(tableName, sizeof(tableName), "%s_%s", "zoom1", tg->table); else if( z == 2) safef(tableName, sizeof(tableName), "%s_%s", "zoom50", tg->table); else if(z == 3) safef(tableName, sizeof(tableName), "%s_%s", "zoom2500", tg->table); else safef(tableName, sizeof(tableName), "%s", tg->table); //printf("(%s)", tableName ); sr = hRangeQuery(conn, tableName, chromName, winStart, winEnd, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { sample = sampleLoad(row+rowOffset); lf = lfFromSample(sample); slAddHead(&lfList, lf); sampleFree(&sample); } if(where != NULL) freez(&where); sqlFreeResult(&sr); hFreeConn(&conn); slReverse(&lfList); /* sort to bring items with common names to the same line but only for tracks with a summary table (with name=shortLabel) in dense mode*/ if( hasDense != NULL ) { sortGroupList = tg; /* used to put track name at * top of sorted list. */ slSort(&lfList, lfNamePositionCmp); sortGroupList = NULL; } tg->items = lfList; }
/* Main */ int main() { matrix MX; mnew(&MX, 200, 8); sampleLoad("data_200x8.txt", &MX); printf("data=\n"); mprint(&MX); double mean[2][8]= {{4.427227e-001, 7.671556e-001, -9.523772e-001, 3.867558e-001, -7.916976e-001, 1.165247e-001, -1.261666e-001, 8.550054e-002}, {-2.383899e-001, -4.130850e-001, 5.128200e-001, -2.082537e-001, 4.263000e-001, -6.274427e-002, 6.793605e-002, -4.603889e-002}}; matrix MUK; mnew(&MUK, 2, 8); MUK.pr = *mean; matrix *Var0; Var0 = new matrix[2]; for(int i=0; i<2; i++) { mnew(Var0+i, 8, 8); } sampleLoad("var0.txt", Var0); printf("var0=\n"); mprint(Var0); sampleLoad("var1.txt", Var0+1); printf("var1=\n"); mprint(Var0+1); double W[] = {3.500007e-001, 6.499993e-001}; vector w0; vnew(&w0, 2); w0.pr = W; matrix Gxn; mnew(&Gxn, 200, 2); vector Fx; vnew(&Fx, 200); veModel(&MX, &MUK, Var0, &w0, &Gxn, &Fx); printf("Gxn=\n"); mprint(&Gxn); printf("Fx=\n"); vprint(&Fx); matrix tmp; mnew(&tmp, 1, 8); matrix tmp2; mnew(&tmp2, 1, 1); matrix cen_Dj; mnew(&cen_Dj, 1, 8); matrix cen_Dj_t; mnew(&cen_Dj_t, 8, 1); for(i=0; i<8; i++) { *(cen_Dj.pr+i) = *(MX.pr+0+i) - *(MUK.pr+8+i); } transpose(&cen_Dj, &cen_Dj_t); printf("\ncen_Dj=\n"); mprint(&cen_Dj); mprint(&cen_Dj_t); matrix inv_Var1; mnew(&inv_Var1, 8, 8); sampleLoad("inv_var1.txt", &inv_Var1); mprint(&inv_Var1); mmMul(&cen_Dj, &inv_Var1, &tmp); printf("\ntmp=\n"); mprint(&tmp); mmMul(&tmp, &cen_Dj_t, &tmp2); printf("\ntmp2=\n"); mprint(&tmp2); double val = *(tmp2.pr); printf("\nval=%e\n", val); mdelete(&MX); mdelete(&MUK); mdelete(Var0); mdelete(Var0+1); vdelete(&w0); mdelete(&Gxn); vdelete(&Fx); return 0; }