I have a file that looks like this:
1 10000 10400 GI.STMC.GAST-EnhA
1 10000 10400 SKIN.PEN.FRSK.FIB.02-EnhA
1 10000 10400 BRN.DL.PRFRNTL.CRTX-EnhA
1 10000 10400 BRN.ANT.CAUD-EnhA
1 10000 10400 HRT.ATR.R-EnhA
1 10200 10400 ESDR.H1.MSC-EnhA
1 10200 10400 GI.ESO-EnhA
1 10200 10400 GI.DUO.SM.MUS-EnhA
1 10200 10400 LNG-EnhA
1 14800 15200 MUS.TRNK.FET-EnhA
I want to split the files based on the annotations in the 4th column, I can extract the unique annotations with the following code:
sort -u file.list > annotation.list # file.list file with the different annotations
And I can store the information in annotation in an array with:
mapfile -t myARRAY < annotation.list,
However I don't know how to split the file in different files containing only annotation, an example would be including the annotation "ADRL.GLND.FET-TssA":
1 713800 714800 ADRL.GLND.FET-TssA
1 762000 763200 ADRL.GLND.FET-TssA
1 948600 948800 ADRL.GLND.FET-TssA
1 1166800 1167400 ADRL.GLND.FET-TssA
1 1208600 1208800 ADRL.GLND.FET-TssA
1 1243400 1243800 ADRL.GLND.FET-TssA
1 1244000 1244200 ADRL.GLND.FET-TssA
1 1284000 1284400 ADRL.GLND.FET-TssA
1 1310200 1310400 ADRL.GLND.FET-TssA
1 1310800 1311200 ADRL.GLND.FET-TssA
I might grep the unique annotations and output it to a file, but I am sure that could be a most elegant way,
Thanks
EDIT: so far i have this
mapfile -t myARRAY < annotation.list;
for ann in ${myARRAY}; do
grep ${ann} roadmap.core_active.bed > ${ann}.annotation
done
However, I only got an annotation made
for ann in "${myARRAY[@]}"; do ...