コード例 #1
0
void bedPlusTabOut(FILE *f, struct bedPlus *bp)
/* Output and handle plus info. */
{
if (bp->rest == NULL)
    bedOutputN(bp->bed, numBedFields, f, '\t', '\n');
else
    {
    bedOutputN(bp->bed, numBedFields, f, '\t', '\t');
    fprintf(f, "%s\n", bp->rest);
    }
}
コード例 #2
0
ファイル: bigWigAverageOverBed.c プロジェクト: sktu/kentUtils
void optionallyPrintBedPlus(FILE *f, struct bed *bed, int fieldCount, double extra)
/* Print BED to tab separated file plus an extra double-format column. */
{
if (f != NULL)
    {
    bedOutputN(bed, fieldCount, f, '\t', '\t');
    fprintf(f, "%g\n", extra);
    }
}
コード例 #3
0
ファイル: altAnalysis.c プロジェクト: ucscGenomeBrowser/kent
void outputControlExonBeds(struct altGraphX *ag, int v1, int v2)
{
int *vPos = ag->vPositions;
struct bed bedUp, bedDown, bedAlt;
struct evidence *ev = slElementFromIx(ag->evidence, altGraphXGetEdgeNum(ag, v1, v2));

/* Make sure that this edge has enough support 
   that we believe it. */
if(ev->evCount >= minControlConf)
    {
    /* Initialize some beds for reporting. */
    bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
    bedUp.name = bedDown.name = bedAlt.name = ag->name;
    bedUp.score = bedDown.score = bedAlt.score = altControl;
    safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
    safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
    safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);
    /* Alt spliced region. */
    bedAlt.chromStart = vPos[v1];
    bedAlt.chromEnd = vPos[v2];
    
    /* Upstream/down stream */
    if(sameString(ag->strand, "+"))
	{
	bedUp.chromStart = vPos[v1] - flankingSize;
	bedUp.chromEnd = vPos[v1];
	bedDown.chromStart = vPos[v2];
	bedDown.chromEnd = vPos[v2] + flankingSize;
	}
    else 
	{
	bedDown.chromStart = vPos[v1] - flankingSize;
	bedDown.chromEnd = vPos[v1];
	bedUp.chromStart = vPos[v2];
	bedUp.chromEnd = vPos[v2] + flankingSize;
	}
    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
    }
}
コード例 #4
0
ファイル: sax.c プロジェクト: hjanime/bwtool
void wigsax_bed4(FILE *out, struct metaBig *mb, struct bed *region, int alpha, int window, double mean, double std, boolean wig_out)
/* output the bed4 style when it's being run over an interval */
{
    struct bed *outBedList = NULL;
    struct bed *bed;
    struct perBaseWig *wigList = perBaseWigLoadContinue(mb, region->chrom, region->chromStart, region->chromEnd);
    struct perBaseWig *pbw;
    struct slDouble *datList = NULL;
    struct slDouble *oneDub;
    /* Maybe sometime I'll put back the option to use multiple alphabets at a time. */
    int alphaS = alpha;
    int alphaE = alpha;
    for (pbw = wigList; pbw != NULL; pbw = pbw->next)
    {
	struct bed *bedList = make_initial_bed_list(pbw, alphaE - alphaS + 2);
	int i, j;
	int data_len = pbw->chromEnd - pbw->chromStart; 
	for (i = alphaS; i <= alphaE; i++)
	{
	    char *sax = sax_from_array_force_window(pbw->data, data_len, i, window, mean, std);
	    for (j = 0, bed = bedList; ((j < data_len) && (bed != NULL)); j++, bed = bed->next)
		bed->name[i-alphaS] = sax[j];
	    freeMem(sax);
	}
	if (wig_out)
	    for (j = 0; j < data_len; j++)
	    {
		struct slDouble *dub = newSlDouble(pbw->data[j]);
		slAddHead(&datList, dub);
	    }
	while ((bed = slPopHead(&bedList)) != NULL)
	    slAddHead(&outBedList, bed);
    }
    slReverse(&outBedList);
    slReverse(&datList);
    perBaseWigFreeList(&wigList);
    oneDub = datList;
    for (bed = outBedList; bed != NULL; bed = bed->next)
    {
	bedOutputN(bed, 4, out, '\t', (wig_out) ? '\t' : '\n');
	if (wig_out)
	{
	    if (oneDub == NULL)
		errAbort("data inconsistency. programmer error\n");
	    fprintf(out, "%0.4f\n", oneDub->val);
	    oneDub = oneDub->next;
	}
    }
    bedFreeList(&outBedList);
    slFreeList(&datList);
}
コード例 #5
0
ファイル: liftOverMerge.c プロジェクト: sktu/kentUtils
void liftOverMerge(char *oldFile, char *newFile)
/* liftOverMerge - Merge regions in BED5  generated by liftOver -multiple */
{
    struct bed *bedList = NULL, *bed = NULL, *otherBed = NULL, *nextBed = NULL;
    struct bedList *bedListHeaders = NULL, *bedListHeader = NULL;
    FILE *f = mustOpen(newFile, "w");

    bedList = bedLoadNAll(oldFile, 5);

    /* break down bed list into a list of lists, one per "region", where region
     * is the name field in the bed */
    for (bed = bedList; bed != NULL; bed = nextBed)
    {
        verbose(3, "%s:%d-%d %s %d\n", bed->chrom, bed->chromStart, bed->chromEnd,
                bed->name, bed->score);
        if (bedListHeader == NULL ||
                differentString(bed->name, bedListHeader->name))
        {
            verbose(2, "region %s\n", bed->name);
            AllocVar(bedListHeader);
            bedListHeader->name = cloneString(bed->name);
            slAddHead(&bedListHeaders, bedListHeader);
        }
        nextBed = bed->next;
        slAddHead(&bedListHeader->bed, bed);
    }
    slReverse(&bedListHeaders);

    for (bedListHeader = bedListHeaders; bedListHeader != NULL;
            bedListHeader = bedListHeader->next)
    {
        int ix = 1;
        verbose(3, "region %s\n", bedListHeader->name);
        slReverse(&bedListHeader->bed);

        /* traverse list of bed lists, merging overlapping entries
         * for each region */
        for (bed = bedListHeader->bed; bed != NULL; bed = bed->next)
        {
            for (otherBed = bed->next; otherBed != NULL; otherBed = nextBed)
            {
                nextBed = otherBed->next;
                if (sameString(bed->chrom, otherBed->chrom) &&
                        (max(bed->chromStart, otherBed->chromStart) <=
                         min(bed->chromEnd, otherBed->chromEnd) + mergeGap))
                {
                    /* these regions overlap (or are within the merge gap),
                     * so create one that is a merge, and drop the other */
                    verbose(2,"merging %s:%d-%d, %s:%d-%d (overlap=%d)",
                            otherBed->chrom, otherBed->chromStart, otherBed->chromEnd,
                            bed->chrom, bed->chromStart, bed->chromEnd,
                            min(bed->chromEnd, otherBed->chromEnd) -
                            max(bed->chromStart, otherBed->chromStart));
                    bed->chromStart = min(otherBed->chromStart, bed->chromStart);
                    bed->chromEnd = max(otherBed->chromEnd, bed->chromEnd);
                    verbose(2," to %s:%d-%d\n",
                            bed->chrom, bed->chromStart, bed->chromEnd);
                    slRemoveEl(&bedListHeader->bed, otherBed);
                }
            }
        }
        for (otherBed = bedListHeader->bed; otherBed != NULL;
                otherBed = otherBed->next)
        {
            otherBed->score = ix++;
            bedOutputN(otherBed, 5, f, '\t', '\n');
        }
    }
}
コード例 #6
0
void bedHashOutput(void * val) 
{
struct bed *bed = val;
bedOutputN(bed, 15, bedOut, '\t', '\n');
}
コード例 #7
0
ファイル: find.c プロジェクト: CRG-Barcelona/bwtool
void bwtool_find_max(struct hash *options, char *favorites, char *regions, double fill,
		     char *bigfile, char *tmp_dir, char *outputfile)
/* find max points in a range */
{
    boolean med_base = (hashFindVal(options, "median-base") != NULL) ? TRUE : FALSE;
    boolean with_max = (hashFindVal(options, "with-max") != NULL) ? TRUE : FALSE;
    struct metaBig *mb = metaBigOpen_check(bigfile, tmp_dir, NULL);
    FILE *out = mustOpen(outputfile, "w");
    struct bed6 *sections6 = readBed6Soft(regions);
    struct bed *sections = bed12FromBed6(&sections6);
    struct bed *section;
    for (section = sections; section != NULL; section = section->next)
    {
	struct perBaseWig *pbwList = perBaseWigLoadContinue(mb, section->chrom, section->chromStart,
							      section->chromEnd);
	struct perBaseWig *pbw;
	struct slInt *ii;
	int i, size;
	double max = -DBL_MAX;
	struct slInt *list = NULL;
	for (pbw = pbwList; pbw != NULL; pbw = pbw->next)
	{
	    int pbw_off = pbw->chromStart - section->chromStart;
	    for (i = 0; i < pbw->len; i++)
	    {
		if (pbw->data[i] > max)
		{
		    slFreeList(&list);
		    struct slInt *new_int = slIntNew(i + pbw_off);
		    slAddHead(&list, new_int);
		    max = pbw->data[i];
		}
		else if (pbw->data[i] == max)
		{
		    struct slInt *new_int = slIntNew(i + pbw_off);
		    slAddHead(&list, new_int);
		}
	    }
	}
	slReverse(&list);
	if (list)
	{
	    size = slCount(list);
	    if (med_base)
	    {
		section->blockCount = 1;
		AllocArray(section->blockSizes, sizeof(int));
		AllocArray(section->chromStarts, sizeof(int));
		section->blockSizes[0] = 1;
		section->chromStarts[0] = median_base_calc(&list);
	    }
	    else
	    {
		section->blockCount = size;
		AllocArray(section->blockSizes, sizeof(int) * size);
		AllocArray(section->chromStarts, sizeof(int) * size);
		for (i = 0, ii = list; (i < size) && (ii != NULL); i++, ii = ii->next)
		{
		    section->blockSizes[i] = 1;
		    section->chromStarts[i] = ii->val;
		}
	    }
	    if (!with_max)
		bedTabOutN(section, 12, out);
	    else
	    {
		bedOutputN(section, 12, out, '\t', '\t');
		fprintf(out, "%f\n", max);
	    }
	    slFreeList(&list);
	}
	perBaseWigFree(&pbwList);
    }
    metaBigClose(&mb);
    bedFreeList(&sections);
    carefulClose(&out);
}
コード例 #8
0
ファイル: altAnalysis.c プロジェクト: ucscGenomeBrowser/kent
boolean isRetainIntron(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		       int *altBpStart, int *altBpEnd)
/* return TRUE if retained intron. 
   Looking for pattern:
   hs-->he---->hs--->he
    \---------------/

   Use edgesInArea() to investigate that encompasses the common hard
   end and common hard start. Should only be 4 edges in area defined by
   splicing.
   eseses 
   012345 
  0  
  1  + +
  2   + 
  3    +
  4   
  5
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;

/* Quick check. */
if(vTypes[vs] != ggHardStart || vTypes[ve1] != ggHardEnd || vTypes[ve2] != ggHardEnd)
    return FALSE;
if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find a hard start that connects ve1 and ve2. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardStart && em[ve1][i] && em[i][ve2] &&
	edgesInArea(ag,em,ve2-1,vs+1) == numAltVerts)
	    {
	    int *vPos = ag->vPositions;
	    struct bed bedAlt;
	    /* Initialize some beds for reporting. */
	    bedAlt.chrom = ag->tName;
	    bedAlt.name = ag->name;
	    bedAlt.score = altRetInt;
	    safef(bedAlt.strand, sizeof(bedAlt.strand), "%s", ag->strand);
	    /* Alt spliced region. */
	    bedAlt.chromStart = vPos[ve1];
	    bedAlt.chromEnd = vPos[i];
	    if(optionExists("printRetIntAccs"))
		{
		int incEdge = altGraphXGetEdgeNum(ag, vs, ve2);
		int exEdge = altGraphXGetEdgeNum(ag, ve1, i);
		struct evidence *ev= slElementFromIx(ag->evidence, incEdge);
		int i;
		fprintf(stdout, "RETINT\t%s\t%d\t", ag->name,ev->evCount);
		for(i = 0; i < ev->evCount; i++)
		    {
		    fprintf(stdout, "%s,", ag->mrnaRefs[ev->mrnaIds[i]]);
		    }
		fprintf(stdout, "\t");
		ev= slElementFromIx(ag->evidence, exEdge);
		fprintf(stdout, "%d\t", ev->evCount);
		for(i = 0; i < ev->evCount; i++)
		    {
		    fprintf(stdout, "%s,", ag->mrnaRefs[ev->mrnaIds[i]]);
		    }
		fprintf(stdout, "\n");
		}
	    /* Upstream/down stream */
	    if(altRegion != NULL)
		{
		bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		}
	    *altBpStart = ve1;
	    *altBpEnd = i;
	    return TRUE;
	    }
	}
    }
return FALSE;
}	    
コード例 #9
0
ファイル: altAnalysis.c プロジェクト: ucscGenomeBrowser/kent
boolean isCassette(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStartV, int *altBpEndV, int *startV, int *endV)
/* Return TRUE if SIMPLE cassette exon.
   Looking for pattern:
   he--->hs---->he---->hs
     \----------------/

   Use edgesInArea() to investigate that encompasses the common hard
   end and common hard start. Should only be 4 edges in area defined by
   splicing.
   sesese 
   012345 
  0  
  1  + +
  2   + 
  3    +
  4   
  5
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
int *vPos = ag->vPositions;
/* Quick check. */
if(vTypes[vs] != ggHardEnd || vTypes[ve1] != ggHardStart || vTypes[ve2] != ggHardStart)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find a hard end that connects ve1 and ve2. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardEnd && em[ve1][i] && em[i][ve2])
	    {
	    /* Make sure that our cassette only connect to downstream. otherwise not
	       so simple...*/
	    if(rowSum(em[i],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       colSum(em, ag->vTypes, ag->vertexCount, ve1) == 1 &&
	       edgesInArea(ag,em,ve2-1,vs+1) == numAltVerts)
		{
		struct bed bedUp, bedDown, bedAlt;
		/* Initialize some beds for reporting. */
		*startV = findClosestUpstreamVertex(ag, em, vs);
		*endV = findClosestDownstreamVertex(ag, em, ve2);
		bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedUp.name = bedDown.name = bedAlt.name = ag->name;
		bedUp.score = bedDown.score = bedAlt.score = altCassette;
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);
		/* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[i];

		/* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedUp.chromStart = vPos[ve1] - flankingSize;
		    bedUp.chromEnd = vPos[ve1];
		    bedDown.chromStart = vPos[i];
		    bedDown.chromEnd = vPos[i] + flankingSize;
		    }
		else 
		    {
		    bedDown.chromStart = vPos[ve1] - flankingSize;
		    bedDown.chromEnd = vPos[ve1];
		    bedUp.chromStart = vPos[i];
		    bedUp.chromEnd = vPos[i] + flankingSize;
		    }
		if(altRegion != NULL)
		    {
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    }
		*altBpStartV = ve1;
		*altBpEndV = i;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}
コード例 #10
0
ファイル: altAnalysis.c プロジェクト: ucscGenomeBrowser/kent
boolean isAlt5Prime(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStart, int *altBpEnd, int *termExonStart, int *termExonEnd)
/* Return TRUE if we have an edge pattern of:
   hs->he----->hs
     \-->he--/
   Which indicates two possible ends to an exon (alt 5' intron starts).

   Use edgesInArea() to investigate an area that begins in the rows with the common
   hard end and finishes with common hard end. 
   esees
   01234 (4 vertices involved in alt splicing)
  0  
  1  ++
  2    +
  3    +
  4   
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
/* Quick check. */
if(vTypes[vs] != ggHardStart || vTypes[ve1] != ggHardEnd || vTypes[ve2] != ggHardEnd)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find common start for the two hard ends. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardStart && em[ve1][i] && em[ve2][i])
	    {
	    /* Make sure that they only connect to that one hard start. */
	    if(rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve2],ag->vTypes,ag->vertexCount) == 1 &&
	       edgesInArea(ag,em,i-1,vs+1) == numAltVerts)
		{
		int *vPos = ag->vPositions;
		struct bed bedUp, bedDown, bedAlt, bedConst;
		
		/* Report the first and last vertexes. */
		*termExonStart = i;
		*termExonEnd = findClosestDownstreamVertex(ag, em, i);
                /* Initialize some beds for reporting. */
		bedConst.chrom = bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedConst.name = bedUp.name = bedDown.name = bedAlt.name = ag->name;
		if(sameString(ag->strand, "+"))
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt5Prime;
		else
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt3Prime;
		safef(bedConst.strand, sizeof(bedConst.strand), "%s", ag->strand);
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);

                /* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[ve2];
		bedConst.chromStart = vPos[vs];
		bedConst.chromEnd = vPos[ve1];

                /* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedDown.chromStart = vPos[ve2];
		    bedDown.chromEnd = vPos[ve2]+flankingSize;
		    bedUp.chromStart = vPos[vs]-flankingSize;
		    bedUp.chromEnd = vPos[vs];
		    }
		else 
		    {
		    bedUp.chromStart = vPos[ve2];
		    bedUp.chromEnd = vPos[ve2]+flankingSize;
		    bedDown.chromStart = vPos[vs]-flankingSize;
		    bedDown.chromEnd = vPos[vs];
		    }
		if(altRegion)
		    {
		    bedOutputN(&bedConst, 6, constRegion, '\t','\n');
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    }		
		*altBpStart = ve1;
		*altBpEnd = ve2;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}