I am trying to run a basic biopython script to rename sequences within a fasta file. I have only ever ran this on a server; i am trying to do it on my macbook but I can't work out what the correct path to the file should be.
on the server is worked as follows:
original_file = r”/home/ggb_myname/Documents/Viromex/Viromex.contigs.fa”
I am trying to do the same thing on my mac with
original_file = r"/Users/u2188165/Documents/Home/Post-qiime/dna-sequences.fasta"
and it returns the error
FileNotFoundError: [Errno 2] No such file or directory: '/Users/u2188165/Documents/Home/Post-qiime/dna-sequences.fasta
I know this is probably basic, but I can't find the correct way to write the path, either on my own or online.
Try using libraries like pathlib
and os
. Makes your code more modular and os independent to use.
from pathlib import Path
import os
dir ="/Users/u2188165/Documents/Home/Post-qiime"
file= "dna-sequences.fasta"
full_path = os.path.join(str(Path(dir)), file)
Or even try drill down approach for more versatility.
from pathlib import Path
import os
path_drill = ["Users","u2188165","Documents","Home","Post-qiime"]
file= "dna-sequences.fasta"
full_path = str(Path(os.path.join(*path_drill, file)))
How/Where you want to store this is upto your imagination and requirements.
Happy coding!