-
Notifications
You must be signed in to change notification settings - Fork 0
/
proteinalignment.rb
182 lines (175 loc) · 6.11 KB
/
proteinalignment.rb
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/ruby
# Author Gaurav
# Universitat Potsdam
# Date 2024-4-4
# a ruby gem for all the alignment and the pattern
# extracttion from the alignments. It plots also the
# alignment length and also a three dimensional plot
# using the mRNA, cds, stop positions. complete support
# for the protein annotations and the alignment of the genome
# to the proteins and generation of the hints for the genome
# annotations.
gem install gr-plot
require 'gr/plot'
class PROTEINALIGNMENT
def initialize(alignmentfile, writemodifiedbuffer)
@alignment = alignmentfile
@modifiedbuffer = writemodifiedbuffer
readfile = File.open(@alignment).readlines
writefile = File.new(writemodifiedbuffer, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
end
def getcorrdinates(inputfile, outputfile, type)
if type == "mRNA"
columnread = []
start_cor = []
end_cor = []
readfile = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { | iter | end_cor.push(iter.strip().split()[4])}
mRNA = []
for i in 0..columnread.length
mRNA.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="mRNA"
end
return mRNA
end
if type == "CDS"
columnread = []
start_cor = []
end_cor = []
readfile = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { | iter | end_cor.push(iter.strip().split()[4])}
cds = []
for i in 0..columnread.length
cds.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="CDS"
end
return mRNA
end
if type == "stop_codon"
columnread = []
start_cor = []
end_cor = []
readfile = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { | iter | end_cor.push(iter.strip().split()[4])}
stop_codon = []
for i in 0..columnread.length
stop_codon.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="stop_codon"
end
return mRNA
end
end
def plotmRNAs(inputfile, outputfile)
if start == "mRNA"
columnread = []
start_cor = []
end_cor = []
fileopen = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { | iter | end_cor.push(iter.strip().split()[4])}
mRNA = []
mRNA_start = []
mRNA_end = []
mRNA_difference = []
for i in 0..columnread.length
mRNA.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="mRNA"
end
for i in 0..columnread.length
mRNA_start.push(start_cor[i].to_i) if columnread[i]=="mRNA"
end
for i in 0..columnread.length
mRNA_end.push(end_cor[i].to_i) if columnread[i]=="mRNA"
end
for i in 0..mRNA_start.length
mRNA_difference.push(mRNA_end[i].to_i - mRNA_start[i].to_i)
end
GR.barplot(mRNA_difference)
end
def plotCDS(inputfile, outputfile)
if start == "CDS"
columnread = []
start_cor = []
end_cor = []
fileopen = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { | iter | end_cor.push(iter.strip().split()[4])}
cds = []
cds_start = []
cds_end = []
cds_difference = []
for i in 0..columnread.length
cds.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="CDS"
end
for i in 0..columnread.length
cds_start.push(start_cor[i].to_i) if columnread[i]=="CDS"
end
for i in 0..columnread.length
cds_end.push(end_cor[i].to_i) if columnread[i]=="CDS"
end
for i in 0..mRNA_start.length
cds_difference.push(cds_end[i].to_i - cds_start[i].to_i)
end
return GR.barplot(cds_difference)
end
def plotstop(inputfile, outputfile)
if start == "stop_codon"
columnread = []
start_cor = []
end_cor = []
fileopen = File.open(inputfile).readlines
writefile = File.new(outputfile, "w")
writefile.puts(readfile[2..readfile.length])
writefile.close
fileopen = File.open(writefile)
fileopen.each { | iter | columnread.push(iter.strip().split()[2]) }
fileopen.each { | iter | start_cor.push(iter.strip().split()[3]) }
fileopen.each { iter | end_cor.push(iter.strip().split()[4])}
stop = []
stop_start = []
stop_end = []
stop_difference = []
for i in 0..columnread.length
stop.push([columnread[i].to_s,start_cor[i].to_i,end_cor[i].to_i]) if columnread[i]=="stop_codon"
end
for i in 0..columnread.length
stop_start.push(start_cor[i].to_i) if columnread[i]=="stop_codon"
end
for i in 0..columnread.length
stop_end.push(end_cor[i].to_i) if columnread[i]=="stop_codon"
end
for i in 0..mRNA_start.length
stop_difference.push(stop_end[i].to_i - stop_start[i].to_i)
end
GR.barplot(stop_difference)
end
def 3D()
GR.scatter3(mRNA_differences,cds_differences. stop_codon_differences)
end
end