Module: SequenceServer::Links
Overview
Module to contain methods for generating sequence retrieval links.
Constant Summary collapse
- NCBI_ID_PATTERN =
/gi\|(\d+)\|/
- UNIPROT_ID_PATTERN =
/sp\|(\w+)\|/
- PFAM_ID_PATTERN =
/(PF\d{5}\.?\d*)/
- RFAM_ID_PATTERN =
/(RF\d{5})/
Instance Method Summary collapse
-
#ncbi ⇒ Object
Link generators are methods that return a Hash as defined below.
- #pfam ⇒ Object
- #rfam ⇒ Object
- #uniprot ⇒ Object
Instance Method Details
#ncbi ⇒ Object
Link generators are methods that return a Hash as defined 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}"
dbtype:
Returns the database type (nucleotide or protein) that was used for
BLAST search.
whichdb:
Returns the databases from which the hit could have originated. To
ensure that one and the correct database is returned, ensure that
your sequence ids are unique across different FASTA files.
NOTE: This method is slow.
coordinates:
Returns min alignment start and max alignment end coordinates for
query and hit sequences.
e.g.,
query_coords = coordinates[0]
hit_coords = coordinates[1]
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sequenceserver/links.rb', line 68 def ncbi return nil unless id.match(NCBI_ID_PATTERN) or title.match(NCBI_ID_PATTERN) ncbi_id = Regexp.last_match[1] ncbi_id = encode ncbi_id url = "https://www.ncbi.nlm.nih.gov/#{dbtype}/#{ncbi_id}" { order: 2, title: 'NCBI', url: url, icon: 'fa-external-link' } end |
#pfam ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sequenceserver/links.rb', line 94 def pfam return nil unless id.match(PFAM_ID_PATTERN) or title.match(PFAM_ID_PATTERN) pfam_id = Regexp.last_match[1] pfam_id = encode pfam_id url = "https://pfam.xfam.org/family/#{pfam_id}" { order: 2, title: 'Pfam', url: url, icon: 'fa-external-link' } end |
#rfam ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sequenceserver/links.rb', line 107 def rfam return nil unless id.match(RFAM_ID_PATTERN) or title.match(RFAM_ID_PATTERN) rfam_id = Regexp.last_match[1] rfam_id = encode rfam_id url = "https://rfam.xfam.org/family/#{rfam_id}" { order: 2, title: 'Rfam', url: url, icon: 'fa-external-link' } end |
#uniprot ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sequenceserver/links.rb', line 81 def uniprot return nil unless id.match(UNIPROT_ID_PATTERN) or title.match(UNIPROT_ID_PATTERN) uniprot_id = Regexp.last_match[1] uniprot_id = encode uniprot_id url = "https://www.uniprot.org/uniprot/#{uniprot_id}" { order: 2, title: 'UniProt', url: url, icon: 'fa-external-link' } end |