Class | Bio::DAS |
In: |
lib/bio/io/das.rb
lib/bio/shell/plugin/das.rb |
Parent: | Object |
# File lib/bio/io/das.rb, line 36 36: def dna(dsn, entry_point, start, stop) 37: seg = Bio::DAS::SEGMENT.region(entry_point, start, stop) 38: self.get_dna(dsn, seg).first.sequence 39: end
# File lib/bio/io/das.rb, line 41 41: def features(dsn, entry_point, start, stop) 42: seg = Bio::DAS::SEGMENT.region(entry_point, start, stop) 43: self.get_features(dsn, seg) 44: end
Returns an Array of Bio::DAS::DNA. The ‘dsn’ can be a String or a Bio::DAS::DSN object. The ‘segments’ can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT
# File lib/bio/io/das.rb, line 104 104: def get_dna(dsn, segments) 105: ary = [] 106: 107: dsn = dsn.source if dsn.instance_of?(DSN) 108: segments = [segments] if segments.instance_of?(SEGMENT) 109: 110: opts = [] 111: segments.each do |s| 112: opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}" 113: end 114: 115: result = Bio::Command.post_form("#{@server}/das/#{dsn}/dna", opts) 116: doc = REXML::Document.new(result.body) 117: doc.elements.each('/descendant::SEQUENCE') do |e| 118: sequence = DNA.new 119: sequence.entry_id = e.attributes['id'] 120: sequence.start = e.attributes['start'] 121: sequence.stop = e.attributes['stop'] 122: sequence.version = e.attributes['version'] 123: e.elements.each do |e| 124: sequence.sequence = Bio::Sequence::NA.new(e.text) 125: sequence.length = e.attributes['length'].to_i 126: end 127: ary << sequence 128: end 129: ary 130: end
Returns an Array of Bio::DAS::DSN
# File lib/bio/io/das.rb, line 48 48: def get_dsn 49: ary = [] 50: result = Bio::Command.post_form("#{@server}/das/dsn") 51: doc = REXML::Document.new(result.body) 52: doc.elements.each('/descendant::DSN') do |e| 53: dsn = DSN.new 54: e.elements.each do |e| 55: case e.name 56: when 'SOURCE' 57: dsn.source = e.text 58: dsn.source_id = e.attributes['id'] 59: dsn.source_version = e.attributes['version'] 60: when 'MAPMASTER' 61: dsn.mapmaster = e.text 62: when 'DESCRIPTION' 63: dsn.description = e.text 64: dsn.description_href = e.attributes['href'] 65: end 66: end 67: ary << dsn 68: end 69: ary 70: end
Returns Bio::DAS::ENTRY_POINT. The ‘dsn’ can be a String or a Bio::DAS::DSN object.
# File lib/bio/io/das.rb, line 74 74: def get_entry_points(dsn) 75: entry_point = ENTRY_POINT.new 76: if dsn.instance_of?(Bio::DAS::DSN) 77: src = dsn.source 78: else 79: src = dsn 80: end 81: result = Bio::Command.post_form("#{@server}/das/#{src}/entry_points") 82: doc = REXML::Document.new(result.body) 83: doc.elements.each('/descendant::ENTRY_POINTS') do |e| 84: entry_point.href = e.attributes['href'] 85: entry_point.version = e.attributes['version'] 86: e.elements.each do |e| 87: segment = SEGMENT.new 88: segment.entry_id = e.attributes['id'] 89: segment.start = e.attributes['start'] 90: segment.stop = e.attributes['stop'] || e.attributes['size'] 91: segment.orientation = e.attributes['orientation'] 92: segment.subparts = e.attributes['subparts'] 93: segment.description = e.text 94: entry_point.segments << segment 95: end 96: end 97: entry_point 98: end
Returns a Bio::DAS::GFF object. The ‘dsn’ can be a String or a Bio::DAS::DSN object. The ‘segments’ is optional and can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT
# File lib/bio/io/das.rb, line 214 214: def get_features(dsn, segments = [], categorize = false, feature_ids = [], group_ids = []) 215: # arguments 'type' and 'category' are deprecated 216: gff = GFF.new 217: 218: dsn = dsn.source if dsn.instance_of?(DSN) 219: segments = [segments] if segments.instance_of?(SEGMENT) 220: 221: opts = [] 222: segments.each do |s| 223: opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}" 224: end 225: if categorize 226: opts << "categorize=yes" # default is 'no' 227: end 228: feature_ids.each do |fid| 229: opts << "feature_id=#{fid}" 230: end 231: group_ids.each do |gid| 232: opts << "group_id=#{gid}" 233: end 234: 235: result = Bio::Command.post_form("#{@server}/das/#{dsn}/features", opts) 236: doc = REXML::Document.new(result.body) 237: doc.elements.each('/descendant::GFF') do |e| 238: gff.version = e.attributes['version'] 239: gff.href = e.attributes['href'] 240: e.elements.each('SEGMENT') do |e| 241: segment = SEGMENT.new 242: segment.entry_id = e.attributes['id'] 243: segment.start = e.attributes['start'] 244: segment.stop = e.attributes['stop'] 245: segment.version = e.attributes['version'] 246: segment.label = e.attributes['label'] 247: e.elements.each do |e| 248: feature = FEATURE.new 249: feature.entry_id = e.attributes['id'] 250: feature.label = e.attributes['label'] 251: e.elements.each do |e| 252: case e.name 253: when 'TYPE' 254: type = TYPE.new 255: type.entry_id = e.attributes['id'] 256: type.category = e.attributes['category'] 257: type.reference = e.attributes['referrence'] 258: type.label = e.text 259: feature.types << type 260: when 'METHOD' 261: feature.method_id = e.attributes['id'] 262: feature.method = e.text 263: when 'START' 264: feature.start = e.text 265: when 'STOP', 'END' 266: feature.stop = e.text 267: when 'SCORE' 268: feature.score = e.text 269: when 'ORIENTATION' 270: feature.orientation = e.text 271: when 'PHASE' 272: feature.phase = e.text 273: when 'NOTE' 274: feature.notes << e.text 275: when 'LINK' 276: link = LINK.new 277: link.href = e.attributes['href'] 278: link.text = e.text 279: feature.links << link 280: when 'TARGET' 281: target = TARGET.new 282: target.entry_id = e.attributes['id'] 283: target.start = e.attributes['start'] 284: target.stop = e.attributes['stop'] 285: target.name = e.text 286: feature.targets << target 287: when 'GROUP' 288: group = GROUP.new 289: group.entry_id = e.attributes['id'] 290: group.label = e.attributes['label'] 291: group.type = e.attributes['type'] 292: e.elements.each do |e| 293: case e.name 294: when 'NOTE' # in GROUP 295: group.notes << e.text 296: when 'LINK' # in GROUP 297: link = LINK.new 298: link.href = e.attributes['href'] 299: link.text = e.text 300: group.links << link 301: when 'TARGET' # in GROUP 302: target = TARGET.new 303: target.entry_id = e.attributes['id'] 304: target.start = e.attributes['start'] 305: target.stop = e.attributes['stop'] 306: target.name = e.text 307: group.targets << target 308: end 309: end 310: feature.groups << group 311: end 312: end 313: segment.features << feature 314: end 315: gff.segments << segment 316: end 317: end 318: gff 319: end
Returns an Array of Bio::DAS::SEQUENCE. The ‘dsn’ can be a String or a Bio::DAS::DSN object. The ‘segments’ can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT
# File lib/bio/io/das.rb, line 136 136: def get_sequence(dsn, segments) 137: ary = [] 138: 139: dsn = dsn.source if dsn.instance_of?(DSN) 140: segments = [segments] if segments.instance_of?(SEGMENT) 141: 142: opts = [] 143: segments.each do |s| 144: opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}" 145: end 146: 147: result = Bio::Command.post_form("#{@server}/das/#{dsn}/sequence", opts) 148: doc = REXML::Document.new(result.body) 149: doc.elements.each('/descendant::SEQUENCE') do |e| 150: sequence = SEQUENCE.new 151: sequence.entry_id = e.attributes['id'] 152: sequence.start = e.attributes['start'] 153: sequence.stop = e.attributes['stop'] 154: sequence.moltype = e.attributes['moltype'] 155: sequence.version = e.attributes['version'] 156: case sequence.moltype 157: when /dna|rna/i # 'DNA', 'ssRNA', 'dsRNA' 158: sequence.sequence = Bio::Sequence::NA.new(e.text) 159: when /protein/i # 'Protein 160: sequence.sequence = Bio::Sequence::AA.new(e.text) 161: else 162: sequence.sequence = e.text 163: end 164: ary << sequence 165: end 166: ary 167: end
Returns a Bio::DAS::TYPES object. The ‘dsn’ can be a String or a Bio::DAS::DSN object. The ‘segments’ is optional and can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT
# File lib/bio/io/das.rb, line 173 173: def get_types(dsn, segments = []) # argument 'type' is deprecated 174: types = TYPES.new 175: 176: dsn = dsn.source if dsn.instance_of?(DSN) 177: segments = [segments] if segments.instance_of?(SEGMENT) 178: 179: opts = [] 180: segments.each do |s| 181: opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}" 182: end 183: 184: result = Bio::Command.post_form("#{@server}/das/#{dsn}/types", opts) 185: doc = REXML::Document.new(result.body) 186: doc.elements.each('/descendant::GFF') do |e| 187: types.version = e.attributes['version'] 188: types.href = e.attributes['href'] 189: e.elements.each do |e| 190: segment = SEGMENT.new 191: segment.entry_id = e.attributes['id'] 192: segment.start = e.attributes['start'] 193: segment.stop = e.attributes['stop'] 194: segment.version = e.attributes['version'] 195: segment.label = e.attributes['label'] 196: e.elements.each do |e| 197: t = TYPE.new 198: t.entry_id = e.attributes['id'] 199: t.method = e.attributes['method'] 200: t.category = e.attributes['category'] 201: t.count = e.text.to_i 202: segment.types << t 203: end 204: types.segments << segment 205: end 206: end 207: types 208: end
# File lib/bio/shell/plugin/das.rb, line 14 14: def list_sequences 15: result = "" 16: self.get_dsn.each do |dsn| 17: src = dsn.source_id 18: self.get_entry_points(src).each do |ep| 19: data = [src, ep.entry_id, ep.start.to_i, ep.stop.to_i, "# #{ep.description}"].join("\t") + "\n" 20: puts data 21: result += data 22: end 23: end 24: return result 25: end