Entering edit mode
2.9 years ago
Phoebe Magdy
•
0
Dear all I have a problem while using seqkit tool command in python jupytar notebook? I was trying to convert some fastq files to fasta files with the simple command:
seqkit fq2fa file_name.fastq -o file_name.fa
or the command:
seqtk seq -a file_name.fastq > output.fasta
But unfortunately in both cases I got the error:
File "<ipython-input-1-88778dbee2d4>", line 1
seqkit fq2fa file_name.fastq -o file_name.fa
^
SyntaxError: invalid syntax
but these commands worked on a bash terminal properly...!
Is there is any way to loop over multiple fastq files in a directory and convert them to fasta files in python jupyter nootbook?
Many thanks actually applying your suggestion worked when I tried to apply it on a single file but when I tried to put it in a loop to convert all files at once I got an error,
Any suggestions for the loop to work properly..??
Many thanks in advance
Please post error next time.
Try this:
!find /home/phoebemagdy/workdir/PhD/1st_PhD_Trial_Code/Ecto_Data/ -type f -name "*.fastq" | while read line; do echo seqkit fq2fa $line -o ${line/.fastq/}_new.fastq; don
eYou don't need to declare directory or extension outside shell. There are three issues here. file is a python variable, not a shell variable. Second issue would be after passing python variable to shell (using {}), it would still print file name only, not file path, due to which command would fail again. Thirdly, you would not have control over extension and renaming unless you write more python code, to remove file extension and add extra text and extension. Hence it is better to do entire operation in shell as I mentioned above.
If you want to continue above way (OP), try this:
(beware of tabs while copy/pasting)
Many thanks your suggestions worked very properly and converted all my fastq files to fasta files. Really appreciate your help, and I'm highly grateful for the tips you wrote it really clarified a lot of mistakes I was falling in, once again thanks alot