How to write a i in loop for readfastq function
3
0
Entering edit mode
8.7 years ago

Hi guys,

I try to read fastq files from a RNA-Seq result. I had 19 fastq files, but the manual of ShortRead said "Methods read all files into a single R object; a typical use is to restrict input to a single FASTQ file."

I do not know how to write a i loop to make one vector for all the 19 files. Could you kindly help, please? Many thanks,

Jerry

Below is what I write, I guess is kind of stupid....

fastqFilesdir <- dir("/Users/jerry/Desktop/RStudio/Key/fastq/fastq", full=TRUE)

fq1<- readFastq(fastqFilesdir[1])

fq2<- readFastq(fastqFilesdir[2])

fq3<- readFastq(fastqFilesdir[3])


...

fq18<- readFastq(fastqFilesdir[18])

fq19<- readFastq(fastqFilesdir[19])
RNA-Seq • 2.9k views
ADD COMMENT
1
Entering edit mode
8.7 years ago

You have to provide a pattern as a parameter to readFastq function. Read the parameter descriptions, you don't have to write a loop.

UPDATE: this is what you need, pattern works like grep search.

fq=readFastq('/Users/jerry/Desktop/RStudio/Key/fastq/fastq',pattern='.q$')
ADD COMMENT
0
Entering edit mode

Dear Sukhdeep Singh,

I used this code as well:

fq1<- readFastq("/Users/Jerry/Desktop/RStudio/Key/fastq/fastq", pattern = "jerry_S1_L001_R1_001.fastq")

It provides same result as above. All the 19 files are in the dirpath "/Users/Jerry/Desktop/RStudio/Key/fastq/fastq", but each file name is different, from "jerry_S1_L001_R1_001.fastq" to ""jerry_S1_L019_R1_001.fastq".

May I ask how to write pattern to includes all the 19 files, please? Thank you~

ADD REPLY
0
Entering edit mode

This is very easy, if you read the parameter information carefully. I don't have the package installed to test it for you.

ADD REPLY
0
Entering edit mode

I updated the answer, should work for you. Be careful, it might bog down your machine, depending on the size of files that you are reading in + a single S4 object in R will contain all the information from all files, this will be heavy duty!!

ADD REPLY
0
Entering edit mode
8.7 years ago
Pol ▴ 70

Try this (since I don't have the program to check it, it is possible the presence of a little mistake in the code):

COUNTER=1
while [  $COUNTER -lt 19 ]; do
             fq"$COUNTER"<-readFastq(fastqFilesdir["$COUNTER"])
             let COUNTER=COUNTER+1 
done
ADD COMMENT
0
Entering edit mode

Thank you Pol, but I use R for coding.

ADD REPLY
0
Entering edit mode

I'm sorry I was working with bash when I read your post and I didn't see that you where asking about R

ADD REPLY
0
Entering edit mode
8.7 years ago

I figure out it. Just need to define a list container fastfilelist, Like this:

fastqFilesdir <- dir("/Users/Jerry/Desktop/RStudio/Key/fastq/fastq", full=TRUE)

fastfilelist= list()

for (i in c(1:19) ) {

fastfilelist[i]<- readFastq(fastqFilesdir[i])

}

ADD COMMENT

Login before adding your answer.

Traffic: 1710 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6