Integrating Sequenceserver with Jbrowse
1
3
Entering edit mode
2.9 years ago
alslonik ▴ 320

Hi,

I am having problems with integrating sequenceserver (v. 1.14) that I am using on apache server with my own jbrowse on the same apache server. I did all (it seems so at least) what is written here .

Still - no links! Obviously, I am missing something basic here and will be very glad for your help!!!! I am not an expert (to say the least) in ruby. Here is my links.rb file -

Hope I will find my mistake here... THANKS!

module SequenceServer
  # Module to contain methods for generating sequence retrieval links.
  module Links
    require 'erb'
        # Provide a method to URL encode _query parameters_. See [1].
    include ERB::Util
    #
    alias_method :encode, :url_encode

    NCBI_ID_PATTERN    = /gi\|(\d+)\|/
    UNIPROT_ID_PATTERN = /sp\|(\w+)\|/
    require 'json'
    # Link generators return a Hash like below.
    #
    # {
    #   # Required. Display title.
    #   :title => "title",
    #
    #   # Required. Generated url.
    #   :url => url,
    #
    #   # Optional. Left-right order in which the link should appear.
    #   :order => num,
    #
    #   # Optional. Classes, if any, to apply to the link.
    #   :class => "class1 class2",
    #
    #   # Optional. Class name of a FontAwesome icon to use.
    #   :icon => "fa-icon-class"
    # }
    #
    # If no url could be generated, return nil.
    #
    # Helper methods
    # --------------
    #
    # Following helper methods are available to help with link generation.
    #
    #   encode:
    #     URL encode query params.
    #
    #     Don't use this function to encode the entire URL. Only params.
    #
    #     e.g:
    #         sequence_id = encode sequence_id
    #         url = "http://www.ncbi.nlm.nih.gov/nucleotide/#{sequence_id}"
    #
    #   querydb:
    #     Returns an array of databases that were used for BLASTing.
    #
    #   whichdb:
    #     Returns the database from which the given hit came from.
    #
    #     e.g:
    #
    #         hit_database = whichdb
    #
    # Examples:
    # ---------
    # See methods provided by default for an example implementation.

    def sequence_viewer
      accession  = encode self.accession
      database_ids = encode querydb.map(&:id).join(' ')
      url = "get_sequence/?sequence_ids=#{accession}" \
            "&database_ids=#{database_ids}"

      {
        :order => 0,
        :url   => url,
        :title => 'Sequence',
        :class => 'view-sequence',
        :icon  => 'fa-eye'
      }
    end

    def fasta_download
      accession  = encode self.accession
      database_ids = encode querydb.map(&:id).join(' ')
      url = "get_sequence/?sequence_ids=#{accession}" \
            "&database_ids=#{database_ids}&download=fasta"

      {
        :order => 1,
        :title => 'FASTA',
        :url   => url,
        :class => 'download',
        :icon  => 'fa-download'
      }
    end

    def ncbi
      return nil unless id.match(NCBI_ID_PATTERN)
      ncbi_id = Regexp.last_match[1]
      ncbi_id = encode ncbi_id
      url = "http://www.ncbi.nlm.nih.gov/#{querydb.first.type}/#{ncbi_id}"
      {
        :order => 2,
        :title => 'NCBI',
        :url   => url,
        :icon  => 'fa-external-link'
      }
    end

    def uniprot
      return nil unless id.match(UNIPROT_ID_PATTERN)
      uniprot_id = Regexp.last_match[1]
      uniprot_id = encode uniprot_id
      url = "http://www.uniprot.org/uniprot/#{uniprot_id}"
      {
        :order => 2,
        :title => 'Uniprot',
        :url   => url,
        :icon  => 'fa-external-link'
      }
    end

    def jbrowse
           qstart = hsps.map(&:qstart).min
           sstart = hsps.map(&:sstart).min
           qend = hsps.map(&:qend).max
           send = hsps.map(&:send).max
           first_hit_start = hsps.map(&:sstart).at(0)
           first_hit_end = hsps.map(&:send).at(0)
           my_features = ERB::Util.url_encode(JSON.generate([{
               :seq_id => accession,
               :start => sstart,
               :end => send,
               :type => "match",
               :subfeatures =>  hsps.map {
                 |hsp| {
                   :start => hsp.send < hsp.sstart ? hsp.send : hsp.sstart,
                   :end => hsp.send < hsp.sstart ? hsp.sstart : hsp.send,
                   :type => "match_part"
                 } 
               }
           }]))
           my_track = ERB::Util.url_encode(JSON.generate([
                {
                   :label => "BLAST",
                   :key => "BLAST hits",
                   :type => "JBrowse/View/Track/CanvasFeatures",
                   :store => "url",
                   :glyph => "JBrowse/View/FeatureGlyph/Segments"
                }
           ]))
           url = "<http://http://mysite/pomegranate/>" \
                        "?loc=#{accession}:#{first_hit_start-500}..#{first_hit_start+500}" \
                        "&addFeatures=#{my_features}" \
                        "&addTracks=#{my_track}" \
                        "&tracks=BLAST" \
                        "&highlight=#{accession}:#{first_hit_start}..#{first_hit_end}"
           {
             :order => 2,
             :title => 'JBrowse',
             :url   => url,
             :icon  => 'fa-external-link'
           }
    end
  end
end

# [1]: https://stackoverflow.com/questions/2824126/whats-the-difference-between-uri-escape-and-cgi-escape
sequenceserver jbrowse • 2.1k views
ADD COMMENT
0
Entering edit mode

Tagging: cmdcolin

ADD REPLY
2
Entering edit mode

Thanks for tagging me @GenoMax . @alslonik do you think that you are loading the links.rb file properly for sequence server? e.g. using sequenceserver -D database_dir -r links.rb (different setup if using passenger phusion, etc but can use that command for simple local dev)

ADD REPLY
0
Entering edit mode

Hi, Thanks for getting back. I am not sure that I load the file properly. This is what I get when I use sequenceserver -D database_dir -r links.rb

/var/lib/gems/2.3.0/gems/sequenceserver-1.0.14/lib/sequenceserver/links.rb:10: warning: already initialized constant SequenceServer::Links::NCBI_ID_PATTERN
/var/lib/gems/2.3.0/gems/sequenceserver-1.0.14/links.rb:10: warning: previous definition of NCBI_ID_PATTERN was here
/var/lib/gems/2.3.0/gems/sequenceserver-1.0.14/lib/sequenceserver/links.rb:11: warning: already initialized constant SequenceServer::Links::UNIPROT_ID_PATTERN
/var/lib/gems/2.3.0/gems/sequenceserver-1.0.14/links.rb:11: warning: previous definition of UNIPROT_ID_PATTERN was here
[2022-01-11 09:26:03] DEBUG  Reading configuration file: /home/alex/.sequenceserver.conf.
[2022-01-11 09:26:03] DEBUG  Will use NCBI BLAST+ at: $PATH
[2022-01-11 09:26:04] DEBUG  Will use BLAST+ databases at: /data/genome/Punica.granatum/wonderful/V3/Draft
[2022-01-11 09:26:04] DEBUG  Found nucleotide database 'Chr0 v3' at '/data/genome/Punica.granatum/wonderful/V3/Draft/Chr0_v3.fasta'
[2022-01-11 09:26:04] DEBUG  Found nucleotide database 'wonderful v3' at '/data/genome/Punica.granatum/wonderful/V3/Draft/wonderful_v3.fasta'
[2022-01-11 09:26:04] DEBUG  Found nucleotide database 'wonderful v3 chr0' at '/data/genome/Punica.granatum/wonderful/V3/Draft/wonderful_v3_chr0.fasta'
[2022-01-11 09:26:04] DEBUG  Loading extension: /var/lib/gems/2.3.0/gems/sequenceserver-1.0.14/links.rb
[2022-01-11 09:26:04] DEBUG  Will use 1 threads to run BLAST.
[2022-01-11 09:26:04] WARN  Will listen on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--host option).
[2022-01-11 09:26:04] INFO  WEBrick 1.3.1
[2022-01-11 09:26:04] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu]
** Could not bind to port 4567.
   Is SequenceServer already accessible at http://localhost:4567?
   No? Try running SequenceServer on another port, like so:

       sequenceserver -p 4570.
ADD REPLY
0
Entering edit mode

I am not too experienced with the sequenceserver side of things and don't have a great internet connection right now, you might try asking the sequenceserver mailing list if you think it is related to the links.rb file not working

ADD REPLY
0
Entering edit mode

Thanks, I do think it is sequenceserver. I used their mailing list, of course. Hope will find the solution there. Thank you!

ADD REPLY
6
Entering edit mode
2.9 years ago
alslonik ▴ 320

For the sake of those who will read this - here is the answer: I followed the tutorial here https://jbrowse.org/docs/faq.html#how-can-i-link-blast-results-to-jbrowse and put links.rb file in installation directory /sequenceserver-1.0.14/lib/sequenceserver/ . I just added the bit that is shown on jbrowse tutorial to the existing links.rb and than added the path to the conf file in /etc/sequenceserver/. Also, note that the url in the bit to be added should be changed to your own jbrowse url. And it works fine now.

ADD COMMENT

Login before adding your answer.

Traffic: 2607 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6