예제 #1
0
    def search_by_keywords_and_filters(self, keyword, query_filter, page_size, page, date_gap, sort_direction, sort_fields):
        """
        search PRIDE API projects by keyword and filters
        :param keyword: keyword to search projects
        :param query_filter: Parameters to filter the search results
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param date_gap: A date range field with possible values of +1MONTH, +1YEAR
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_fields: Field(s) for sorting the results on
        :return: PRIDE projects in json format
        """
        request_url = self.api_base_url + "search/projects?keyword=" + keyword + "&"

        if query_filter:
            request_url = request_url + "filter=" + query_filter + "&"

        request_url = request_url + "pageSize=" + str(page_size) + "&page=" + str(page) + "&"

        if date_gap != "":
            request_url = request_url + "dateGap=" + str(date_gap) + "&"

        request_url = request_url + "sortDirection=" + sort_direction + "&sortFields=" + sort_fields

        headers = {"Accept": "application/JSON"}
        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #2
0
    def protein_evidences(self, project_accession, assay_accession,
                          reported_accession, page_size, page, sort_direction,
                          sort_conditions):
        """
        search protein_evidences from PRIDE API
        :param project_accession: PRIDE accession
        :param assay_accession: PRIDE assay accession
        :param reported_accession: PRIDE reported accession
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_conditions: Field(s) for sorting the results on
        :return: return protein evidences in json format
        """

        request_url = self.api_base_url + "proteinevidences?"

        if project_accession:
            request_url = request_url + "projectAccession=" + project_accession + "&"

        if assay_accession:
            request_url = request_url + "assayAccession=" + assay_accession + "&"

        if reported_accession:
            request_url = request_url + "reportedAccession=" + reported_accession + "&"

        request_url = request_url + "pageSize=" + str(
            page_size
        ) + "&page=" + str(
            page
        ) + "&sortDirection=" + sort_direction + "&sortConditions=" + sort_conditions

        headers = {"Accept": "application/JSON"}
        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #3
0
    def update_msrun_metadata(self, filename, token):
        """
        Updates the metadata extracted from the raw file into MongoDB database
        :param filename: metadata json file
        :param token: pride authentication token to access the api update method
        :return: response
        """

        # get project file accession from the prefix of the file name (e.g: PXF00000145820)
        accession = filename.split('-', 1)[0]

        url = self.base_url + "msruns/" + accession + "/updateMetadata"
        headers = {
            'Content-type': 'application/json',
            'Accept': 'application/json',
            'Authorization': 'Bearer ' + token
        }

        with open(filename) as json_file:
            data = json.load(json_file)
            logging.debug(json.dumps(data))

            response = Util.update_api_call(url, headers, json.dumps(data))

        return response
예제 #4
0
    def get_all_paged_files(self, query_filter, page_size, page,
                            sort_direction, sort_conditions):
        """
         Get all filtered pride submission files
        :param query_filter: Parameters to filter the search results
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_conditions: Field(s) for sorting the results on
        :return: paged file list on JSON format
        """
        """
           
        """
        request_url = self.api_base_url + "files?"

        if query_filter:
            request_url = request_url + "filter=" + query_filter + "&"

        request_url = request_url + "pageSize=" + str(
            page_size
        ) + "&page=" + str(
            page
        ) + "&sortDirection=" + sort_direction + "&sortConditions=" + sort_conditions

        headers = {"Accept": "application/JSON"}
        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #5
0
 def get_reanalysis_projects_by_accession(self, accession):
     """
         search PRIDE projects by reanalysis accession
         :return: project list on JSON format
     """
     request_url = self.api_base_url + "projects/reanalysis/" + accession
     headers = {"Accept": "application/JSON"}
     response = Util.get_api_call(request_url, headers)
     return response.json()
예제 #6
0
    def get_all_raw_file_list(self, project_accession):
        """
        Get all the file list from PRIDE api in JSON format
        :return: file list on JSON format
        """
        request_url = self.api_base_url + "files/byProject?accession=" + project_accession + ",fileCategory.value==RAW"
        headers = {"Accept": "application/JSON"}

        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #7
0
 def get_projects(self, page_size, page, sort_direction, sort_conditions):
     """
        get projects from PRIDE API in JSON format
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_conditions: Field(s) for sorting the results on
        :return: paged peptide_evidences in json format
    """
     request_url = self.api_base_url + "projects?" + "pageSize=" + str(page_size) + "&page=" + str(page) + "&sortDirection=" + sort_direction + "&sortConditions=" + sort_conditions
     headers = {"Accept": "application/JSON"}
     response = Util.get_api_call(request_url, headers)
     return response.json()
예제 #8
0
 def get_similar_projects_by_accession(self, accession):
     """
     Search similar projects by accession
     :param accession: PRIDE accession
     :return: similar PRIDE projects
     """
     """
         search PRIDE project's files by accession
         :return: file list on JSON format
     """
     request_url = self.api_base_url + "projects/" + accession + "/files"
     headers = {"Accept": "application/JSON"}
     response = Util.get_api_call(request_url, headers)
     return response.json()
예제 #9
0
 def get_file_from_api(self, accession, file_name):
     """
     Fetches file from API
     :param accession: PRIDE accession
     :param file_name: file name
     :return: file in json format
     """
     request_url = self.api_base_url + "files/byProject?accession=" + accession + ",fileName==" + file_name
     headers = {"Accept": "application/JSON"}
     try:
         response = Util.get_api_call(request_url, headers)
         return response.json()
     except Exception as e:
         raise Exception("File not found" + str(e))
예제 #10
0
    def spectra_evidences(self, usi, project_accession, assay_accession,
                          peptide_sequence, modified_sequence, result_type,
                          page_size, page, sort_direction, sort_conditions):
        """
        Search spectra evidences from PRIDE API
        :param usi: USI
        :param project_accession: PRIDE project accession
        :param assay_accession: PRIDE assay accession
        :param peptide_sequence: PRIDE peptide sequence
        :param modified_sequence: modified sequence
        :param result_type: result type
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_conditions: Field(s) for sorting the results on
        :return: spectra_evidences in JSON format
        """

        request_url = self.api_base_url + "spectra?"

        if usi:
            usiArray = usi.split("\\n")
            for usiElement in usiArray:
                request_url = request_url + "usi=" + usiElement + "&"

        if project_accession:
            request_url = request_url + "projectAccession=" + project_accession + "&"

        if assay_accession:
            request_url = request_url + "assayAccession=" + assay_accession + "&"

        if peptide_sequence:
            request_url = request_url + "peptideSequence=" + peptide_sequence + "&"

        if modified_sequence:
            request_url = request_url + "modifiedSequence=" + modified_sequence + "&"

        if result_type:
            request_url = request_url + "resultType=" + result_type + "&"

        request_url = request_url + "pageSize=" + str(
            page_size
        ) + "&page=" + str(
            page
        ) + "&sortDirection=" + sort_direction + "&sortConditions=" + sort_conditions

        headers = {"Accept": "application/JSON"}
        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #11
0
    def get_files_by_accession(self, accession, query_filter, page_size, page, sort_direction, sort_conditions):
        """
        search PRIDE project's files by accession
        :param accession: PRIDE project accession
        :param query_filter: Parameters to filter the search results
        :param page_size: Number of results to fetch in a page
        :param page: Identifies which page of results to fetch
        :param sort_direction: Sorting direction: ASC or DESC
        :param sort_conditions: Field(s) for sorting the results on
        :return: PRIDE project files
        """
        request_url = self.api_base_url + "projects/" + accession + "/files?"

        if query_filter:
            request_url = request_url + "filter=" + query_filter + "&"

        request_url = request_url + "pageSize=" + str(page_size) + "&page=" + str(page) + "&sortDirection=" + sort_direction + "&sortConditions=" + sort_conditions

        headers = {"Accept": "application/JSON"}
        response = Util.get_api_call(request_url, headers)
        return response.json()
예제 #12
0
    def plot_monthly_submissions(output_filename):
        """
        Plot monthly submission as a bar chart and save into a file
        :param output_filename: html output file
        :return:
        """

        # get monthly submission data from API
        request_url = base_url + "stats/submissions-monthly"
        headers = {"Accept": "application/JSON"}

        response = Util.get_api_call(request_url, headers)
        response_body = response.json()

        # sort data by past to present
        data = [
            go.Bar(x=[d[0] for d in response_body][::-1],
                   y=[d[1] for d in response_body][::-1])
        ]

        # plot the data in a bar chart
        plotly.offline.plot(data, filename=output_filename, auto_open=True)