Skip to content

Commit

Permalink
Deploying to gh-pages from @ a6caa22 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ielis committed Sep 18, 2024
1 parent e2845d4 commit 76bf3d3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions latest/_modules/gpsea/preprocessing/_uniprot.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ <h1>Source code for gpsea.preprocessing._uniprot</h1><div class="highlight"><pre
<span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">30.</span><span class="p">,</span>
<span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">=</span> <span class="s1">&#39;https://rest.uniprot.org/uniprotkb/search?query=(</span><span class="si">%s</span><span class="s1">)AND(reviewed:true)&amp;fields=accession,id,&#39;</span> \
<span class="s1">&#39;gene_names,gene_primary,protein_name,ft_domain,ft_motif,ft_region,ft_repeat,xref_refseq,length&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_headers</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Content-type&#39;</span><span class="p">:</span> <span class="s1">&#39;application/json&#39;</span><span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">=</span> <span class="s1">&#39;https://rest.uniprot.org/uniprotkb/search?query=(</span><span class="si">%s</span><span class="s1">)AND(reviewed:true)&amp;(organism_id:9606)&#39;</span> \
<span class="s1">&#39;&amp;fields=accession,id,gene_names,gene_primary,protein_name,ft_domain,ft_motif,ft_region,ft_repeat,&#39;</span> \
<span class="s1">&#39;xref_refseq,length&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">=</span> <span class="n">timeout</span>

<div class="viewcode-block" id="UniprotProteinMetadataService.parse_uniprot_json">
Expand Down Expand Up @@ -177,6 +179,17 @@ <h1>Source code for gpsea.preprocessing._uniprot</h1><div class="highlight"><pre

<span class="k">return</span> <span class="n">ProteinMetadata</span><span class="p">(</span><span class="n">protein_id</span><span class="p">,</span> <span class="n">protein_name</span><span class="p">,</span> <span class="n">all_features_list</span><span class="p">,</span> <span class="n">protein_length</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_fetch_uniprot_response</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">protein_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Mapping</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">typing</span><span class="o">.</span><span class="n">Any</span><span class="p">]:</span>
<span class="n">api_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_url</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">protein_id</span><span class="p">)</span>
<span class="k">return</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
<span class="n">api_url</span><span class="p">,</span>
<span class="n">headers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_headers</span><span class="p">,</span>
<span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">,</span>
<span class="p">)</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

<div class="viewcode-block" id="UniprotProteinMetadataService.annotate">
<a class="viewcode-back" href="../../../apidocs/gpsea.preprocessing.html#gpsea.preprocessing.UniprotProteinMetadataService.annotate">[docs]</a>
<span class="k">def</span> <span class="nf">annotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">protein_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">ProteinMetadata</span><span class="p">:</span>
Expand All @@ -195,9 +208,8 @@ <h1>Source code for gpsea.preprocessing._uniprot</h1><div class="highlight"><pre
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Please remove whitespace from protein id: </span><span class="se">\&quot;</span><span class="si">{</span><span class="n">protein_id</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2"> and try again!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">protein_id</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;NP_&quot;</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;only works with a RefSeq database ID (e.g. NP_037407.4), but we got </span><span class="si">{</span><span class="n">protein_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">api_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">%</span> <span class="n">protein_id</span>
<span class="n">response</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">api_url</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">)</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

<span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fetch_uniprot_response</span><span class="p">(</span><span class="n">protein_id</span><span class="p">)</span>
<span class="k">return</span> <span class="n">UniprotProteinMetadataService</span><span class="o">.</span><span class="n">parse_uniprot_json</span><span class="p">(</span><span class="n">response</span><span class="p">,</span> <span class="n">protein_id</span><span class="p">)</span></div>
</div>

Expand Down

0 comments on commit 76bf3d3

Please sign in to comment.