Esempio n. 1
0
def search_data(free_text_search, query, result, display, download, file,
                fields, sortfields, offset, length):
    """ Search data given a query """
    free_text_search = True if free_text_search else False
    download = None if not download else download
    file = None if not file else file
    fields = None if not fields else ",".join(fields)
    sortfields = None if not sortfields else ",".join(sortfields)
    offset = None if not offset else offset
    length = None if not length else length
    if display in ["fasta", "fastq"]:
        results = enasearch.search_all_data(free_text_search=free_text_search,
                                            query=query,
                                            result=result,
                                            display=display,
                                            download=download,
                                            file=file)
    else:
        results = enasearch.search_data(free_text_search=free_text_search,
                                        query=query,
                                        result=result,
                                        display=display,
                                        download=download,
                                        file=file,
                                        fields=fields,
                                        sortfields=sortfields,
                                        offset=offset,
                                        length=length)

    if file is None:
        print_display(results, display)
Esempio n. 2
0
def test_search_data():
    """Test search_data function"""
    search_data = enasearch.search_data(
        free_text_search=False,
        query="tax_tree(7147) AND dataclass=STD",
        result="coding_release",
        display="fasta",
        offset=0,
        length=20,
        download=None,
        file=None,
        fields=None,
        sortfields=None)
    assert len([seq.id for seq in search_data]) > 0
Esempio n. 3
0
def search_data(free_text_search, query, result, display, download, file,
                fields, sortfields, offset, length):
    """Search data given a query.

    This function

    - Extracts the number of possible results for the query
    - Extracts the all the results of the query (by potentially running several times the search function)

    The output can be redirected to a file and directly display to the standard
    output given the display chosen.
    """
    free_text_search = True if free_text_search else False
    download = None if not download else download
    file = None if not file else file
    fields = None if not fields else ",".join(fields)
    sortfields = None if not sortfields else ",".join(sortfields)
    offset = None if not offset else offset
    length = None if not length else length
    if display in ["fasta", "fastq"]:
        results = enasearch.search_all_data(free_text_search=free_text_search,
                                            query=query,
                                            result=result,
                                            display=display,
                                            download=download,
                                            file=file)
    else:
        results = enasearch.search_data(free_text_search=free_text_search,
                                        query=query,
                                        result=result,
                                        display=display,
                                        download=download,
                                        file=file,
                                        fields=fields,
                                        sortfields=sortfields,
                                        offset=offset,
                                        length=length)

    if file is None:
        print_display(results, display)
Esempio n. 4
0
        data = json.loads(out)
        return data[0]


def sample2assembly(sample_id):
    response = ena_sample(sample_id, result='assembly')
    if response.status_code != 200:
        return ''
    else:
        out = response.text
        data = json.loads(out)
        return data[0]


data = enasearch.search_data(free_text_search=True,
                             query="CABMLH010000000",
                             result='wgs_set',
                             display='xml')
data = enasearch.retrieve_data(ids="CABMLH010000000", display="html")


def get_returnable_fields(result):
    url = f"https://www.ebi.ac.uk/ena/portal/api/returnFields?dataPortal=ena&format=json&result={result}"
    response = requests.get(url, )
    out = response.text
    data = json.loads(out)
    return data


returnable_fields = get_returnable_fields('wgs_set')
returnable_fields = [_['columnId'] for _ in returnable_fields]