|
| 1 | + |
| 2 | +#def indicates that it is a function definition |
| 3 | +def partA(gcCount): |
| 4 | + #sets teh variable count = to 0 so it can be added to |
| 5 | + count = 0 |
| 6 | + for i in gcCount: |
| 7 | + #looks for all indications of G and C |
| 8 | + if i == "G" or i =="C": |
| 9 | + #adds 1 to the count variable when a G/C is found |
| 10 | + count = count + 1 |
| 11 | + #returns the number of G/C bases |
| 12 | + return count |
| 13 | + |
| 14 | +#built-in random variable generator |
| 15 | +import random |
| 16 | + |
| 17 | +def partB(seq): |
| 18 | + #reads the file |
| 19 | + seq1 = seq.read() |
| 20 | + #puts it into lowercase |
| 21 | + seq1 = seq1.lower() |
| 22 | + bases = ['A','T','C','G'] |
| 23 | + num = input("Please input an integer ") |
| 24 | + num = int(num) |
| 25 | + for i in range(num): |
| 26 | + #determines a random postion in the file of bases and then replaces the base with a random base |
| 27 | + ranPosition = random.randint(0, len(seq1)-1) |
| 28 | + print("The nucleotide at the random postion " + str(ranPosition) + " was replaced") |
| 29 | + baseFin = random.choice(bases) |
| 30 | + seq2 = seq1[:ranPosition] + baseFin + seq1[ranPosition +1:] |
| 31 | + #returns thhe modified file |
| 32 | + return(seq2) |
| 33 | + |
| 34 | +def main(): |
| 35 | + seqGC = input('Please enter a sequence of bases. The G and C bases will be counted.') |
| 36 | + finCount = partA(seqGC) |
| 37 | + #str() converts the integer from the input to a string |
| 38 | + print("The GC count is " + str(finCount)) |
| 39 | + fileName = input("Please enter a file name ") |
| 40 | + #will try to open the file name thhat was input |
| 41 | + try: |
| 42 | + seq = open(fileName) |
| 43 | + #if the file cannot be opened the the print statement will run |
| 44 | + except: |
| 45 | + print("File cannot be read. Please try again.") |
| 46 | + exit() |
| 47 | + seq2 = partB(seq) |
| 48 | + print(seq2) |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + main() |
0 commit comments