Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How are paths meant to be denoted on for Biopython on mac?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading