Class: Bio::UniProtKB

Inherits:
Object
  • Object
show all
Defined in:
lib/full_lengther_next/bio_patch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.patched?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/full_lengther_next/bio_patch.rb', line 3

def self.patched?
	return true
end

Instance Method Details

#ft(feature_key = nil) ⇒ Object



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
# File 'lib/full_lengther_next/bio_patch.rb', line 7

def ft(feature_key = nil)
  return ft[feature_key] if feature_key
  return @data['FT'] if @data['FT']

  table = []
  begin
    get('FT').split("\n").each do |line|
      if line =~ /^FT   \w/
        feature = line.chomp.ljust(74)
        table << [feature[ 5..12].strip,   # Feature Name
                  feature[14..19].strip,   # From
                  feature[21..26].strip,   # To
                  feature[34..74].strip ]  # Description
      else
        table.last << line.chomp.sub!(/^FT +/, '')
      end
    end

    # Joining Description lines
    table = table.map { |feature| 
      ftid = feature.pop if feature.last =~ /FTId=/
      if feature.size > 4
        feature = [feature[0], 
                   feature[1], 
                   feature[2], 
                   feature[3, feature.size - 3].join(" ")]
      end
      feature << if ftid then ftid else '' end
    }
    
    ###### PATCH TO RECOVER PARSER
    to_delete = []
    table.each_with_index do |feature, i|
    		name, from, to, descrition = feature
    		if from.empty?
    			coors = to.split("..")
    			if coors.length == 2
    				feature[1] = coors[0]
    				feature[2] = coors[1]
    			elsif /[^\d]/ =~ to
    				to_delete << i 
    			else
    				feature[1] = to
    				feature[2] = to
    			end
    		end
    end
    to_delete.reverse_each{|i| table.delete_at(i)}
    #####

    hash = {}
    table.each do |feature|
      hash[feature[0]] = [] unless hash[feature[0]]
      hash[feature[0]] << {
        # Removing '<', '>' or '?' in FROM/TO endopoint.
        'From' => feature[1].sub(/\D/, '').to_i,  
        'To'   => feature[2].sub(/\D/, '').to_i, 
        'Description' => feature[3], 
        'FTId' => feature[4].to_s.sub(/\/FTId=/, '').sub(/\.$/, ''),
        'diff' => [],
        'original' => feature
      }

      case feature[0]
      when 'VARSPLIC', 'VARIANT', 'VAR_SEQ', 'CONFLICT'
        case hash[feature[0]].last['Description']
        when /(\w[\w ]*\w*) - ?> (\w[\w ]*\w*)/
          original_res = $1
          changed_res = $2
          original_res = original_res.gsub(/ /,'').strip
          chenged_res = changed_res.gsub(/ /,'').strip
        when /Missing/i
          original_res = seq.subseq(hash[feature[0]].last['From'],
                                    hash[feature[0]].last['To'])
          changed_res = ''
        end
        hash[feature[0]].last['diff'] = [original_res, chenged_res]
      end
    end
  rescue
    raise "Invalid FT Lines(#{$!}) in #{entry_id}:, \n'#{self.get('FT')}'\n"
  end

  @data['FT'] = hash
end