Before I go to more in details, I want to point out that I already asked a certain part of this question -> You can find it here. I received some nice answers, but I need to do more so I'll repeat my question and add more details this time:
So I have a file with unique content that looks like this(lets call this myUniqueFile
):
chromosoom start end phylop GPS
chr1 28745756 28745756 7.905 5
chr1 31227215 31227215 10.263 5
chr1 47562402 47562402 2.322 4
chr1 64859630 64859630 1.714 3
chr1 70805699 70805699 1.913 2
chr1 89760653 89760653 -0.1 0
chr1 95630169 95630169 -1.651 -1
These are all different locations with different scores as you can see.
And I have another file that looks like this(lets call this one myDuplicationFile
:
chromosoom start end phylop GPS
chr3 15540407 15540407 -1.391 -1
chr3 30648039 30648039 2.214 3
chr3 31663820 31663820 0.713 3
chr3 33093371 33093371 3.753 4
chr3 37050398 37050398 1.650 2
chr3 38053456 38053456 1.1 1
chr3 39597927 39597927 8.721 5
So to start with I would like to add lines(except the header) from myUniqueFile
to myDuplicationFile
, but I want them to be added in way that myDublicationFile
is duplicated for each new line that is added from myUniqueFile
. So myDublicationFile
keeps his standard content + 1 new line added from myUniqueFile
. it should look something like this:
myDublicatedFile1.txt:
chromosoom start end phylop GPS
chr3 15540407 15540407 -1.391 -1
chr3 30648039 30648039 2.214 3
chr3 31663820 31663820 0.713 3
chr3 33093371 33093371 3.753 4
chr3 37050398 37050398 1.650 2
chr3 38053456 38053456 1.1 1
chr3 39597927 39597927 8.721 5
chr1 28745756 28745756 0.905 1 <- first line from `myUniquefile`
myDublicatedFile2.txt:
chromosoom start end phylop GPS
chr3 15540407 15540407 -1.391 -1
chr3 30648039 30648039 2.214 3
chr3 31663820 31663820 0.713 3
chr3 33093371 33093371 3.753 4
chr3 37050398 37050398 1.650 2
chr3 38053456 38053456 1.1 1
chr3 39597927 39597927 8.721 5
chr1 31227215 31227215 10.263 5 <- second line from `myUniquefile`
so for each new line added a new file is created like myDublicatedFile3,4,5
etc..
After I have these myDublicatedFiles
with the new added content, I would like to sort these files for a specific columns from high to low , (for the phylop column) I do this with for f in myDublicatedFile* ; do sort -g -r -k 3 $f >> $f.method1.txt
so this looks something like this:
myDublicatedFile1.method1.txt:
chr3 39597927 39597927 8.721 5
chr1 28745756 28745756 7.905 5 <- count 2
chr3 33093371 33093371 3.753 4
chr3 30648039 30648039 2.214 3
chr3 37050398 37050398 1.650 2
chr3 38053456 38053456 1.1 1
chr3 31663820 31663820 0.713 3
chr3 15540407 15540407 -1.391 -1
chromosoom start end phylop GPS
So after I sort these files, I would like to know the position of the lines I added after the sorting. It seems logical to me to do something with "grep" and use a "count".
So for myDublicatedFile1.method1.txt
is this count/rank 2 since the added line from myUniquefile
ended up in the second place in the file.
After calculating the count/rank for the phlop
(method1) column i would like to do a sort for the GPS
(method2) column and than calculate the ranks of the added lines again. myDublicatedFile1.method1.method2.txt should look something like this:
chr3 39597927 39597927 8.721 5
chr1 28745756 28745756 7.905 5
chr3 33093371 33093371 3.753 4
chr3 30648039 30648039 2.214 3
chr3 31663820 31663820 0.713 3
chr3 37050398 37050398 1.650 2
chr3 38053456 38053456 1.1 1
chr3 15540407 15540407 -1.391 -1
chromosoom start end phylop GPS
Its easy if the counts/rankings are written in different file so I can use these later for statistics. So the most important files are these count since I will end up use these :)
Something like:
countsForMethod1.txt:
29
3
5
6
50
etc.
countsForMethod2.txt:
7
3
21
45
etc..
myDuplicatedFiles*
files explicitly.