Skip to content
Snippets Groups Projects
Commit d4465971 authored by Deepankar Chakroborty's avatar Deepankar Chakroborty
Browse files

Add CT_GA_count.R

commit ec4f4915
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Fri Jul 31 13:23:36 2020 +0300

    Removed testing code

commit c1fddc71
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Fri Jul 31 13:23:14 2020 +0300

    Fixed subsetting to make it work

commit a64df5c0
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Fri Jul 31 13:16:28 2020 +0300

    add CT_GA_count.R

commit fe050d47
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Fri Jul 31 12:57:11 2020 +0300

    Include usage instruction inside function body

    Include usage instruction inside function body, so on typing just the function name to display the R code, the instructions will appear.
    Also stated things clearly in the T&C

commit fedbca4a
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Thu Jul 30 12:50:20 2020 +0300

    Updates

    1. Improve readability
    2. Manage differing lengths of breaks and labels.

commit fb32fb91
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Thu Jul 30 12:43:20 2020 +0300

    skip.steps works as expected

    skip.steps = 1, now skips 1 observation.

commit 00a8bbcf
Author: Deepankar Chakroborty <deepankar.chakroborty@utu.fi>
Date:   Thu Jul 30 12:32:16 2020 +0300

    add script to calculate breaks for axes in ggplot2

    calculates breaks and labels for axes in ggplot2 with user defined gaps
parent 52554283
Branches
No related tags found
No related merge requests found
CT_GA_count <- function(SampleID,Ref_Base,Alt_Base){
# #<---------------------------->
# # You must include this section when:
# # Distributing, Using and/or Modifying this code.
# # Please read and abide by the terms of the included LICENSE.
# # Copyright 2020, Deepankar Chakroborty, All rights reserved.
# #
# # Author : Deepankar Chakroborty (https://gitlab.utu.fi/deecha)
# # Report issues: https://gitlab.utu.fi/deecha/shared_scripts/-/issues
# # License: https://gitlab.utu.fi/deecha/shared_scripts/-/blob/master/LICENSE
# #<---------------------------->
# # PURPOSE:
# # This function takes in three vectors:
# # SampleID = Sample IDs
# # Ref_Base = Reference Base
# # Alt_Base = altered base that created the mutation.
# # And calculates the number of C > T and G > A changes are there (per sample)
# # The function returns a data frame listing the number of mutations (per sample):
# # SampleID = Sample ID
# # Total = Total number of mutations
# # CT = C > T changes
# # GA = G > A changes
# # Others = all other types of transitions and transversions combined.
MutMatrix <- data.frame(SampleID,
Ref_Base,
Alt_Base,
stringsAsFactors = F)
return.df <- data.frame(SampleID=NA,
Total=0,
CT=0,
GA=0,
Others=0)
for(SampleID in levels(MutMatrix$SampleID)){
set <- MutMatrix[ MutMatrix$SampleID == SampleID, ]
# if(dim(set)[1]==0){
# return.df <- rbind.data.frame(return.df,c(SampleID,0,0,0,0))
# next
# }
Total <- dim(set)[1]
CT <- dim(subset(set, set$Ref_Base == "C" & set$Alt_Base == "T"))[1]
GA <- dim(subset(set, set$Ref_Base == "G" & set$Alt_Base == "A"))[1]
Others=Total-CT-GA
return.df <- rbind.data.frame(return.df,list(SampleID,Total,CT,GA,Others),stringsAsFactors = F)
Total <- 0;CT <- 0;GA <- 0;Others <- 0 # re-initialize
rm(set)
}
return(return.df[-1,]) # Removes the first empty row
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment