Light1992

links.rb

May 22nd, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. require 'json'
  2. module SequenceServer
  3. module Links
  4. def jbrowse
  5. qstart = hsps.map(&:qstart).min
  6. sstart = hsps.map(&:sstart).min
  7. qend = hsps.map(&:qend).max
  8. send = hsps.map(&:send).max
  9. first_hit_start = hsps.map(&:sstart).at(0)
  10. first_hit_end = hsps.map(&:send).at(0)
  11. organism = accession.partition('-').first
  12. sequence_id = accession.partition('-').last
  13. my_features = ERB::Util.url_encode(JSON.generate([{
  14. :seq_id => sequence_id,
  15. :start => sstart,
  16. :end => send,
  17. :type => "match",
  18. :subfeatures => hsps.map {
  19. |hsp| {
  20. :start => hsp.send < hsp.sstart ? hsp.send : hsp.sstart,
  21. :end => hsp.send < hsp.sstart ? hsp.sstart : hsp.send,
  22. :type => "match_part"
  23. }
  24. }
  25. }]))
  26. my_track = ERB::Util.url_encode(JSON.generate([
  27. {
  28. :label => "BLAST",
  29. :key => "BLAST hits",
  30. :type => "JBrowse/View/Track/CanvasFeatures",
  31. :store => "url",
  32. :glyph => "JBrowse/View/FeatureGlyph/Segments"
  33. }
  34. ]))
  35. url = "<http://10.150.2.3/jbrowse1>" \
  36. "?data=#{organism}" \
  37. "&loc=#{sequence_id}:#{first_hit_start-500}..#{first_hit_start+500}" \
  38. "&addFeatures=#{my_features}" \
  39. "&addTracks=#{my_track}" \
  40. "&tracks=BLAST" \
  41. "&highlight=#{accession}:#{first_hit_start}..#{first_hit_end}"
  42. {
  43. :order => 2,
  44. :title => 'JBrowse',
  45. :url => url,
  46. :icon => 'fa-external-link'
  47. }
  48. end
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment