Last active
August 29, 2015 14:01
-
-
Save ROODAY/9a14778a292a93832dfe to your computer and use it in GitHub Desktop.
IntreXon Prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileToRead = input("Type in the name of the data file: ") | |
dataFile = "data/" + str(fileToRead) | |
totalExons = int(input("Type in the total number of exons: ")) | |
totalIntrons = int(input("Type in the total number of introns: ")) | |
exonNumber = 0 | |
intronNumber = 0 | |
exon = chr(58) | |
intron = chr(45) | |
print(dataFile + " will be used. Total number of exons is " + str(totalExons) + ", total number of introns is " + str(totalIntrons) +".") | |
with open(dataFile, "r+") as data: | |
dataArray = data.read().splitlines() | |
printOption = input("Would you like to see data by line? y/n ") | |
if printOption == "y": | |
dataByLinePosition = 0 | |
while dataByLinePosition < len(dataArray): | |
print(dataArray[dataByLinePosition]) | |
dataByLinePosition += 1 | |
dataLine = 0 | |
shouldOutputInProgress = input("Would you like to see output in progress? y/n ") | |
while dataLine < len(dataArray): | |
linePosition = 0 | |
line = dataArray[dataLine] | |
while linePosition < len(line): | |
if ord(line[linePosition]) == 58: | |
exonNumber += 1 | |
elif ord(line[linePosition]) == 45: | |
intronNumber += 1 | |
if shouldOutputInProgress == "y": | |
print("Total Base Pairs in Exons(%s): %s, Total Base Pairs in Introns(%s): %s" % (str(exon), str(exonNumber), str(intron), str(intronNumber))) | |
linePosition += 1 | |
dataLine += 1 | |
print("Analysis of %s: Average Exon Length: %s, Average Intron Length: %s" % (str(dataFile), str(round(exonNumber / totalExons)), str(round(intronNumber / totalIntrons)))) | |
data.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created for a biology project which involved finding the average length of exons and introns in a gene. I'm too lazy, however, to count each one individually so I used the alignment that the San Diego Supercomputer center creates with two sequences and then whipped up this script that looks for any colons and dashes in the data. Colons represent base pairs in an exon, dashes represent base pairs in an intron. And if you're wondering why I went out of the way to use use two symbols in the shouldOutputInProgress if statement's print, I just wanted to confirm I was using the correct ASCII character codes.