Entering edit mode
5.6 years ago
imda
▴
10
I need your help. I have one folder that stores a lot of fasta alignment files. I want to use a program in R and run it for all the files that are stored in my folder. So, I do not know how to loop my script
Here I set my working directory
w.d <- '/share/Part1/icruz/data/orthofinder_all/all_solanaceas_protein_cds_correction/cafe_headers/Results_Apr15/cds_extractions/Rmultiplefiles'
setwd(w.d)
cds.fa <- read.fasta( '/share/Part1/icruz/data/orthofinder_all/all_solanaceas_protein_cds_correction/cafe_headers/Results_Apr15/cds_extractions/all_cds_solanaceae.fasta', seqtype="DNA", strip.desc=T, as.string=T )
# Here is the problem because I do not know how to read all the fasta files instead of set manually one by one
msa.aa <- read.fasta( '/home/icruz/data/orthofinder_all/all_solanaceas_protein_cds_correction/cafe_headers/Results_Apr15/cds_extractions/Rmultiplefiles/*.fa', seqtype="AA", strip.desc=T, as.string=T )
#Also I need to modify the headers in all my fasta files
names(msa.aa)
msa.san <- msa.aa
names(msa.san) <- sub("^.*_", "", names(msa.aa))
names(msa.san)
#THIS IS THE PROGRAM THAT I NEED TO LOOP once I have load all my fasta files
cds.msa <- alignCDSSetWithAlignedAAsAsGuide(cds.fa, msa.san)
first part reading multiple fasta files (at once) after setting working directory (where the fasta files are kept):
script saves each fasta file in individual data frames for each fasta file.