rbbt-entities 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,28 +17,61 @@ module Protein
17
17
 
18
18
  self.format = "Ensembl Protein ID"
19
19
 
20
- def ensembl
20
+ def self.ensp2sequence(organism, protein)
21
+ @@ensp2sequence ||= {}
22
+ @@ensp2sequence[organism] ||= Organism.protein_sequence(organism).tsv :persist => true
23
+ if Array === protein
24
+ @@ensp2sequence[organism].values_at *protein
25
+ else
26
+ @@ensp2sequence[organism][protein]
27
+ end
28
+ end
29
+
30
+ def self.ensp2enst(organism, protein)
31
+ @@ensp2enst ||= {}
32
+ @@ensp2enst[organism] ||= Organism.transcripts(organism).tsv(:type => :single, :key_field => "Ensembl Protein ID", :fields => ["Ensembl Transcript ID"], :persist => true)
33
+ @@ensp2enst[organism][protein]
34
+ end
35
+
36
+ property :uniprot => :array2single do
37
+ to "UniProt/SwissProt Accession"
38
+ end
39
+ persist :uniprot
40
+
41
+ property :ensembl => :array2single do
21
42
  to "Ensembl Protein ID"
22
43
  end
44
+ persist :ensembl
45
+
46
+ property :transcript => :array2single do
47
+ ensembl.collect{|ensp|
48
+ Protein.ensp2enst(organism, ensp)
49
+ }
50
+ end
51
+ persist :transcript
23
52
 
24
53
  property :ensembl_protein_image_url => :single2array do
25
54
  ensembl_url = if organism == "Hsa" then "www.ensembl.org" else "#{organism.sub(/.*\//,'')}.archive.ensembl.org" end
26
55
  "http://#{ensembl_url}/Homo_sapiens/Component/Transcript/Web/TranslationImage?db=core;p=#{ensembl};_rmd=d2a8;export=svg"
27
56
  end
57
+ persist :ensembl_protein_image_url
28
58
 
29
59
  property :to! => :array2single do |new_format|
30
60
  return self if format == new_format
31
61
  Protein.setup(Translation.job(:translate_protein, "", :organism => organism, :proteins => self, :format => new_format).exec, new_format, organism)
32
62
  end
63
+ persist :to!
33
64
 
34
65
  property :to => :array2single do |new_format|
35
66
  return self if format == new_format
36
67
  to!(new_format).collect!{|v| v.nil? ? nil : v.first}
37
68
  end
69
+ persist :to
38
70
 
39
- property :gene do
71
+ property :gene => :array do
40
72
  Gene.setup(to("Ensembl Protein ID").clean_annotations, "Ensembl Protein ID", organism)
41
73
  end
74
+ persist :gene
42
75
 
43
76
  property :pfam => :array2single do
44
77
  index = Organism.gene_pfam(organism).tsv :flat, :persist => true
@@ -46,17 +79,16 @@ module Protein
46
79
  pfam = index.values_at(*self).flatten
47
80
  Pfam.setup pfam
48
81
  end
82
+ persist :pfam
49
83
 
50
84
  property :sequence => :array2single do
51
- @protein_sequence ||= begin
52
- protein_sequence = Organism.protein_sequence(organism).tsv :persist => true
53
- protein_sequence.unnamed = true
54
- protein_sequence.values_at(*self.ensembl)
55
- end
85
+ Protein.ensp2sequence(organism, self.ensembl)
56
86
  end
87
+ persist :sequence
57
88
 
58
89
  property :sequence_length => :array2single do
59
90
  sequence.collect{|seq| seq.nil? ? nil : seq.length}
60
91
  end
92
+ persist :sequence_length
61
93
  end
62
94
 
@@ -0,0 +1,69 @@
1
+ require 'rbbt/entity'
2
+ require 'rbbt/entity/gene'
3
+
4
+ module Transcript
5
+ extend Entity
6
+
7
+ self.annotation :format
8
+ self.annotation :organism
9
+
10
+ self.format = "Ensembl Transcript ID"
11
+
12
+ def self.enst2ensg(organism, transcript)
13
+ @@enst2ensg ||= {}
14
+ @@enst2ensg[organism] ||= Organism.gene_transcripts(organism).tsv(:type => :single, :key_field => "Ensembl Transcript ID", :fields => ["Ensembl Gene ID"], :persist => true).tap{|o| o.unnamed = true}
15
+ res = if Array === transcript
16
+ @@enst2ensg[organism].values_at *transcript
17
+ else
18
+ @@enst2ensg[organism][transcript]
19
+ end
20
+ Gene.setup(res, "Ensembl Gene ID", organism)
21
+ end
22
+
23
+ def self.enst2ensp(organism, transcript)
24
+ @@enst2ensp ||= {}
25
+ @@enst2ensp[organism] ||= Organism.transcripts(organism).tsv(:type => :single, :key_field => "Ensembl Transcript ID", :fields => ["Ensembl Protein ID"], :persist => true)
26
+ res = if Array === transcript
27
+ @@enst2ensp[organism].values_at *transcript
28
+ else
29
+ @@enst2ensp[organism][transcript]
30
+ end
31
+ Protein.setup(res, "Ensembl Protein ID", organism)
32
+ end
33
+
34
+
35
+ property :to! => :array2single do |new_format|
36
+ return self if format == new_format
37
+ Gene.setup(Translation.job(:tsv_translate_probe, "", :organism => organism, :probes => self, :format => new_format).exec.values_at(*self), new_format, organism)
38
+ end
39
+
40
+ property :to => :array2single do |new_format|
41
+ return self if format == new_format
42
+ to!(new_format).collect!{|v| v.nil? ? nil : v.first}
43
+ end
44
+
45
+ property :ensembl => :array2single do
46
+ to "Ensembl Transcript ID"
47
+ end
48
+
49
+ property :sequence => :array2single do
50
+ transcript_sequence = Organism.transcript_sequence(organism).tsv :persist => true
51
+ transcript_sequence.unnamed = true
52
+ transcript_sequence.values_at *self.ensembl
53
+ end
54
+
55
+ property :sequence_length => :array2single do
56
+ sequence.collect{|s|
57
+ s.nil? ? nil : s.length
58
+ }
59
+ end
60
+
61
+ property :gene => :array2single do
62
+ Transcript.enst2ensg(organism, self)
63
+ end
64
+
65
+ property :protein => :array2single do
66
+ Transcript.enst2ensp(organism, self)
67
+ end
68
+ end
69
+
@@ -24,7 +24,7 @@ class TestGene < Test::Unit::TestCase
24
24
  def test_transcripts
25
25
  assert CDK5.transcripts.length > 1
26
26
  assert_equal "Hsa", CDK5.transcripts.organism
27
- assert_equal "Hsa", CDK5.make_list.transcripts.first.organism
27
+ assert_equal "Hsa", CDK5.make_list.transcripts[0].organism
28
28
  assert_equal "Hsa", CDK5.transcripts.make_list.organism
29
29
  end
30
30
 
@@ -8,15 +8,6 @@ require 'rbbt/entity/genomic_mutation'
8
8
  class TestGenomicMutation < Test::Unit::TestCase
9
9
  MUTATION = GenomicMutation.setup("10:124745844:A:158", "Test", "Hsa/jun2011")
10
10
  SPLICING = GenomicMutation.setup("18:14787040:A", "Test", "Hsa/jun2011")
11
- GENOTYPE = GenomicMutation.setup(Rbbt.data.genotype.list, "Test", "Hsa/jun2011")
12
-
13
- def test_genes
14
- assert GENOTYPE.genes.flatten.to("Associated Gene Name").include? "PSTK"
15
- end
16
-
17
- def test_consolidate
18
- assert GENOTYPE.genes.consolidate.to("Associated Gene Name").include? "PSTK"
19
- end
20
11
 
21
12
  def test_mutated_isoforms
22
13
  assert MUTATION.mutated_isoforms.length > 1
@@ -32,7 +23,6 @@ class TestGenomicMutation < Test::Unit::TestCase
32
23
  assert MUTATION.over_gene? Gene.setup("PSTK", "Associated Gene Name", "Hsa/jun2011").ensembl
33
24
  assert(!(SPLICING.over_gene? Gene.setup("PSTK", "Associated Gene Name", "Hsa/jun2011").ensembl))
34
25
  end
35
-
36
26
  end
37
27
 
38
28
 
@@ -0,0 +1,101 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'rbbt/entity'
3
+ require 'rbbt/util/tmpfile'
4
+ require 'test/unit'
5
+
6
+ module ReversableString
7
+ extend Entity
8
+
9
+ property :reverse_text_ary => :array do
10
+ $count += 1
11
+ self.collect{|s| s.reverse}
12
+ end
13
+
14
+ property :reverse_text_single => :single do
15
+ $count += 1
16
+ self.reverse
17
+ end
18
+
19
+ property :reverse_text_ary_p => :array do
20
+ $count += 1
21
+ self.collect{|s| s.reverse}
22
+ end
23
+
24
+ property :reverse_text_single_p => :single do
25
+ $count += 1
26
+ self.reverse
27
+ end
28
+
29
+ property :reverse_text_ary_p_array => :array do
30
+ $count += 1
31
+ self.collect{|s| s.reverse}
32
+ end
33
+
34
+ persist :reverse_text_ary_p
35
+ persist :reverse_text_ary_p
36
+ persist :reverse_text_ary_p
37
+ persist :reverse_text_single_p
38
+
39
+ persist :reverse_text_ary_p_array, :array, :dir => TmpFile.tmp_file
40
+ end
41
+ class TestEntity < Test::Unit::TestCase
42
+
43
+ def test_property_ary
44
+ a = ["String1", "String2"]
45
+ a.extend ReversableString
46
+
47
+ $count = 0
48
+
49
+ assert_equal "2gnirtS", a.reverse_text_ary.last
50
+ assert_equal 1, $count
51
+ assert_equal "2gnirtS", a[1].reverse_text_ary
52
+ assert_equal 2, $count
53
+ end
54
+
55
+ def test_property_single
56
+ a = ["String1", "String2"]
57
+ a.extend ReversableString
58
+
59
+ $count = 0
60
+
61
+ assert_equal "2gnirtS", a.reverse_text_single.last
62
+ assert_equal 2, $count
63
+ assert_equal "2gnirtS", a[1].reverse_text_single
64
+ assert_equal 3, $count
65
+ end
66
+
67
+ def test_property_ary_p
68
+ a = ["String1", "String2"]
69
+ a.extend ReversableString
70
+
71
+ $count = 0
72
+
73
+ assert_equal "2gnirtS", a.reverse_text_ary_p.last
74
+ assert_equal "2gnirtS", a[1].reverse_text_ary_p
75
+ assert_equal 1, $count
76
+ end
77
+
78
+ def test_property_single_p
79
+ a = ["String1", "String2"]
80
+ a.extend ReversableString
81
+
82
+ $count = 0
83
+
84
+ assert_equal "2gnirtS", a.reverse_text_single_p.last
85
+ assert_equal 2, $count
86
+ assert_equal "2gnirtS", a[1].reverse_text_single_p
87
+ assert_equal 2, $count
88
+ end
89
+
90
+ def test_property_ary_p_array
91
+ a = ["String1", "String2"]
92
+ a.extend ReversableString
93
+
94
+ $count = 0
95
+
96
+ assert_equal "2gnirtS", a.reverse_text_ary_p_array.last
97
+ assert_equal 1, $count
98
+ assert_equal "2gnirtS", a.reverse_text_ary_p_array.last
99
+ assert_equal 1, $count
100
+ end
101
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-entities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Miguel Vazquez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-17 00:00:00 +01:00
18
+ date: 2012-01-13 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,7 @@ files:
79
79
  - lib/rbbt/entity/mutated_isoform.rb
80
80
  - lib/rbbt/entity/pmid.rb
81
81
  - lib/rbbt/entity/protein.rb
82
+ - lib/rbbt/entity/transcript.rb
82
83
  - test/test_helper.rb
83
84
  - test/rbbt/entity/test_gene.rb
84
85
  - test/rbbt/entity/test_genomic_mutation.rb