read.csv("src/components/sexHormoneMeds.csv")
##           code                                                           name
## 1   1140869270                                          "medroxyprogesterone"
## 2   1140910674                                       "ethinylnortestosterone"
## 3   1140857656                                   "methyltestosterone product"
## 4   1140865136                        "yohimbine/pemoline/methyltestosterone"
## 5   1140868532                                         "testosterone product"
## 6   1140857690                              "oestradiol 25mg implant 36 week"
## 7   1140857700                                 "oestradiol 1mg/1ml injection"
## 8   1141165318                                                   "cetrorelix"
## 9   1140917306                                                 "bicalutamide"
## 10  1140917310                                          "casodex 50mg tablet"
## 11  1140917448                                    "oestradiol 1.25g/dose gel"
## 12  1140917450                                          "oestrogel 1.25g gel"
## 13  1141171536                                                    "ganirelix"
## 14  1140884638                                                   "clomiphene"
## 15  1140884634                                                  "cyproterone"
## 16  1140870186                                        "oestrifen 10mg tablet"
## 17  1140921100                                                  "triptorelin"
## 18  1140868984                                                    "nafarelin"
## 19  1140868978                                                   "gestrinone"
## 20  1140884544                                                  "leuprorelin"
## 21  1140870248                                                    "buserelin"
## 22  1140870194                                                    "goserelin"
## 23  1141157394                                            "goserelin product"
## 24  1140868882                                                  "gonadorelin"
## 25  1141182558                                               "urofollitropin"
## 26  1140868722                                                   "cyclofenil"
## 27  1140868580                                               "norethisterone"
## 28  1140869328    "ethinyloestradiol+norethisterone acetate 20mcg/1mg tablet"
## 29  1140869356             "mestranol+norethisterone 50micrograms/1mg tablet"
## 30  1141157406                                       "norethisterone product"
## 31  1141168324           "oestradiol+norethisterone acetate 1mg/0.5mg tablet"
## 32  1141181298     "ethinylestradiol+norethisterone acetate 20mcg/1mg tablet"
## 33  1141181204            "ethinylestradiol+norgestimate 35mcg/250mcg tablet"
## 34  1141181218                                     "ethinylestradiol product"
## 35  1141181220                                             "ethinylestradiol"
## 36  1141181240          "ethinylestradiol+levonorgestrel 30mcg/150mcg tablet"
## 37  1141181286             "ethinylestradiol+desogestrel 20mcg/150mcg tablet"
## 38  1140869348           "ethinyloestradiol+norgestimate 35mcg/250mcg tablet"
## 39  1140868520                                         "estracombi tts patch"
## 40  1140857628                                   "gestone 10mg/1ml injection"
## 41  1140857704                                 "ovestin 250micrograms tablet"
## 42  1140857706                                "oestriol 250micrograms tablet"
## 43  1140857708                                                 "quinestradol"
## 44  1140857710                                "pentovis 250micrograms tablet"
## 45  1140857714                                                   "quinestrol"
## 46  1140857716                                          "estrovis 4mg tablet"
## 47  1140857736                                 "virormone 10mg/1ml injection"
## 48  1140857912                                                  "desogestrel"
## 49  1140857918                                                 "lynoestrenol"
## 50  1140857920                                               "minilyn tablet"
## 51  1140858324                      "medroxyprogest 80mg/ml suspension 100ml"
## 52  1140858332                                           "sh-420 10mg tablet"
## 53  1140858338                                      "drostanolone propionate"
## 54  1140858340                                 "masteril 100mg/1ml injection"
## 55  1140858348                                           "noltam 10mg tablet"
## 56  1140864196                                         "climagest 1mg tablet"
## 57  1140864502                          "testotop tts 15mg transdermal patch"
## 58  1140868400                                             "oestriol product"
## 59  1140868372                                          "climaval 1mg tablet"
## 60  1140868406                                        "conjugated oestrogens"
## 61  1140868408                                "premarin 625micrograms tablet"
## 62  1140868420                                 "piperazine oestrone sulphate"
## 63  1140868422                                        "harmogen 1.5mg tablet"
## 64  1140868472                                        "vagifem 25mcg pessary"
## 65  1140868482                                                     "tibolone"
## 66  1140868488                                               "allyloestrenol"
## 67  1140868490                                          "gestanin 5mg tablet"
## 68  1140868494                                               "dydrogesterone"
## 69  1140868496                                        "duphaston 10mg tablet"
## 70  1140868508                                   "cyclo-progynova 1mg tablet"
## 71  1140868512                                      "syntex menophase tablet"
## 72  1140868514                                            "trisequens tablet"
## 73  1140868518                                               "nuvelle tablet"
## 74  1140868524                                         "androcur 50mg tablet"
## 75  1140868526                                                  "mesterolone"
## 76  1140868528                                        "pro-viron 25mg tablet"
## 77  1140868534                   "primoteston depot 250mg/1ml oily injection"
## 78  1140868536                                       "restandol 40mg capsule"
## 79  1140868538                                  "sustanon 100 oily injection"
## 80  1140868584                                        "primolut-n 5mg tablet"
## 81  1140868586                                           "utovlan 5mg tablet"
## 82  1140868588                                         "progesterone product"
## 83  1140868590                                  "cyclogest 200mg suppository"
## 84  1140868614                       "deca-durabolin 25mg/1ml oily injection"
## 85  1140868618                                                   "stanozolol"
## 86  1140868620                                           "stromba 5mg tablet"
## 87  1140868628               "humegon 75iu injection (pdr for recon)+solvent"
## 88  1140869032                                                  "dienoestrol"
## 89  1140869034                           "ortho-gynest 500micrograms pessary"
## 90  1140869166            "ethinyloestradiol+desogestrel 20mcg/150mcg tablet"
## 91  1140869170                                             "conova 30 tablet"
## 92  1140869172      "ethinyloestradiol+ethynodiol diacetate 30mcg/2mg tablet"
## 93  1140869174                                            "eugynon 30 tablet"
## 94  1140869176                                               "logynon tablet"
## 95  1140869180                                         "microgynon 30 tablet"
## 96  1140869184                                              "ovran 30 tablet"
## 97  1140869186                                             "ovranette tablet"
## 98  1140869188                                          "schering pc4 tablet"
## 99  1140869190                                            "trinordiol tablet"
## 100 1140869248         "ethinyloestradiol+levonorgestrel 30mcg/150mcg tablet"
## 101 1140869254                                               "binovum tablet"
## 102 1140869256                                              "brevinor tablet"
## 103 1140869258                                           "neocon 1/35 tablet"
## 104 1140869260                                               "norimin tablet"
## 105 1140869262                                               "ovysmen tablet"
## 106 1140869264                                              "synphase tablet"
## 107 1140869266                                              "trinovum tablet"
## 108 1140869272                                               "neogest tablet"
## 109 1140869276                                              "micronor tablet"
## 110 1140869278                                               "noriday tablet"
## 111 1140869282                          "noristerat 200mg/1ml oily injection"
## 112 1140869324                                           "loestrin 20 tablet"
## 113 1140869332                                               "minulet tablet"
## 114 1140869334                                              "femodene tablet"
## 115 1140869338                                           "tri-minulet tablet"
## 116 1140869340                                              "triadene tablet"
## 117 1140869346                                                "cilest tablet"
## 118 1140869352                                             "norinyl-1 tablet"
## 119 1140869354                                      "ortho-novin 1/50 tablet"
## 120 1140869360                                         "ethynodiol diacetate"
## 121 1140869362                                               "femulen tablet"
## 122 1140869366                                               "levonorgestrel"
## 123 1140869368                                              "microval tablet"
## 124 1140869370                                             "norgeston tablet"
## 125 1140870060                                      "polyestradiol phosphate"
## 126 1140870052                                          "honvan 100mg tablet"
## 127 1140870062            "estradurin 40mg injection (pdr for recon)+diluent"
## 128 1140870070                                                 "stilboestrol"
## 129 1140870076                                            "apstil 1mg tablet"
## 130 1140876638                        "cyproterone acetate+ethinyloestradiol"
## 131 1140879554                                                 "estramustine"
## 132 1140884622                                            "oestrogen product"
## 133 1140884624                                                   "fosfestrol"
## 134 1140884626                                                    "mestranol"
## 135 1140884688                                          "hydroxyprogesterone"
## 136 1140909906                                                  "estropipate"
## 137 1140910562                                                  "gestonorone"
## 138 1140921088                                             "tridestra tablet"
## 139 1141157404                                    "ethinyloestradiol product"
## 140 1141157410                                       "levonorgestrel product"
## 141 1141157492                                            "mestranol product"
## 142 1141166196                                                 "etonogestrel"
## 143 1141166354                      "testoderm 6mg/24hours transdermal patch"
## 144 1141166366 "ethinyloestradiol+gestodene 20micrograms/75micrograms tablet"
## 145 1141167206                                          "oestrogel 0.06% gel"
## 146 1141177150                                       "adgyn medro 5mg tablet"
## 147 1141177158                                       "adgyn estro 2mg tablet"
## 148 1141177226                                       "adgyn combi 2mg tablet"
## 149 1141179822        "ethinylestradiol+drospirenone 30micrograms/3mg tablet"
## 150 1141179820                                                 "drospirenone"
## 151 1141180988                                                   "dienestrol"
## 152 1141181594                                              "estriol product"
## 153 1141181700                                            "estradiol product"
## 154 1141182794                                          "desogestrel product"
## 155 1141190580  "conjugated oestrogens 0.3mg / medroxyprogesterone 1.5mg tab"
## 156 1141192344                         "cyproterone acetate+ethinylestradiol"
## 157 1141192874 "ethinylestradiol+norelgestromin 600mcg/6mg transdermal patch"
## 158 1141193272                                  "testogel 50mg gel 5g sachet"
## 159 1141202030                                  "estradot 25micrograms patch"
## 160 1141181818            "estradiol+norethisterone acetate 1mg/0.5mg tablet"
read.table("src/components/phenocodes.txt", header=F)
##       V1                           V2
## 1  30620     Alanine_aminotransferase
## 2  30600                      Albumin
## 3  30610         Alkaline_phosphatase
## 4  30630             Apolipoprotein_A
## 5  30640             Apolipoprotein_B
## 6  30650   Aspartate_aminotransferase
## 7  30710           C-reactive_protein
## 8  30680                      Calcium
## 9  30690                  Cholesterol
## 10 30700                   Creatinine
## 11 30720                   Cystatin_C
## 12 30660             Direct_bilirubin
## 13 30730    Gamma_glutamyltransferase
## 14 30740                      Glucose
## 15 30750 Glycated_haemoglobin_(HbA1c)
## 16 30760              HDL_cholesterol
## 17 30770                        IGF-1
## 18 30780                   LDL_direct
## 19 30790                Lipoprotein_A
## 20 30800                   Oestradiol
## 21 30810                    Phosphate
## 22 30820            Rheumatoid_factor
## 23 30830                         SHBG
## 24 30850                 Testosterone
## 25 30840              Total_bilirubin
## 26 30860                Total_protein
## 27 30870                Triglycerides
## 28 30880                        Urate
## 29 30670                         Urea
## 30 30890                    Vitamin_D
writeLines(readLines("src/components/SSRI_Meds.R",warn = F))
## #SSRIs=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## 
## ssricodes<-c(1140921600,
##              1141180212,
##              1140879540,
##              1140867888,
##              1140867878,
##              1140867876,
##              1140867884,
##              1140867888,
##              1140867860  
## )
## 
## names(ssricodes)<-c("citalopram",
##                     "escitalopram",
##                     "fluoxetine",
##                     "paroxetine",
##                     "sertraline",
##                     "prozac 20mg capsule",
##                     "lustral 50mg tablet",
##                     "paroxetine",
##                     "faverin 50mg tablet"
## )
writeLines(readLines("src/components/cbat.R",warn = F))
## #Vermeulen equation
## #CBAT = calculated bioavailable testosterone
## #Rcode from: https://labrtorian.com/tag/vermeulen-equation/
## # where testosterone is reported in nmol/L (same as UKB), 
## # sex hormone binding globulin (SHBG) is reported in nmol/L (same as UKB), 
## # and albumin is reported in g/L (same as UKB)
## # see also http://www.issam.ch/freetesto.htm which does the Vermeulen calc.
## # Ruth et al 2020 does the Morris for BT and I agree.
## 
## cbat <- function(TT,SHBG,ALB = 43){
##     Ka <- 3.6*10^4 #called kat in ruth
##     Kshbg <- 10^9 #called kt in ruth
##     N <- 1 + Ka*ALB/69000 #called k1 in ruth
##     a <- N*Kshbg #called a in ruth
##     b <- N + Kshbg*(SHBG - TT)/10^9 
##     c <- -TT/10^9
##     FT <- (-b + sqrt(b^2 - 4*a*c))/(2*a)*10^9
##     cbat <- N*FT
##     #return(list(free.T = FT, cbat = cbat))
##     BT<-exp(-.266+.955*log(TT)-0.228 * log (SHBG)) #Morris equation
##     return(list(freeTest = FT, bioavailableTest = BT))
## }
## 
## # cbat(TT = 3.47, SHBG = 50, ALB = 40)
## # 
## # #3.47 nmol/L = 100.08 ng/dL
## # 100.08/3.47 #[1] 28.8415
## # #divide by 28.8 to go from ng/dL to nmol/L
## # 
## # #228.4 ng/dL
## # 228.4/28.8
## # 7.93
## # 
## # cbat(7.93, SHBG = 40)
## # #0.1351578 nmol/L to ng/dL #conversion : http://unitslab.com/node/136
## # 0.1351578*28.8
## # 
## # #free T in nmol/L
## # TT1<-3.47
## # SHBG1<-50
## # 
## # 
## # BT<-exp(-.266+.955*log(TT1)-0.228 * log (SHBG1))
## # BT
writeLines(readLines("src/components/manyColsToDummy.R",warn = F))
## #A base-R script that searches over many input columns for input values 
## #and returns a dataframe of dummy variables that indicate if the values 
## #were present in these columns.
## 
## #Note that grep functions use regular expressions as their search terms, so if you are trying to match a string or number, adding ^ and $ is necessary!
## #For example, if you want to match 612, use "^612$"
## 
## 
## 
## manyColsToDummy<-function(search_terms, search_columns,
##                           output_table){
##     #initialize output table
##     temp_table<-data.frame(matrix(ncol=length(search_terms),
##                                   nrow= nrow(search_columns)))
##     colnames(temp_table)<-search_terms
##     
##     #make table
##     for (i in 1:length(search_terms)){
##         vec<-rowSums(sapply(search_columns,
##                             function(x) grepl(search_terms[i], x, ignore.case = TRUE)
##         ))>0
##         temp_table[,i]<-vec
##     }
##     temp_table<-sapply(temp_table, as.integer, as.logical)
##     temp_table<-as.data.frame(temp_table)
##     assign(x = output_table, value = temp_table, envir = globalenv())
## }
## 
## 
## #Example
## #manyColsToDummy("find_this", big_table[,columns_to_look_in], "dummy_output_table")
## 
## #Visual example found here: https://ibb.co/VwHvBLT