I have a dataset with following information. Column C1_1 is chromosome number, C1_2 is SNP position and C3 is the p-value. I want to pick the most significant association within a genomic region of 3000 bp:
C1 C2 C3
L01_005000 L002g034 1.5e-12
L01_003000 L001g045 2.3e-6
L02_145000 L004g034 1.1e-2
L02_155000 L002g050 1.1e-4
L02_148000 L002g001 1.1e-3
I want to split first column into two as:
C1_1 C1_2 C2 C3
L01 005000 L002g034 1.5e-12
L01 003000 L001g045 2.3e-6
L02 145000 L004g034 1.1e-2
L02 155000 L002g050 1.1e-4
L02 148000 L002g001 1.1e-3
Then I want to sort subsets such as L01
and L02
separately based on C1_2
column:
C1_1 C1_2 C2 C3
L01 003000 L001g045 2.3e-6
L01 005000 L002g034 1.5e-12
L02 145000 L004g034 1.1e-2
L02 148000 L002g001 1.1e-3
L02 155000 L002g050 1.1e-4
Then I want to pick one value from each subset such as for L02
– I want to pick the most significant value based on C3
column under the difference of 3000. For example, L02-148000
is chosen as shown below as its C3
value is lower than L02-145000
, and then the next value L02-155000
is chosen as the difference is more than 3000 than the previous value of L02-148000
:
C1_1 C1_2 C2 C3
L01 005000 L002g034 1.5e-12
L02 148000 L002g001 1.1e-3
L02 155000 L002g050 1.1e-4
I have a long dataset with 500,000 rows of values and the subset goes from L01-L24
. I think it will need a loop to process these many values to get the final values.
This is just an example, I have shown one for L01 because the difference in L01 203000 and L01 205000 is less than 3000. I have shown two values for L02 because the difference between L02 145000 and L02 148000 is not more than 3000. Whereas the difference between L02 155000 and L02 148000 is more than 3000.
C1_2
value forL01
supposed to be005000
or205000
? $\endgroup$205000
(lower table), either that or its not possible to solve. $\endgroup$C1_2
.. well thats how I'd do it anyway. $\endgroup$