Skip to content

Commit

Permalink
Create GC calculator with a single sequence as input
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinsorchid committed Jun 18, 2024
0 parents commit 3accb9f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions gc_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ===================================================== DEPENDENCIES =============================================================
from Bio.Seq import Seq
from Bio.SeqUtils import gc_fraction
from matplotlib import pyplot as plt
plt.style.use('ggplot')


# ===================================================== FUNCTIONS =================================================================
def calculate_gc(sequence):
print(gc_fraction(sequence))

def calculate_window_gc(sequence, window, step):
gc_parts = []
window_count = 0
window_list = []
for i in range(0, len(sequence) - window +1, step):
gc_part = gc_fraction(sequence[i: i+window])
gc_parts.append(gc_part)
window_count +=1
window_list.append(f"Window {window_count}")
return window_list, gc_parts

def create_window_plot():
x_axis, y_axis = calculate_window_gc(sequence, window_size, step_size)
plt.plot(x_axis, y_axis, color = "k", linestyle = "--", marker = "o")
plt.title("Sliding Window GC Content Calculation")
plt.xlabel("Sequence windows")
plt.ylabel("GC content")
plt.tight_layout()
plt.show()

# ====================================================== LOGIC =====================================================================
sequence = Seq(input('Please enter a DNA/RNA sequence. '))

choice = input("Would you like to perform a sliding window GC content calculation? ")
if choice.lower()[0] == 'n':
calculate_gc(sequence)
else:
window_size = int(input("Please enter window size. "))
step_size = int(input("Please enter step size. "))
create_window_plot()






0 comments on commit 3accb9f

Please sign in to comment.