Thanks, let me try this and report back
Hello,
I have 25 lists of genes.
On each list, there are anywhere from 1-50 genes
I want to process these lists to find, between these 25 lists, which genes show up most frequently.
Can anyone help?
What I have tried on R:
Loading all 25 lists, and then
Reduce(intersect, list(a,b,c))
However: when inputting 25 lists, it usually gives me a null because no single gene appears on all 25 lists.
My aim is to have a result where I have a list of genes listed by frequency of appearance within these 25 lists.
Thanks
3 answers
sort(table(c(list1, list2, ..., list25)), decreasing=T)
What is the format of your gene list?
If it is just a text file split by newlines, then you could easily do this on the command line with awk:
$ cat geneListA.txt geneListB.txt ... geneListN.txt
| awk ' \
{ \
geneCounts[$0]++; \
} \
END { \
for (geneName in geneCounts) { \
print geneName"\t"geneCounts[geneName]; \
} \
}' - \
> unsortedCounts.txt
The file unsortedCounts.txt is an unsorted two-column file containing the gene name and its count across files geneListA.txt through geneListN.txt.
To sort this by counts, just pipe the output of the awk statement to GNU sort and do a (descending) numeric sort on the second column:
$ cat geneListA.txt geneListB.txt ... geneListN.txt \
| awk ' \
{ \
geneCounts[$0]++; \
} \
END { \
for (geneName in geneCounts) { \
print geneName"\t"geneCounts[geneName]; \
} \
}' - \
| sort -n k2,2r - \
> sortedCounts.txt
I just tried to download gawk for windows + source files, accessed Gnuwin32/bin/awk etc on MS DOS and placed the genelists in the directory - I am completely lost though. Maybe staying on R is a better option
edit: or if you could provide some simpler steps
cheers
From MSDOS, I realized that type is the equivalent of cat
so I did cat genelist1.txt genelist2.txt genelist3.txt and in the cmd all the lists were printed out
Then, gawk { \geneCounts[$0]++; \} gives me an invalid character
Don't do bioinformatics on Windows. Sorry to be a snob about it, but you'll otherwise have to jump through numerous hoops to do common command-line tasks like these. Either swap out your OS or run your analyses within a Linux VM in VirtualBox or similar.
Megatron,
I had to do something similar in R a while ago. You'll need to create a list of lists, a list of unique gene IDs and then a matrix of counts. Here is my code:
my.lists <- list(list1=c(123,234,345), list2=c(45,23,12,78,43,87,123), list3=c(123,432,234,45,23))
unique_genes <- unique(unlist(my.lists))
#set up empty matrix
mtx <- matrix(0, nrow=length(names(my.lists)), ncol=length(unique_genes))
rownames(mtx) <- names(my.lists)
colnames(mtx) <- unique_genes
#populate the matrix
for(i in rownames(mtx)){
mtx[i,(colnames(mtx) %in% my.lists[[i]])] <- 1
}
freqSorted <- sort(colSums(mtx), decreasing=T)
Log in to answer this question.
?
Can you be a little more specific? I'm new at R.
I uploaded the lists onto my Global Environment so I'm not sure if I have to cat list or sort.
When I did
unique(list1, list2, list 3...list 25)it says hash table is full ---not sure what-cmeansThanks for your patience this is probably so easy for you
If it helps, here is my data specifically that I enter into the R Console:
Load lists: