title: How to calculate the frequency of every pathogenic germline variant in every disease cohort?
body: <p>I am trying to calculate the frequency of every pathogenic germline variant in every disease cohort. For ex: for variant 1:17588689, there are 20 het.variants (column H), I need to report what percentage of these samples are in glioma cohort, what percent in meningioma cohort..etc. I should append that information for each disease cohort, i.e. (meningioma, glioma, schwannoma, pituitary adenoma, others) at the end of the last column. So, also have to make sure the sum of the percentages add upto 1. The heterozygous sampleIDs are listed in column-AZ, titled &quot;HetSamples&quot; and IDs are seperated by comma in my dataset. I am stuck at some point so I would appreciate if someone can assist me to complete it.</p>
  <pre><code>library(stringr)
  library(tidyr)
  library(dplyr)
  </code></pre>
  <pre><code>diseaseData &lt;- read.delim(&quot;.../.txt&quot;, header = T, sep = &quot;\t&quot;) #disease cohort informations
  variantData &lt;- read.delim(&quot;.../.txt&quot;, header = T, sep = &quot;\t&quot;)
  </code></pre>
  <pre><code>variantData &lt;- variantData %&gt;% 
    mutate(HetSamples = strsplit(as.character(HetSamples), &quot;,&quot;)) %&gt;% 
    unnest(HetSamples)
  
  variantDataOld &lt;- variantData %&gt;% 
    filter(!str_detect(HetSamples, 'U'))
  
  variantDataNew &lt;- variantData %&gt;% 
    filter(str_detect(HetSamples, 'U'))
  
  diseaseDataOld &lt;- diseaseData %&gt;% 
    filter(!str_detect(ClinicalSeqID, 'U'))
  
  diseaseDataNew &lt;- diseaseData %&gt;% 
    filter(str_detect(ClinicalSeqID, 'U'))
  </code></pre>
  <pre><code>data.frame(do.call(&quot;rbind&quot;, strsplit(as.character(variantDataOld$HetSamples), &quot;-&quot;, fixed = TRUE)))
  data.frame(do.call(&quot;rbind&quot;, strsplit(as.character(diseaseDataOld$ClinicalSeqID), &quot;-&quot;, fixed = TRUE)))
  
  </code></pre>
  <pre><code>variantDataOld[c('Col1', 'Col2', 'Col3')] &lt;- str_split_fixed(variantDataOld$HetSamples, '-', 3)
  </code></pre>