Skip to content

Commit

Permalink
add seqcol client compare
Browse files Browse the repository at this point in the history
  • Loading branch information
nsheff committed Feb 14, 2024
1 parent 8031d0e commit fc7c94d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ open_pipelines/
*RESERVE*

# Build-related stuff
build
dist/
refget.egg-info/

#ipynm checkpoints
*ipynb_checkpoints*
*.egg-info*


4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://travis-ci.com/refgenie/refget.svg?branch=master)](https://travis-ci.com/refgenie/refget)

The refget package provides a Python interface to both remote and local use of the refget protocol.
The refget package provides a Python interface to both remote and local use of the refget protocol.

This package provides clients and functions for both refget sequences and refget sequence collections (seqcol).

Documentation is hosted at [refget.databio.org](http://refget.databio.org).
3 changes: 2 additions & 1 deletion refget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from .refget import parse_fasta
from .seqcol import *
from .utilities import *
from .seqcol_client import *

__classes__ = ["RefGetClient", "SeqColHenge"]
__classes__ = ["RefGetClient", "SeqColHenge", "SeqColClient"]
__all__ = (
__classes__
+ ["build_sorted_name_length_pairs", "compare", "validate_seqcol", "fasta_file_to_digest"],
Expand Down
47 changes: 47 additions & 0 deletions refget/seqcol_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests

class SeqColClient(object):
"""
A client for interacting with a sequence collection API.
Args:
url (str, optional): The base URL of the sequence collection API. Defaults to "http://seqcolapi.databio.org".
Attributes:
url (str): The base URL of the sequence collection API.
Methods:
get_collection(accession, level=2): Retrieves a sequence collection for a given accession and level.
"""
def __init__(self, url="http://seqcolapi.databio.org"):
self.url = url

def get_collection(self, accession, level=2):
"""
Retrieves a sequence collection for a given accession and detail level.
Args:
accession (str): The accession of the sequence collection.
level (int, optional): The level of detail for the sequence collection. Defaults to 2.
Returns:
dict: The JSON response containing the sequence collection.
"""
url = f"{self.url}/collection/{accession}?level={level}"
response = requests.get(url)
return response.json()

def compare(self, accession1, accession2):
"""
Compares two sequence collections.
Args:
accession1 (str): The accession of the first sequence collection.
accession2 (str): The accession of the second sequence collection.
Returns:
dict: The JSON response containing the comparison of the two sequence collections.
"""
url = f"{self.url}/comparison/{accession1}/{accession2}"
response = requests.get(url)
return response.json()

0 comments on commit fc7c94d

Please sign in to comment.