Re: [R] inserting text lines in a dat frame

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 6 Feb 2008 05:37:38 -0500

Try this and see if it is what you want:

x <- read.table(textConnection(" V1 V2 V3 1 chr1 11255 55
2 chr1 11320 29
3 chr1 11400 45
4 chr2 21680 35
5 chr2 21750 84
6 chr2 21820 29
7 chr2 31890 46
8 chr3 32100 29
9 chr3 52380 29
10 chr3 66450 46" ), header=TRUE)
cat("browser position chr1:1-10000\nrowser hide all\n", file='tempxx.txt') result <- lapply(split(x, x$V1), function(.chro){

    cat(sprintf("track type=wiggle_0 name=sample description=%s_sample visibility=full\nvariableStep chrom=%s span=1\n",

        as.character(.chro$V1[1]), as.character(.chro$V1[1])), file="tempxx.txt", append=TRUE)

    write.table(.chro, sep="\t", file="tempxx.txt", append=TRUE, col.names=FALSE, row.names=FALSE)
})

On Feb 5, 2008 11:22 PM, joseph <jdsandjd_at_yahoo.com> wrote:
>
>
>
>
>
> Hi Jim
> I am trying to prepare a bed file to load as accustom track on the UCSC
> genome browser.
> I have a data frame that looks like the one below.
> > x
> V1 V2 V3
> 1 chr1 11255 55
> 2 chr1 11320 29
> 3 chr1 11400 45
> 4 chr2 21680 35
> 5 chr2 21750 84
> 6 chr2 21820 29
> 7 chr2 31890 46
> 8 chr3 32100 29
> 9 chr3 52380
> 29
> 10 chr3 66450 46
> I would like to insert the following 4 lines at the beginning:
> browser position chr1:1-10000
> browser hide all
> track type=wiggle_0 name=sample description=chr1_sample visibility=full
> variableStep chrom=chr1 span=1
> and then insert 2 lines before each chromosome:
> track type=wiggle_0 name=sample description=chr2_sample visibility=full
> vriableStep chrom=chr2 span=1
> The final result should be tab delimited file that looks like this:
> browser position chr1:1-10000
> browser hide all
> track type=wiggle_0 name=sample description=chr1_sample visibility=full
> variableStep chrom=chr1 span=1
> chr1 11255 55
> chr1 11320 29
> chr1 11400 45
> track type=wiggle_0 name=sample description=chr2_sample visibility=full
> variableStep chrom=chr2 span=1
> chr2 21680 35
> chr2 21750 84
> chr2 21820 29
> track type=wiggle_0 name=sample description=chr3_sample visibility=full
> variableStep chrom=chr3
> span=1
> chr3 32100 29
> chr3 32170 45
> chr3 32240 45
> Any kind of help or guidance will be much appreciated.
> Joseph
>
> ________________________________
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it
> now.

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 06 Feb 2008 - 10:45:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Feb 2008 - 11:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive