Question: Sorting Enhancers According To Transcription Factors In R
0
gravatar for Diana
6.6 years ago by
Diana800
Germany
Diana800 wrote:

Hi everyone,

I have a file like this with enhancers from 4 different genes with their TFs:

gene1            gene2            gene3            gene4            TF
gene1Enhancer1    gene2Enhancer1    gene3Enhancer2    Gene4Enhancer1    V$GSH1
gene1Enhancer2    gene2Enhancer2    gene3Enhancer3    Gene4Enhancer2    V$GSH1
gene1Enhancer3    gene2Enhancer3    gene3Enhancer4    Gene4Enhancer3    V$GSH1
gene1Enhancer1    gene2Enhancer1    gene3Enhancer2    Gene4Enhancer1    V$REF
gene1Enhancer3    gene2Enhancer3    gene3Enhancer4    Gene4Enhancer3    V$AB
gene1Enhancer6    gene2Enhancer6    gene3Enhancer7    Gene4Enhancer6    V$LEF1

I want the output to be sorted such that the first 4 columns are sorted so that same enhancers from 4 columns are put together with their transcription factors so it should look like this:

gene1            gene2            gene3            gene4            TF
gene1Enhancer1    gene2Enhancer1    gene3Enhancer2    Gene4Enhancer1    V$GSH1
gene1Enhancer1    gene2Enhancer1    gene3Enhancer2    Gene4Enhancer1    V$REF
gene1Enhancer3    gene2Enhancer3    gene3Enhancer4    Gene4Enhancer3    V$GSH1
gene1Enhancer3    gene2Enhancer3    gene3Enhancer4    Gene4Enhancer3    V$AB
gene1Enhancer2    gene2Enhancer2    gene3Enhancer3    Gene4Enhancer2    V$GSH1
gene1Enhancer6    gene2Enhancer6    gene3Enhancer7    Gene4Enhancer6    V$LEF1

I was thinking of using aggregate function in R but that didn't help. Any advice?

Thanks a lot!!!

R • 1.0k views
ADD COMMENTlink modified 6.6 years ago by Anthony Mathelier870 • written 6.6 years ago by Diana800
2
gravatar for zx8754
6.6 years ago by
zx87548.2k
London
zx87548.2k wrote:

Sorting example based on multiple columns:

m <- matrix( sample(1:5, 20, rep=TRUE), nc=2)
m[ order(m[,1],m[,2]), ]

Also have a look at this How to sort a dataframe by column(s) in R

ADD COMMENTlink written 6.6 years ago by zx87548.2k
0
gravatar for Anthony Mathelier
6.6 years ago by
University of Oslo, Oslo, Norway
Anthony Mathelier870 wrote:

Just in case you need it outside of R, only one line is necessary in your terminal:

$ sort -k4,4 [input file] > [output file]
ADD COMMENTlink modified 6.6 years ago • written 6.6 years ago by Anthony Mathelier870
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2379 users visited in the last hour