python cicling on a list of mini fastq
1
0
Entering edit mode
9.2 years ago

Hi, I wrote these few lines to create different file of the same extension.

I was wondering if there is a better way to perform this task!

In my folder I have all the items of mylist and a xaa.sh file. Starting from this one I want to obtain all these files .sh.

mylist= ["xaa","xab","xac","xad","xae","xaf","xag","xah","xai"]

for el in l:
    f=file("xaa.sh","r")
    a=f.read()
    b=a.replace("xaa",el)
    f=file(el+".sh","w")
    f.write(b)

Thanks!

sequence • 1.6k views
ADD COMMENT
0
Entering edit mode

Hello damiano.bassani!

We believe that this post does not fit the main topic of this site.

Not really a bioinformatics question, this is about either python or shell scripting. Context has since been added in a comment, making this somewhat more relevant (those disagreeing are free to revert my reopening).

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLY
0
Entering edit mode
9.2 years ago

As I mentioned, this isn't really a bioinformatics question. There's also no reason to do this in python, just use cp.

Regarding your actual script, you only need to perform f.read() once, so move it outside of the for loop.

ADD COMMENT
0
Entering edit mode

OK sorry I'll try to be more clear:

I have split a big fastq file in more little fastq:

split -l 50000 fastqfile.fastq

this split the big fastq producing different fastq file of 50000 lines:

"xaa","xab","xac","xad","xae","xaf","xag","xah","xai" (fwith split command they don't have extension but they actually are .fastq )

then I write two command in a xaa.sh file for get the fasta from the fastq and then blast it.

Now, I would write a script in python top avoid to do this task for each mini-fastq.

My script actually works fine! I was only looking for a better alternatives!

ADD REPLY
0
Entering edit mode

OK, given the extra context this becomes a bit more relevant and I've reopened the post.

I would actually just perform the iteration in the bash script. You would then only have a single script.

ADD REPLY
0
Entering edit mode

Sorry. Actually there is only a command to blast the sequence:

cd /my/path/folder/

/my _path_to_folder/blastn -query xaa.fa -db /my_path_to_folder/nr_nt_db/nt -out xaa.xml -outfmt 5 -num_threads 12 -evalue 0.00001 -max_target_seqs 20

gzip xaa.xml

ADD REPLY
0
Entering edit mode

A single script alternative would be something like

cd /some/path
for f in x??.fa
do
    bname=${f%%.fa}
    oname=$bname.xml
    blastn -query $f -db someDB -out $oname -outfmt 5 -num_threads 12 -evalue 0.00001 -max_target_seqs 20
    gzip $oname
done
ADD REPLY
0
Entering edit mode

Thanks!

Sorry if I was not clear at the beginning!

ADD REPLY
0
Entering edit mode

No worries!

ADD REPLY

Login before adding your answer.

Traffic: 2665 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