Example #1
0
void avgTranscriptomeExps()
{
struct sample *s = NULL;
struct sample *s1,*s2,*s3;
struct sample *sList1, *sList2, *sList3 = NULL;
struct sample **sArray1, **sArray2, **sArray3 = NULL;
int i,j,k;
FILE *out = NULL;
for(i=1; i<12; i++)
    {
    for(j='a'; j<'d'; j++)
	{
	char buff[2048];
	int count;
	struct sample *avgList = NULL, *avg;
	if((i != 6 || j != 'a') || doAll)
	    {
	    snprintf(buff, sizeof(buff), "%d.%c.1.%s", i,j,suffix);
	    printf("Averaging %s\n", buff);
	    sList1 = sampleLoadAll(buff);
	    snprintf(buff, sizeof(buff), "%d.%c.2.%s", i,j,suffix);
	    sList2 = sampleLoadAll(buff);
	    snprintf(buff, sizeof(buff), "%d.%c.3.%s", i,j,suffix);
	    sList3 = sampleLoadAll(buff);
	    count = slCount(sList1);
	    AllocArray(sArray1,count);
	    AllocArray(sArray2,count);
	    AllocArray(sArray3,count);
	    for(k=0, s1=sList1, s2=sList2, s3=sList3; k<count; s1=s1->next,s2=s2->next,s3=s3->next, k++)
		{
		sArray1[k] = s1;
		sArray2[k] = s2;
		sArray3[k] = s3;
		}
	    for(k=0;k<count; k++)
		{
		avg = avgSamples(sArray1[k], sArray2[k], sArray3[k], i, k);
		slAddHead(&avgList, avg);
		}
	    slReverse(&avgList);
	    snprintf(buff, sizeof(buff), "%d.%c.1.%s.avg", i,j,suffix);
	    out = mustOpen(buff, "w");
	    for(s = avgList; s != NULL; s = s->next)
		sampleTabOut(s, out);
	    carefulClose(&out);
	    freez(&sArray1);
	    freez(&sArray2);
	    freez(&sArray3);
	    sampleFreeList(&avgList);
	    sampleFreeList(&sList1);
	    sampleFreeList(&sList2);
	    sampleFreeList(&sList3);
	    }
	}
    }
}
void maxTranscriptomeExps(char *files[], int numFiles, char *outputFile, char *trackName)
{
struct sample **pSampList = NULL;
struct sample *s1;
struct sample *maxListSamp  = NULL;
struct sample *maxSamp = NULL;
int i;
int count =0;
FILE *out = NULL;
AllocArray(pSampList, numFiles);
for(i=0;i<numFiles; i++)
 {
 warn("Reading %s.", files[i]);
 pSampList[i] = sampleLoadAll(files[i]);
 }

warn("Calculating Maxes.");
count = slCount(pSampList[0]);
for(i=0;i<count;i++)
    {
    AllocVar(maxSamp);
    s1 = slElementFromIx(pSampList[0], i);
    maxSamp->chrom = cloneString(s1->chrom);
    maxSamp->chromStart = s1->chromStart;
    maxSamp->chromEnd = s1->chromEnd;
    maxSamp->name = cloneString(trackName);
    snprintf(maxSamp->strand, sizeof(maxSamp->strand), "%s", s1->strand);
    maxSamp->sampleCount = s1->sampleCount;
    maxSamp->samplePosition = CloneArray(s1->samplePosition, maxSamp->sampleCount);
    AllocArray(maxSamp->sampleHeight, maxSamp->sampleCount);
    fillInMaxVals(maxSamp, pSampList, numFiles, i);
    slAddHead(&maxListSamp, maxSamp);
    }
slReverse(&maxListSamp);
warn("Saving Maxes");
out = mustOpen(outputFile, "w");
for(maxSamp = maxListSamp; maxSamp != NULL; maxSamp = maxSamp->next)
    {
    sampleTabOut(maxSamp, out);
    }
carefulClose(&out);
warn("Cleaning up");
sampleFreeList(&maxListSamp);
for(i=0;i<numFiles; i++)
    sampleFreeList(&pSampList[i]);
freez(&pSampList);
warn("Done.");
}
Example #3
0
void normalizeSampleFiles(int minVal, int maxVal, boolean doNorm, char *files[], int numFiles)
/* Top level function to do nomalization. */
{
float ave = 0;
int i = 0;
int numSamples = 0;
char buff[10*strlen(files[0])];
struct sample *sList = NULL, *s = NULL;
float normVal = 0;
FILE *out = NULL;
for(i=0; i<numFiles; i++)
    {
    float currentAve = 0;
    sList = sampleLoadAll(files[i]);
    numSamples = countGoodSamples(sList, minVal, maxVal);
    currentAve = calculateAverage(sList, minVal, maxVal, numSamples);
    printf("Average val for %s is %f\n", files[i], currentAve);
    sampleFreeList(&sList);
    ave += currentAve;
    }
ave = ave/numFiles;
printf("Global Average is: %f\n", ave);
if(doNorm)
    {
    printf("Normalizing files.");
    for(i=0; i<numFiles; i++)
	{
	float currentAve = 0;
	fprintf(stdout, ".");
	fflush(stdout);
	sList = sampleLoadAll(files[i]);
	numSamples = countGoodSamples(sList, minVal, maxVal);
	currentAve = calculateAverage(sList, minVal, maxVal, numSamples);
	normVal = currentAve/ave;
	normalizeSamples(sList, normVal);
	snprintf(buff, sizeof(buff), "%s.norm", files[i]);
	out = mustOpen(buff, "w");
	for(s=sList; s != NULL; s = s->next)
	    sampleTabOut(s,out);
	carefulClose(&out);
	sampleFreeList(&sList);
	}
    fprintf(stdout, "\tDone.\n");
    }

}
void affyTransLiftedToSample(int grouping, char *affyTransIn)
/* Top level function to run combine pairs and offset files to give sample. */
{
struct affyTransLifted *atl = NULL, *atlList = NULL;
struct sample *sampList = NULL, *samp = NULL;
struct sample *groupedList = NULL;
char *fileRoot = NULL;
char buff[10+strlen(affyTransIn)];
FILE *out = NULL;
char *fileNameCopy = cloneString(affyTransIn);
chopSuffix(fileNameCopy);
fprintf(stderr, ".");
fflush(stderr);
atlList = affyTransLiftedLoadAll(affyTransIn);
//warn("Creating samples.");
for(atl = atlList; atl != NULL; atl = atl->next)
    {
    samp = sampleFromAffyTransLifted(atl, fileNameCopy);
    if(samp != NULL)
	slAddHead(&sampList, samp);
    }
//warn("Sorting Samples");
slSort(&sampList, sampleCoordCmp);
groupedList = groupByPosition(grouping, sampList);
//warn("Saving Samples.");
snprintf(buff, sizeof(buff), "%s.sample", affyTransIn);
out = mustOpen(buff, "w");
for(samp = groupedList; samp != NULL; samp = samp->next)
    {
    sampleTabOut(samp, out);
    }
//warn("Cleaning up.");
freez(&fileNameCopy);
carefulClose(&out);
sampleFreeList(&sampList);
sampleFreeList(&groupedList);
affyTransLiftedFreeList(&atlList);
}
Example #5
0
void affyPairsToSample(struct hash *liftHash, int grouping, char *pairsIn)
/* Top level function to run combine pairs and offset files to give sample. */
{
struct affyPairs *apList = NULL, *ap = NULL;
struct sample *sampList = NULL, *samp = NULL;
struct sample *groupedList = NULL;
char buff[10+strlen(pairsIn)];
FILE *out = NULL;
fprintf(stderr, ".");
fflush(stderr);
//warn("Loading Affy Pairs.");
apList = affyPairsLoadAll(pairsIn);
//warn("Creating samples.");
for(ap = apList; ap != NULL; ap = ap->next)
    {
    samp = sampFromAffyPair(ap, liftHash);
    if(samp != NULL)
	{
	slAddHead(&sampList, samp);
	}
    }
//warn("Sorting Samples");
slSort(&sampList, sampleCoordCmp);
groupedList = groupByPosition(grouping, sampList);
//warn("Saving Samples.");
snprintf(buff, sizeof(buff), "%s.sample", pairsIn);
out = mustOpen(buff, "w");
for(samp = groupedList; samp != NULL; samp = samp->next)
    {
    sampleTabOut(samp, out);
    }
//warn("Cleaning up.");
carefulClose(&out);
sampleFreeList(&sampList);
sampleFreeList(&groupedList);
affyPairsFreeList(&apList);
}