File: trna2tbl.rb

package info (click to toggle)
ncbi-tools6 6.1.20120620-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 241,628 kB
  • ctags: 101,236
  • sloc: ansic: 1,431,713; cpp: 6,248; pascal: 3,949; xml: 3,390; sh: 3,090; perl: 1,077; csh: 488; makefile: 449; ruby: 93; lisp: 81
file content (125 lines) | stat: -rwxr-xr-x 2,051 bytes parent folder | download | duplicates (8)
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
#! /usr/bin/ruby

# subroutines

def firstnum str
  a = str.index('(')
  b = str.index('-')
  loc = str.slice(a + 1 .. b - 1)
  loc.to_i
end

def lastnum str
  c = str.index('-')
  d = str.index(')')
  loc = str.slice(c + 1 .. d - 1)
  loc.to_i
end

def getaa str
  x = str.index(' ')
  y = str.index("\t")
  loc = str.slice(x + 1 .. y - 1)
  loc.to_s
end

def getid str
  z = str.index('.trna')
  loc = str.slice(0 .. z - 1)
  loc.to_s
end

# main program

idnotsent = true

st = 0;
sp = 0;
inst = 0
insp = 0
acst = 0
acsp = 0
id = ''
aa = ''
pseudo = false

name = gets

while name
  name = name.chomp

  if name.index('Seq:') != nil

    if idnotsent
      puts '>Features ' + id + ' tRNAscan-SE'
      idnotsent = false
    end

    if inst == 0 and insp == 0
      puts st.to_s + "\t" + sp.to_s + "\t" + "tRNA"
    else
      inst = inst - 1
      insp = insp + 1
      puts st.to_s + "\t" + inst.to_s + "\t" + "tRNA"
      puts insp.to_s + "\t" + sp.to_s
    end

    puts "\t\t\tproduct\t" + aa

    if pseudo
      puts "\t\t\tpseudo"
    else
      if acst != 0 and acsp != 0
        if acst < acsp
          puts "\t\t\tanticodon\t(pos:" + acst.to_s + ".." + acsp.to_s + ",aa:" + aa + ")"
        else
          puts "\t\t\tanticodon\t(pos:complement(" + acsp.to_s + ".." + acst.to_s + "),aa:" + aa + ")"
        end
      end
    end

    puts "\t\t\tgene\t-"

    st = 0;
    sp = 0;
    inst = 0
    insp = 0
    acst = 0
    acsp = 0
    id = ''
    aa = ''
    pseudo = false

  elsif name.index('Type:') != nil

    aa = getaa name
    if aa == 'Undet' or aa == 'Sup'
      aa = 'OTHER'
    end

    loc = name.slice(/[(].*[)]/)
    acst = firstnum loc
    acsp = lastnum loc

  elsif name.index('Length') != nil

    id = getid name

    loc = name.slice(/[(].*[)]/)
    st = firstnum loc
    sp = lastnum loc

  elsif name.index('Possible intron:') != nil

    loc = name.slice(/[(].*[)]/)
    inst = firstnum loc
    insp = lastnum loc

  elsif name.index('Possible pseudogene:') != nil

    pseudo = true

  end
  name = gets
end