forked from lyy005/Intro_Biocom_ND_319_Tutorial7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise7Part1.py
More file actions
executable file
·29 lines (22 loc) · 1.13 KB
/
Copy pathExercise7Part1.py
File metadata and controls
executable file
·29 lines (22 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Part 1
import pandas
from plotnine import *
InFile=open("Lecture11.fasta","r") #Open fasta file as read-only
sequenceLength=[] #Set up variables to accept/store sequence data as it is calculated
percentGC=[]
for line in InFile: #Loop through each line in fasta file
if '>' in line: #Check line for >, if present, skip to next line
continue
else:
seqLen=float(len(line)) #Calculate length of sequence
nG=line.count("G") #Count individual G and C contents
nC=line.count("C")
percGC=float(((nG+nC)/seqLen)*100) #Calculate % GC
sequenceLength.append(seqLen) #Append length of individual sequences to list
percentGC.append(percGC) #Append %GC of individual sequences to list
seqDF=pandas.DataFrame(list(zip(sequenceLength,percentGC)),columns=['sequenceLength','percentGC']) #combine lists into dataframe for easier plotting
a=ggplot(seqDF, aes(x="sequenceLength")) #Create plot of sequence lengths
a+geom_histogram()+theme_classic() #Plot as histogram
b=ggplot(seqDF, aes(x="percentGC")) #Create plot of %GC
b+geom_histogram()+theme_classic() #Plot as histogram
InFile.close() #Close file