示例#1
0
void hgGenericMicroarray(char *file)
/* Load the simple file into two tables.*/
{
struct expRecord *exps = NULL;
struct expData *data = NULL;
struct lineFile *lf = lineFileOpen(file,TRUE);
char *strings[1000];
int ncols, i, n;
/* First line has experiment info */
ncols = lineFileChopTab(lf,strings);
for (i = 1; i < ncols; i++)
    {
    struct expRecord *oneRec = NULL;
    AllocVar(oneRec);
    oneRec->id = i - 1;
    oneRec->name = cloneString(strings[i]);
    oneRec->description = cloneString(strings[i]);
    oneRec->url = CSNA;
    oneRec->ref = CSNA;
    oneRec->credit = CSNA;
    oneRec->numExtras = 3;
    AllocArray(oneRec->extras, oneRec->numExtras);
    oneRec->extras[0] = cloneString("n/a");
    oneRec->extras[1] = cloneString("n/a");
    oneRec->extras[2] = cloneString(strings[i]);
    slAddHead(&exps, oneRec);
    }
slReverse(&exps);
/* Other lines have the data. */
while ((n = lineFileChopTab(lf,strings)) > 0)
    {
    struct expData *oneGene = NULL;
    AllocVar(oneGene);
    oneGene->name = cloneString(strings[0]);
    oneGene->expCount = ncols - 1;
    AllocArray(oneGene->expScores, oneGene->expCount);
    for (i = 1; i < ncols; i++)
	oneGene->expScores[i-1] = sqlFloat(strings[i]);
    slAddHead(&data, oneGene);
    }
if ((n != ncols) && (n > 0))
    errAbort("Wrong number of columns in line %d of %s. Got %d, want %d", lf->lineIx, file, n, ncols);
slReverse(&data);
saveExpsTable(exps);
saveDataTable(data);
expRecordFreeList(&exps);
expDataFreeList(&data);
lineFileClose(&lf);
}
void eisenInput(char *database, char *outFile)
/* eisenInput - Create input for Eisen-style cluster program. */
{
struct slName *chromList = NULL, *chromEl;
FILE *f = mustOpen(outFile, "w");
char *chrom;
struct hash *refLinkHash = hashNew(0);
struct refLink *refLinkList;
struct hash *erHash = hashNew(0);
struct expRecord *erList = NULL, *er;


/* Load info good for all chromosomes. */
refLinkList = loadRefLink(database, refLinkHash);
erList = loadExpRecord(expRecordTable, "hgFixed");
for (er = erList; er != NULL; er = er->next)
    {
    char sid[16];
    snprintf(sid, sizeof(sid), "%u", er->id);
    hashAdd(erHash, sid, er);
    }

/* Do it chromosome by chromosome. */
chromList = hAllChromNames(database);
for (chromEl = chromList; chromEl != NULL; chromEl = chromEl->next)
    {
    chrom = chromEl->name;
    uglyf("%s\n", chrom);
    oneChromInput(database, chrom, hChromSize(database, chrom), "rnaCluster", expTrack, 
    	refLinkHash, erHash, f);
    }

/* Cleanup time! */
expRecordFreeList(&erList);
freeHash(&erHash);
refLinkFreeList(&refLinkList);
freeHash(&refLinkHash);
}
void bedListExpRecordAverage(struct bed **pBedList, struct expRecord **pERList, int extrasIndex)
/* This is a mildy complicated function to make the details page have the */
/* same data as the track when the UI option "Tissue averages" is selected. */
/* This is done by hacking the bed and expRecord lists in place and keeping */
/* the original code for the most part. */
{
struct bed *bed = NULL;
struct expRecord *er, *newERList = NULL;
struct slName *extras = NULL, *oneSlName;
int M, N, i, columns;
int *mapping;
if (!pBedList || !pERList || !*pBedList || !*pERList)
    return;
er = *pERList;
if ((extrasIndex < 0) || (extrasIndex >= er->numExtras))
    return;
/* Build up a unique list of words from the specific "extras" column. */
for (er = *pERList; er != NULL; er = er->next)
    slNameStore(&extras, er->extras[extrasIndex]);
slReverse(&extras);
M = slCount(extras);
N = slCount(*pERList);
columns = N + 1;
/* M rows, reserve first column for counts. */
mapping = needMem(sizeof(int) * M * columns);
/* Create the mapping array: */
/*   each row corresponds to one of the groupings.  The first column is the number of */
/*   things in the original list in the group (k things), and the next k elements  on */
/*   that row are indeces. */
for (er = *pERList, i = 0; er != NULL && i < N; er = er->next, i++)
    {    
    int ix = slNameFindIx(extras, er->extras[extrasIndex]) * columns;
    mapping[ix + ++mapping[ix]] = er->id; 
    }
/* Make a new expRecord list. */
for (oneSlName = extras, i = 0; oneSlName != NULL && i < M; oneSlName = oneSlName->next, i++)
    {
    struct expRecord *newER = basicExpRecord(oneSlName->name, i, extrasIndex);
    slAddHead(&newERList, newER);
    }
slReverse(&newERList);
expRecordFreeList(pERList);
*pERList = newERList;
/* Go through each bed and change it. */
for (bed = *pBedList; bed != NULL; bed = bed->next)
    {
    float *newExpScores = needMem(sizeof(float) * M);
    int *newExpIds = needMem(sizeof(int) * M);
    /* Calculate averages. */
    for (i = 0; i < M; i++)
	{
	int ix = i * columns;
	int size = mapping[ix];
	int j;
	double sum = 0;
	for (j = 1; j < size + 1; j++)
	    sum += (double)bed->expScores[mapping[ix + j]];
	newExpScores[i] = (float)(sum/size);
	newExpIds[i] = i;
	}
    bed->expCount = M;
    freeMem(bed->expIds);
    bed->expIds = newExpIds;
    freeMem(bed->expScores);
    bed->expScores = newExpScores;    
    }
/* Free stuff. */
slNameFreeList(&extras);
freez(&mapping);
}