forked from araiho/Intro_Biocomp_ND_317_Tutorial8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerciseScript8_1.R
More file actions
30 lines (28 loc) · 1.22 KB
/
Copy pathExerciseScript8_1.R
File metadata and controls
30 lines (28 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## Keith O'Connor Excercise 8 Problem #1
## This code will find and change the names of files from Florida and Texas to a set naming scheme (elseif statement in for loop).
## Then it will simplify the allele data to allele counts (else part of for loop)
## This is then exported to a new file called "CfloridaCounts.txt"
library('stringr')
## Import Data
Cflorida <- scan("~/Desktop/data-shell/Intro_Biocomp_ND_317_Tutorial8/Cflorida.vcf",what=character(),sep = "\n")
#creates an empty file
file.create("CfloridaCounts.txt")
## Regular Expressions! Yay! The first two are standardize the naming.
## The third regular expression is to find the allele counts for each individual.
TX <- "[Cc][Ff](07)?\\.[Aa]2?"
FL <- "[Cc][Ff]\\.(G2|GAI|gai)"
SNP <- "[01.]/[01.]:([0-9.,]+):[0-9.]+:[0-9.]+:[0-9,.]+"
for(i in 1:length(Cflorida)){
if(i==1){
Header <- Cflorida[1]
write(Header,file="CfloridaCounts.txt",append=TRUE)
}else if (i==2){
TXE <- str_replace_all(Cflorida[2],TX,"Cf.Sfa")
FLE <- str_replace_all(TXE,FL,"Cf.Gai")
write(FLE,file="CfloridaCounts.txt",append=TRUE)
} else{
AL <- str_replace_all(Cflorida[i],SNP,"\\1")
NSA <- str_replace_all(AL,"\\.","NA")
write(NSA,file="CfloridaCounts.txt",append=TRUE)
}
}