From 66df1ea6fe1c1c352c2e030ef72d1d40f96a7eca Mon Sep 17 00:00:00 2001 From: Weiheng Liao Date: Tue, 29 Nov 2022 18:35:19 +0800 Subject: [PATCH] Update 2022.11.29 little change 1. add utility.get_result_from_file() 2. fixed some bugs --- patpat/querier.py | 4 ++-- patpat/utility.py | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/patpat/querier.py b/patpat/querier.py index d8d2d7f..4b32a2a 100644 --- a/patpat/querier.py +++ b/patpat/querier.py @@ -376,7 +376,7 @@ def get_properties(self): return self.digestion_params, self.source, self.filtered_peptides - def query(self): + def query(self, threshold=1): """Functions for external calls. 供外部调用的函数。 Raises: @@ -386,7 +386,7 @@ def query(self): raise ValueError('Please run func self.set_params() first. 请先运行self.set_params()函数') self.digestion() - self.search() + self.search(threshold=1) class UniProtPeptideQuerier(PeptideQuerier): diff --git a/patpat/utility.py b/patpat/utility.py index 0b0a3db..3f31cef 100644 --- a/patpat/utility.py +++ b/patpat/utility.py @@ -4,6 +4,7 @@ import os import re import time +import json import gzip from urllib import parse from ftplib import FTP @@ -162,7 +163,7 @@ def pagination_download_uniprot_proteome(identifier: str, reviewed: bool = True, total = int(response.headers['x-total-results']) fasta = [response.text] - for i in tqdm.tqdm(range(size, total, size)): + for _ in tqdm.tqdm(range(size, total, size)): try: response = session.get(response.links['next']['url']) fasta.extend([response.text]) @@ -266,3 +267,24 @@ def inner(): return _instance[cls] return inner + + +def get_result_from_file(task=None): + """Get Patpat search result from patpat_env/result//result.json + + Args: + task: uuid + + Returns: + dict, project metadata + """ + if task: + with open(f'patpat_env/result/{task}/result.json') as f: + data_json = ''.join(f.readlines()) + data_dict = json.loads(data_json) + f.close() + + return data_dict + + else: + print('Need to input task uuid.')