Welcome back to Ori Finder!
In Part 1, we met Pyrococcus abyssi, an archaeon that lives in very hot deep-sea environments. We also learned that scientists have studied a small region of its chromosome where DNA copying begins. We know which organism we want to investigate and which DNA we need. Now, how do we get that DNA into our own Python project?
In Getting Started in Bioinformatics, we talked about how far a simple question can take you. Where does DNA copying begin on a circular chromosome? That’s one of many questions you could start with in bioinformatics.
You can follow Ori Finder as an example. We’ll get to know a few tiny organisms, learn how they copy their DNA, and write a little Python at a time to make sense of what we see. If you’re wondering how to start with a question of your own, I hope working through this one with us helps you find your first step.
As we build Ori Finder, that one question will give us a reason to learn how to:
- Read a circular chromosome and search across the place where the file wraps around.
- Find short DNA patterns and see where they appear on both strands.
- Look for groups of matches and check how close they are to the regions scientists have already studied.
- Try the same approach on other species and see where it works well and where it struggles.
By the time we finish version 1, we’ll have a working project and more questions to ask. Would a different pattern help us find a better candidate? Would the same search work on another species? Which part of the program could we make faster? If you write the code along with us, you’ll have your own copy to take in any of those directions. It would be lovely to see people try different ideas, share what they find, and build on each other’s work.
In This Part
This Part will be quick and maybe a little boring. We’re setting up the place where our Ori Finder tool will live. For Ori Finder to start its journey, we need a Python project and a way to open FASTA files and look at the DNA inside. That’s what we’ll set up together here. In the next Part, we’ll start writing our tool one algorithm at a time.
Part 1. Create Our Python Project
We’ll use VS Code / VSCodium, the editor we’ve used in our other series. It’s easy to get going, and it has plenty of extensions we can use later. What I like most is that we can write a little Python, run it, change something, and see the result right away. If you already have an editor you like, feel free to use it. You just need a way to run Python and select the project’s virtual environment, which we’ll create with uv below. We’ll check that uv works, use it to start the project, and run a welcome message. Once the editor is using the project’s Python, we can bring in our first FASTA file.
Open a new editor window. Choose File → Open Folder and go to the place where you keep your Python projects. Use New Folder in the folder picker to make a folder called ori-finder. Select that folder and open it. The file list on the left is called the Explorer. It will be empty for now. That’s exactly what we want.

Choose Terminal → New Terminal. The terminal is where we type commands. Since we opened our project folder first, the terminal starts there.
Install uv if you need it
Run uv --version. If you see a version number, you’re ready to create the project. If the terminal can’t find uv, use the command for your operating system.
On Windows, open PowerShell. If you have WinGet, run:
winget install --id=astral-sh.uv -eOn macOS or Linux, open a terminal and run Astral’s installer:
curl -LsSf https://astral.sh/uv/install.sh | shAfter installation, open a new terminal and run uv --version again. If it still can’t find uv, reopen your editor and check again. Astral’s installation guide has another Windows option if you don’t have WinGet.
Initialize the project
Back in the terminal for the ori-finder folder, type the command below and press Enter.
# Give this folder the files it needs to be a Python project.
uv init --app --no-packageWhen the terminal says the project was initialized, look at the Explorer. You should see a few new files, including main.py and pyproject.toml. We’ll open main.py next to check that Python runs.
Open the new main.py in the Explorer. Right-click it, choose Rename, and call it ori_finder.py. Replace the sample code with this line and save the file.
# Make sure we can run our Python file.
print("Welcome to Ori Finder v1!")Back in the terminal, run the file.
uv run ori_finder.pyWhen you see Welcome to Ori Finder v1!, you’ve got a working Python project. Take a moment to enjoy that. We’ll come back to this same file when it’s time to read the DNA.

If this is your first project with us, or your first time using uv, don’t worry about all those extra files in the Explorer. They’re there to help with the project. You can leave them as they are and follow along in ori_finder.py. Today we’ll open a real chromosome with Python. In the next Part, we’ll start writing the algorithms that help us ask questions about it.
If you’re curious about what the other files are for, we go through the setup in Genome Toolkit Part 4.2. You can read the article or watch the video whenever you’re ready.
Choose This Project’s Python
On the first run, uv creates a folder called .venv. Think of it as the place where Python and any extra tools for this project live. If the Python extension asks whether to use the newly created environment for this project, choose Yes. Keep your Python file open and check that the bottom bar shows the project’s .venv.

If you didn’t see the message, or you’d like to make sure the editor picked the right Python, here’s where to check.
- Open View → Command Palette and choose Python: Select Interpreter. If the command is missing, open Extensions and install the Python extension.
- Choose the entry marked .venv for
ori-finder. If you need to pick the file yourself, choose Enter interpreter path and select.venv/bin/pythonon Linux or macOS, or.venv/Scripts/python.exeon Windows. - Keep
ori_finder.pyopen and look for the Python version in the bottom bar. Check that it says .venv. If you only see a version number, click it to open the picker and check that the selected path is inside theori-finder/.venvfolder, like in the picture below.
If .venv still doesn’t show up in the picker, run uv run ori_finder.py once and check that it runs. Then restart the editor, open the ori-finder folder again, and go back to Python: Select Interpreter. Look for the project’s .venv and select it if the editor hasn’t already done so.

We’ll run our program from the terminal with uv run. If you’re curious about Code Runner, our editor setup video shows how to install it.
Part 2. Find Our Chromosome
So how do we get our hands on the right FASTA file? We want the whole chromosome of Pyrococcus abyssi GE5. Its reference number is NC_000868.1. That number helps us make sure we’re all looking at the same version of the DNA.
Get the file
If you cloned the Ori Finder repository for this lesson, the two FASTA files are already in its samples folder. If you’re building along from scratch, let’s download the full chromosome and put it there ourselves.
In the editor’s Explorer, choose New Folder and name it samples. You can download the FASTA file here or use the link below the video. Once you have the file, put it in samples and name it exactly NC_000868.1.fasta. If you already see that file in samples, you’re ready to open it.
Optional: Download from the NCBI record
If you’d like to see where the file comes from, you can get it yourself. Open the NCBI record for our chromosome. Look for the organism’s name and the number NC_000868.1, then follow these steps.
- Choose Send to → Complete Record → File.
- Choose FASTA as the format and click Create File.
- Put the download in
samplesand name itNC_000868.1.fasta.
Once the file is at samples/NC_000868.1.fasta, open it in the editor for a quick look. Then we’ll load it into Python together.
Part 3. Open Our First FASTA File
Open samples/NC_000868.1.fasta in the Explorer. If you’re new to FASTA, look for the greater than sign (>) at the very start. The text after it is the label. Here it gives us the ID NC_000868.1 and the name Pyrococcus abyssi GE5. The lines below the label hold the DNA letters in order.
>NC_000868.1 Pyrococcus abyssi GE5, complete sequence
GGGCTTTAGCCTCCTTCACCGCTTCCACGATTTTCTGCCTGTCAAAGGGCATTCTAGACATCCCTCCTTA
GGTTTTTAATTAAAAATTCAAGGTGGAGTAAAAAGGGATGTTTTTAAATTTTTCTCACTCTTTCTCGGCC
TTCTCAAATAGCTCGTCGTAAACCCCTTCATCTATTTCTCTCTGAACTTCCCTTGGATCCTTGCCTTCGAOn the NCBI record, the line marked LOCUS shows 1,765,118 bp. The line marked VERSION gives us NC_000868.1. We’ll use both values to check the file in Python. The FASTA header gives us the reference name, and the DNA lines give us the letters to count. The first check helps us catch a file for a different record. The second helps us catch a file with a different number of letters. We’re showing just the first three DNA lines here. Next, let’s see if Python can read the whole file.
You can also open the live GenBank text on NCBI to see those same lines.
Part 4. Read the Chromosome With Python
We can already see the DNA in the editor. How do we get it into our program? We could copy and paste a few letters by hand, but imagine doing that for a whole chromosome each time we want to try an experiment. Python can already open the file as text. Let’s add a reader to Ori Finder that understands the FASTA layout and gives us the label and the DNA letters.
Reading the file is a job we’ll need again and again. We call a function that takes care of a job like this a helper function. Our helper does one small job. It opens a FASTA file so we can use its label and letters in Python. We’ll keep our file helpers together in helpers.py so we can use them from any experiment we write. Our first trusty helper will be read_fasta(). We give it a file name, and it gives us the label and the assembled DNA sequence. Researchers already put many short reads together to build that sequence. It’s spread over many lines in the FASTA file, so our helper puts those lines back into one long string.
We’ve written a small FASTA reader before in DNA Toolkit. Genome Toolkit Part 4.5 shows another approach for large files. It reads records one at a time, so you can look for a record without loading all the other sequences into memory. Both links are optional. We’re building Ori Finder from scratch as a standalone project. Our file holds one sequence, so we’ll write a small reader that reads the label, collects the DNA lines, and joins them.
In the Explorer, choose New File and name it helpers.py. Put it in the same folder as ori_finder.py. We’ll keep small jobs we can reuse in this file. The first one reads a FASTA file and gives us two things: the label and the DNA letters. Later, we’ll add a second helper that saves a FASTA file.
def read_fasta(filename):
"""Read one DNA sequence from a FASTA file."""
# 1. Open the file as text using UTF-8.
with open(filename, encoding="utf-8") as fasta_file:
# 2. Read the label and check that it starts with >.
# Read that first line before we start collecting DNA.
header = fasta_file.readline().strip()
if not header.startswith(">"):
raise ValueError("FASTA needs a description line.")
# 3. Read the DNA one line at a time.
# strip() removes spaces at the ends and the line break.
dna_lines = []
for line in fasta_file:
dna_lines.append(line.strip())
# 4. Join the lines so Python can work with one long sequence.
# Use uppercase letters so we can check them against A, C, G and T.
dna = "".join(dna_lines).upper()
if not dna or any(letter not in "ACGT" for letter in dna):
raise ValueError("Expected DNA made from A, C, G and T.")
# 5. Give back the label without > and the sequence separately.
return header[1:], dnaThis might look like a lot of Python at first. Take it one step at a time. The job itself is simple.
- Open the file. We give the function a file name.
open()opens that file as text using UTF-8, a common way to store text. Thewithblock closes it for us when we’re done reading. - Read the label. We read the first line and look for
>, the mark at the start of a FASTA label. Look atif not header.startswith(">"). Thestartswith()check looks at the beginning of the line. You can almost read that aloud. If the label doesn’t start with>, tell us something is wrong. - Collect the DNA. We already read the first line and saved it in
header. The open file remembers where we stopped. The loop carries on at line two and reads the rest of the file one line at a time.strip()takes off the line break and any spaces at the ends.append()adds the cleaned line to the end of our list, so the pieces stay in the order we read them. - Join and check the letters.
join()puts all the lines together. We join them with an empty string so there’s nothing between the pieces.upper()turns a lowercaseaintoA, for example, so we can check every letter the same way. - Give back two things. We return the label without
>and the assembled DNA sequence. Now we can keep track of which DNA we loaded and pass just the sequence to an algorithm.
It almost feels as if Python was made for little bioinformatics jobs like this. If you’re curious about any of these tools, click its name for a quick detour into the official Python docs. You can come back and carry on whenever you’re ready.
This is why it pays to learn the basics of Python as we go. If you know these tools are there, you can spend less time writing and checking code that does the same work by hand. And when you read the function again, you can see what it’s doing. We take the same approach in DNA Toolkit and Genome Toolkit. Start with a real question, learn the Python that helps, and put it to work.
Once we run it on the chromosome file, we’ll have the whole DNA sequence in Python. We can pass those letters straight to an algorithm, like the one we’ll use to count a pattern in Part 3.
Save helpers.py. Now open ori_finder.py and replace the welcome message with the experiment below. The import line brings read_fasta() over from our helper file. This is where we choose which DNA to look at and what to print.
# 1. Bring in Path and our FASTA reader.
from pathlib import Path
from helpers import read_fasta
# 2. Read the complete chromosome from the samples folder.
genome_path = Path("samples/NC_000868.1.fasta")
genome_name, genome = read_fasta(genome_path)
# 3. Check that we opened the chromosome we expected.
if "NC_000868.1" not in genome_name or len(genome) != 1_765_118:
raise ValueError("Please check the complete NC_000868.1 FASTA file.")
# 4. Show the label, total length, and first 60 DNA letters.
print("Reference:", genome_name)
print("Chromosome bases:", len(genome))
print("First 60 DNA letters:", genome[:60])We just taught Python how to read a FASTA file. Now let’s give it a real chromosome and see what comes back. If you’re new to Python, take it one number at a time.
- Use the reader we just wrote. Find
from helpers import read_fastaat the top. Read it like a little note to Python. Go tohelpers.pyand getread_fasta()for us. The other import gives usPathfrompathlib. Think of a path as the address of a file. Here, the address says to go intosamplesand openNC_000868.1.fasta. When someone runs the program from their ownori-finderfolder, Python looks in their copy ofsamples. We can share the same code without writing anyone’s full folder address into it. - Open our FASTA file. Remember where we put the download? That’s the file name we give to
read_fasta(). Look back atreturn header[1:], dnainhelpers.py. The return order tells us which value goes where.genome_namegets the label first, thengenomegets the DNA letters. Now we have a name we can print and a sequence we can work with. - Make sure it’s the chromosome we came for. We know two things before we run the code. The label should include
NC_000868.1, the version shown by NCBI. The sequence should have 1,765,118 letters, the length from the record’sLOCUSline. We write it as1_765_118in the code so it’s easier to read at a glance. Python gives it the same value as1765118. If either one looks wrong, the program stops and tells us to check the file. You can go back to the download and see whether you saved the complete record. - Take a first look. A million letters would be a lot to scroll through. Let’s use
print()to show the label andlen()to get the total, then show just the first 60 letters. That’s whatgenome[:60]asks for. When you see those letters in the terminal, you can compare them with the FASTA you opened earlier. You’ve just read a real chromosome with your own Python code.
Save the file and run the program again.
uv run ori_finder.pyHere’s what we see in the terminal.
Reference: NC_000868.1 Pyrococcus abyssi GE5, complete sequence
Chromosome bases: 1765118
First 60 DNA letters: GGGCTTTAGCCTCCTTCACCGCTTCCACGATTTTCTGCCTGTCAAAGGGCATTCTAGACAFind the first few DNA letters in the FASTA you opened earlier. Do they match what Python printed? Now try changing genome[:60] to genome[:20] and run it again. The preview gets shorter. The total stays at 1,765,118 because Python still has the whole chromosome. You can put the preview back to 60 when you’re ready.
Part 5. Save the 799 Letters We’ll Study
Now let’s return to our second scientific source. DoriC collects information about origins of replication, the places where cells begin copying their DNA. Researchers studied a region on the same chromosome we already loaded. For this chromosome, its historical record aORI10010003 lists 122701 to 123499 in the row called Reported experimental region. In that same row, check the source accession. It is NC_000868.1, the same version we opened earlier.
This 799-base region is connected to earlier research on where DNA copying begins. You can also read the original regional replication study that we introduced in Part 1. We’re preparing a known sample to help us check our experiments. Use the Reported experimental region row for this lesson. DoriC also lists an OriC annotation with a different start. Our sample follows the reported experimental interval.
Why start with this little piece when we have the whole chromosome? We already know which region researchers studied, so we have somewhere to start. When we try our first counting functions, we can look closely at the patterns they find. Later we can ask a bigger question. Can our tool find a promising region when we give it the whole chromosome to search?
Let’s store those two positions in ori_finder.py, where we already have the full chromosome in genome. We’ll take a slice from that string and use our FASTA writer to save the slice separately. Give each position a name before using it. If you open this project a month from now, p_abyssi_ori_start tells you what the number is for. The name also helps when we bring in DNA from another species.
We’ll keep the numbers as DoriC shows them. DoriC counts from 1 and includes both ends. Python counts from 0 and stops just before the end of a slice. So we subtract 1 from the start and use the end as it is. Counting both ends gives us 123499 - 122701 + 1 = 799 letters. The extra one counts the first position as well as the last.
How do we keep these 799 letters for next time? We could find the positions and copy the letters by hand, but we’d repeat that work each time we prepared a sample. Let’s add write_fasta() to helpers.py. The experiment takes a slice from the full chromosome. The writer takes those letters, a label and a file name, then saves them in the FASTA layout we just learned to read. We can open the smaller file directly in the next experiment. The full chromosome is still there for when we need it. Add the function below at the bottom of the file.
def write_fasta(filename, label, dna):
# 1. Open the new FASTA file so we can write to it.
with open(filename, "w", encoding="utf-8") as fasta_file:
# 2. Write the label on the first line.
fasta_file.write(">" + label + "\n")
# 3. Write 60 DNA letters per line.
for start in range(0, len(dna), 60):
fasta_file.write(dna[start:start + 60] + "\n")The writer takes three things. The file name tells it where to save, the label tells us what’s in the file, and the sequence gives it the letters to write.
- Open the file for writing. The
"w"tells Python to write. It creates the file if needed and replaces its contents if we run the example again. - Give it a label. We put
>in front and add\nat the end. That starts a new line for the DNA. - Write the sequence.
range()gives us the starting points 0, 60, 120, and so on. The loop moves ahead 60 letters each time. Adding\nafter each piece gives us the familiar FASTA layout when we open the file. If fewer than 60 letters are left, the last line is shorter.
Back in ori_finder.py, change the import to from helpers import read_fasta, write_fasta. Then add this below the full chromosome print statements.
# 1. Keep the DoriC positions for P. abyssi, then take those letters.
p_abyssi_ori_start = 122_701
p_abyssi_ori_end = 123_499
p_abyssi_ori_region = genome[p_abyssi_ori_start - 1:p_abyssi_ori_end]
# 2. Give the sample its own file and label, then save it.
sample_path = Path("samples/NC_000868.1_known_ori_799.fasta")
sample_label = "P_abyssi_GE5_NC_000868.1_known_ori_region_799bp"
write_fasta(sample_path, sample_label, p_abyssi_ori_region)
# 3. Read the new file and check it against our sample.
sample_name, sample_dna = read_fasta(sample_path)
if len(sample_dna) != 799 or sample_dna != p_abyssi_ori_region:
raise ValueError("The saved sample does not match our known region.")
# 4. Show the label, length, and first 60 letters of the sample.
print("Known sample:", sample_name)
print("Known-region bases:", len(sample_dna))
print("First 60 sample letters:", sample_dna[:60])- Pick the region. The names tell us which organism these positions belong to. We can compare the numbers with DoriC right in the code. The slice takes the 799 letters and gives them the name
p_abyssi_ori_region. The whole chromosome is still available ingenomewhen we want to search it later. - Save the sample.
sample_pathgives the writer the new file’s address insamples.sample_labelidentifies what we saved.p_abyssi_ori_regionsupplies the letters we just took from the chromosome. We pass all three towrite_fasta()so the sample has its own file and we can keep the original too. - Read it back. We use
read_fasta()again. We check both the length and the letters themselves. A file can have 799 letters and still contain the wrong sequence. - Look at the result. The label tells us which file we opened, and the length and preview give us something to compare with the FASTA in the editor.
Run uv run ori_finder.py once more. Below the full chromosome output, you’ll see the new sample.
Known sample: P_abyssi_GE5_NC_000868.1_known_ori_region_799bp
Known-region bases: 799
First 60 sample letters: GACCTAAATTTCCAGTGGAAACATAACACTTTTCGCTAACATATTTTCATTGTGCATGACOpen the new file in samples/ and compare its first few letters with the terminal. We’ve used the same reader twice, first on the whole chromosome and then on the file we just made. We’ve turned a region inside a chromosome with more than a million letters into a separate file. Now we can work directly with that smaller sample. For another known region, we can reuse the same steps when we have its positions. The whole chromosome is still there whenever we need it.
Part 6. Look at Our Project So Far
Let’s look at the files we used today. These are the ones you’ll want to find when we come back for the next experiment.
ori-finder/
├── pyproject.toml # Python project settings from uv
├── helpers.py # Reads and writes FASTA files
├── ori_finder.py # Runs our experiment
└── samples/
├── NC_000868.1.fasta # Complete P. abyssi chromosome
└── NC_000868.1_known_ori_799.fasta # Our smaller known-region sampleThe setup files we saw after the first run are still in the project. This small tree shows the files we worked with today. Our algorithms.py file will arrive when we actually need our first algorithms. For now, we have a program that can read real DNA, keep the original chromosome, and give us a small sample for experiments.
Summary
Look at what we’ve done already. We’re only in Part 2, and we’ve already done some bioinformatics together.
- In Part 1, we met a few tiny organisms with circular chromosomes. Out of all the questions we could ask about them, we picked one. Where does DNA copying begin on a circular chromosome?
- In this Part, we set up our Python project, went to a public database, and downloaded the complete chromosome of P. abyssi.
- We loaded that DNA into our program and saved the 799 letters we’ll study first. We opened both files with the same little Python function.
I think it’s amazing that we can do this together. People around the world worked to read this DNA, check the sequence, and share it so anyone could study it. We get to pick up where they left off and build on what they shared. That’s part of what makes open science and open-source work so special.
Now we can ask a question in plain English and write a little Python to help us answer it. That’s what we talked about in Getting Started in Bioinformatics. A simple question can lead us, step by step, into a real project. And each answer can give us a bigger question to try next.
I hope Ori Finder helps you see how you could start a project of your own. There are so many things to get curious about in biology, chemistry, and physics. You can start with one that makes you stop and think, I wonder how that works.
What’s Next?
We can now read the DNA. In Ori Finder Part 3, we’ll start asking it questions.
- Bring our two familiar counting functions into a new file called
algorithms.py. - Try both functions on a tiny DNA sequence, where we can check the answers by hand.
- Run them on our 799-letter sample and see which patterns turn up.
If you’d like a quick refresher, here’s where we first wrote those functions.
- Genome Toolkit Part 2, counting one pattern
- Genome Toolkit Part 3, finding the most frequent patterns
Your Turn
Now that you can load the DNA, see if you can work out how to start looking for patterns.
- How would you search the 799 letters we saved? What tiny sequence would you use to check your answer by hand first?
- If you remember the two Genome Toolkit functions, you can get a little head start. Try bringing them into
algorithms.pyand calling them fromori_finder.pywith the DNA you’ve already loaded.
If you’re still thinking about how to do that, you’re right where we need you to be. We’ll do it together in Part 3.
If you found this Part useful for your bioinformatics and Python journey, and you’d like to help us keep creating free, open-source science education, you can support REBELSCIENCE. Your support helps us share what we learn and grow our community.
Project Files
You can find the complete code for this lesson in the Ori Finder Part 2 repository. The samples folder includes both the complete chromosome FASTA and the 799-letter origin sample. You can also get the chromosome directly from NCBI using the steps above.
Until next time, rebelCoder, signing out.
Git repository for this lesson: Ori Finder on GitHub.
Video version of this article:

Loading the conversation…