Question: python cicling on a list of mini fastq
0
gravatar for damiano.bassani
4.6 years ago by
Italy
damiano.bassani10 wrote:

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 • 808 views
ADD COMMENTlink written 4.6 years ago by damiano.bassani10

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 REPLYlink modified 4.6 years ago • written 4.6 years ago by Devon Ryan92k
0
gravatar for Devon Ryan
4.6 years ago by
Devon Ryan92k
Freiburg, Germany
Devon Ryan92k wrote:

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 COMMENTlink written 4.6 years ago by Devon Ryan92k

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 REPLYlink written 4.6 years ago by damiano.bassani10

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 REPLYlink written 4.6 years ago by Devon Ryan92k

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 REPLYlink written 4.6 years ago by damiano.bassani10

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 REPLYlink written 4.6 years ago by Devon Ryan92k

Thanks!

Sorry if I was not clear at the beginning!

 

ADD REPLYlink written 4.6 years ago by damiano.bassani10

No worries!

ADD REPLYlink written 4.6 years ago by Devon Ryan92k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 984 users visited in the last hour