R/base_export.R

Defines functions .exportBED .exportGFF .exportTXT

Documented in .exportBED .exportGFF .exportTXT

# export all possible info

.exportTXT <- function( chrVec, muVec, strengthVec, psize, nameVec, filename )
{
    outFormat <- data.frame( chrVec, round(muVec)-floor(psize/2), round(muVec)+floor(psize/2),
        strengthVec, nameVec, stringsAsFactors=FALSE )
    colnames(outFormat) <- c( "chrID", "siteStart", "siteEnd", "strength", "peakName" )

    # Note (ver 0.9.9): chromStart 1-base & chromEnd inclusive.
    outFormat[ outFormat[,2] == 0, 2 ] <- 1
    	# first base should be 1, not 0, if we use 1-base system

    # variable names

    message( file=filename )
    message( as.character(colnames(outFormat)), file=filename, sep="\t", append=TRUE )
    message( "\n", file=filename, append=TRUE )

    # peak list

    for ( i in seq_len(nrow(outFormat)) )
    {
        message( as.character(outFormat[i,]), file=filename, sep="\t", append=TRUE )
        message( "\n", file=filename, append=TRUE )
    }

    message( "Info: Dpeak results were exported in TXT format:" )
    message( "Info: File name: ", filename )
}

# GFF format (score = 1000 * \pi)

.exportGFF <- function( chrVec, muVec, strengthVec, psize, nameVec, filename )
{
    # GFF: seqname, source, feature, start, end, score, strand, frame, group
    # Note (ver 0.9.9): chromStart 1-base & chromEnd inclusive.

    outFormat <- data.frame( chrVec, "Dpeak", nameVec,
        round(muVec)-floor(psize/2), round(muVec)+floor(psize/2), strengthVec,
        ".", ".", ".", stringsAsFactors=FALSE )
    outFormat[ outFormat[,4] <= 0, 4 ] <- 1
    	# first base should be 1, not 0, if we use 1-base system

    line0 <- 'track name=dpeak description=\"Dpeak binding sites\"'
    message( as.character(line0), "\n", file=filename )
    for ( i in seq_len(nrow(outFormat)) )
    {
        message( as.character(outFormat[i,]), file=filename, sep="\t", append=TRUE )
        message( "\n", file=filename, append=TRUE )
    }

    message( "Info: Dpeak results were exported in GFF format:" )
    message( "Info: File name: ", filename )
}

# BED format (score = 1000 * \pi)
.exportBED <- function( chrVec, muVec, strengthVec, psize, nameVec, filename )
{
    # BED: (required) chrom, chromStart, chromEnd
    # BED: (optional) name, score, strand, thickStart, thinkEnd, itemRgb,
    #                   blockCount, blockSizes, blockStarts
    # Note (ver 0.9.9): chromStart 0-base & chromEnd NOT inclusive (i.e., 1-base).

    outFormat <- data.frame( chrVec, round(muVec)-floor(psize/2), round(muVec)+floor(psize/2),
        nameVec, strengthVec, stringsAsFactors=FALSE )
    outFormat[ , 2 ] <- outFormat[ , 2 ] - 1
    outFormat[ outFormat[,2] < 0, 2 ] <- 0
    	# first base becomes -1 by (peakList$peakStart-1)

    line0 <- 'track name=dpeak description=\"Dpeak binding sites\" useScore=1'
    message( as.character(line0), "\n", file=filename )
    for ( i in seq_len(nrow(outFormat)) )
    {
        message( as.character(outFormat[i,]), file=filename, sep="\t", append=TRUE )
        message( "\n", file=filename, append=TRUE )
    }

    message( "Info: Dpeak results were exported in BED format:" )
    message( "Info: File name: ", filename )
}

Try the dpeak package in your browser

Any scripts or data that you put into this service are public.

dpeak documentation built on Nov. 8, 2020, 7:45 p.m.