dimanche 5 juillet 2020

Is there a way to group polymorphisms between genes into both gene categories using R and the ifelse function?

I have two datasets. One is a list of genes that shows the nucleotide positions of each gene.

For example:

    Gene Name  Low Position   Upper Position
    Gene 1       1000           2000
    Gene 2       5000           6000

The other dataset is a list of polymorphisms and their nucleotide positions

For example:

           Position  Gene Location
    SNP 1   3000       NA
    SNP 2   5500       NA

I have used the ifelse function in R to sort my dataset of polymorphisms into their respective genes (so SNP 2 would have Gene 2 in its "Gene Location" column). The code I used was:

   SampleGeneData$Gene.Name=as.character(SampleGeneData$Gene.Name)
   SampleSNPData$Gene.Location=ifelse(sapply(SampleSNPData$Position,function(p) any(SampleGeneData$Low.Position<=p&SampleGeneData$High.Position>=p)),SampleGeneData$Gene.Name,"NO")

I was wondering if it was possible to also define the Gene Location as both of the genes that the SNP is located in between (so SNP 1 would have some output of "Gene 1 and Gene 2" or something similar). Could I do this with the ifelse function or would I have to use something else?

Aucun commentaire:

Enregistrer un commentaire