Advertisement
dsuveges

Untitled

Jan 14th, 2023 (edited)
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.17 KB | None | 0 0
  1. column_names = [
  2.     'studyId',
  3.     'leadVariantId',
  4.     'tagVariantId',
  5.     'pValueMantissa',
  6.     'pValueExponent',
  7.     'R_overall',
  8. ]
  9.  
  10. data = [
  11.     # variant 1 (independent association):
  12.     ('s1', 'v1', 'v1', 1, -9, 1.0),
  13.     # variant 2, not resolved in ld matrix (independent association):
  14.     ('s1', 'v2', None, 1, -18, None),
  15.     # variant 3, most significant p-value (independent association):
  16.     ('s1', 'v3', 'v4', 1, -18, 1.0),
  17.     ('s1', 'v3', 'v5', 1, -18, 0.98),
  18.     # variant 4: higher p-value, explained by v3:
  19.     ('s1', 'v4', 'v3', 4, -9, 0.98),
  20.     ('s1', 'v4', 'v5', 4, -9, 0.98),
  21.     ('s1', 'v4', 'v6', 4, -9, 1.0),
  22.     # variant 5: higher p-value, explained by v3 and v4:
  23.     ('s1', 'v5', 'v3', 1, -8, 1.0),
  24.     ('s1', 'v5', 'v4', 1, -8, 0.98),
  25.     ('s1', 'v5', 'v6', 1, -8, 0.98),
  26.     # variant 6: higher p-value, explained by v5,v4 and v7 but not v3:
  27.     ('s1', 'v6', 'v5', 5, -8, 1.0),
  28.     ('s1', 'v6', 'v4', 5, -8, 1.0),
  29.     ('s1', 'v6', 'v7', 5, -8, 1.0),
  30.     # variant 7: low p-value (independent association).
  31.     ('s1', 'v7', 'v6', 1, -18, 1.0),
  32. ]
  33.  
  34. df = (
  35.     spark.createDataFrame(data, column_names)
  36.     .withColumn('qualityControl', f.array())
  37.     .persist()
  38. )
  39. df.show()
  40.  
  41. '''
  42. Input:
  43.  
  44. +-------+-------------+------------+--------------+--------------+---------+--------------+
  45. |studyId|leadVariantId|tagVariantId|pValueMantissa|pValueExponent|R_overall|qualityControl|
  46. +-------+-------------+------------+--------------+--------------+---------+--------------+
  47. |     s1|           v1|          v1|             1|            -9|      1.0|            []|
  48. |     s1|           v2|        null|             1|           -18|     null|            []|
  49. |     s1|           v3|          v4|             1|           -18|      1.0|            []|
  50. |     s1|           v3|          v5|             1|           -18|     0.98|            []|
  51. |     s1|           v4|          v3|             4|            -9|     0.98|            []|
  52. |     s1|           v4|          v5|             4|            -9|     0.98|            []|
  53. |     s1|           v4|          v6|             4|            -9|      1.0|            []|
  54. |     s1|           v5|          v3|             1|            -8|      1.0|            []|
  55. |     s1|           v5|          v4|             1|            -8|     0.98|            []|
  56. |     s1|           v5|          v6|             1|            -8|     0.98|            []|
  57. |     s1|           v6|          v5|             5|            -8|      1.0|            []|
  58. |     s1|           v6|          v4|             5|            -8|      1.0|            []|
  59. |     s1|           v6|          v7|             5|            -8|      1.0|            []|
  60. |     s1|           v7|          v6|             1|           -18|      1.0|            []|
  61. +-------+-------------+------------+--------------+--------------+---------+--------------+
  62.  
  63.  
  64. Expected output:
  65.  
  66. +-------+---------+------------+--------------+--------------+---------+----------------------------------+
  67. |studyId|variantId|tagVariantId|pValueMantissa|pValueExponent|R_overall|qualityControl                    |
  68. +-------+---------+------------+--------------+--------------+---------+----------------------------------+
  69. |s1     |v1       |v1          |1             |-9            |1.0      |[]                                |
  70. |s1     |v2       |null        |1             |-18           |null     |[]                                |
  71. |s1     |v3       |v5          |1             |-18           |0.98     |[]                                |
  72. |s1     |v3       |v4          |1             |-18           |1.0      |[]                                |
  73. |s1     |v4       |null        |4             |-9            |null     |[Association explained by: v3]    |
  74. |s1     |v5       |null        |1             |-8            |null     |[Association explained by: v3]    |
  75. |s1     |v6       |null        |5             |-8            |null     |[Association explained by: v3, v7]|
  76. |s1     |v7       |v6          |1             |-18           |1.0      |[]                                |
  77. +-------+---------+------------+--------------+--------------+---------+----------------------------------+
  78. '''
Tags: pyspark
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement