Entering edit mode
5.6 years ago
archana.bioinfo87
▴
210
Hi, I am trying to extract few sequnces from a csv file. I am unable to save the result. The for loop is working once.
fasta <- read.csv("trial_seq.csv", header = TRUE, sep =",")
fasta
a<- as.character(fasta$Seq)
a ###original file
b = matrix(nrow=6, ncol=10)
for (i in 1:length(a)){
for ( j in 1:nchar(a[i])) ######Succesfully extract 2-6 nt from start postion
{
b[j] <- substr(a, (j-(j-1)), j+1)
ifelse ((j<=5),{print(b[j])}, break())
}
}
b
#####################File stored in "a"
[1] "ACGTATTGATGCCACAGACGTATTGATGCCACAGACGTATTGATGCCACAG"
[2] "ACGTATTGATGCCACAGACGTATTGATGCCACAGACGTATTGATGCCACCC"
[3] "ACGTATTGATGCCACAGACGTATTGATGCCACAGACGTATTGATGCCACTT"
Any help is much appreciated.
Thanks
Can you give a representative example of the input (ok you did that already) and the expected output. I am 99.99% sure this can be done with a simply one-liner avoiding any loop and if statements.