Sorting Enhancers According To Transcription Factors In R
2
0
Entering edit mode
10.9 years ago
Diana ▴ 910

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.6k views
ADD COMMENT
2
Entering edit mode
10.9 years ago
zx8754 11k

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 COMMENT
0
Entering edit mode
10.9 years ago

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 COMMENT

Login before adding your answer.

Traffic: 1983 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6