This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How separate one column in two columns?

I have a table with two columns and I would like to separate its first column in two separated columns or remove some useless values.

Input:

Gene            Disease
MSMO1 (6307)    MICROCEPHALY, CONGENITAL CATARACT, AND P... (OMIM:616834)
SC5D (6309)     LATHOSTEROLOSIS (OMIM:607330), Lathosterolosis (ORPHA:46059)
COG1 (9382)     CONGENITAL DISORDER OF GLYCOSYLATION, TY... (OMIM:611209)
COG6 (57511)    CONGENITAL DISORDER OF GLYCOSYLATION, TY... (OMIM:614576)
UBE3A (7337)    15q11q13 microduplication syndrome (ORPHA:238446)

Output:

Gene            Disease
MSMO1          MICROCEPHALY, CONGENITAL CATARACT, AND P... (OMIM:616834)
SC5D           LATHOSTEROLOSIS (OMIM:607330), Lathosterolosis (ORPHA:46059)
COG1           CONGENITAL DISORDER OF GLYCOSYLATION, TY... (OMIM:611209)
COG6           CONGENITAL DISORDER OF GLYCOSYLATION, TY... (OMIM:614576)
UBE3A          15q11q13 microduplication syndrome (ORPHA:238446)

Thanks for any solution in advanced.

r linix

I know it is not what you want to hear and probably you will be annoyed but I can only repeat what I commented on your last question ( how make a data table by merging three data sets? ) as this is exactly the same kind of underlying problem:

You should really try and find answers for these kinds of problems yourself. I remember you asked this kind of question before in a different context and got many solutions. Try to understand the logic behind it. There is no point in spoon-feeding as you cannot abstract it to different problems.

Get a background in basic Unix tool for data manipulation. There is no point in asking for spoon-feeding every time you encounter such a problem. I guarantee you this 100% can be done with basic awk commands. Spend quality-time learning it, really this is essential in bioinformatics. No offense intended.

See e.g. https://unix.stackexchange.com/questions/156919/splitting-a-column-using-awk

1 answer

library(splitstackshape)
cSplit(df, 'Gene', sep=" ", type.convert=FALSE)
df<-df[-c(column_name_generated_after_split),]

Log in to answer this question.