From ce26ffcae5e876cf4127173c92f0eddffc9830da Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 22 Apr 2016 16:42:23 +0100 Subject: [PATCH] JAL-1563 JAL-2071 Update and completed implementation for UniProt FTS support --- resources/fts/uniprot_data_columns.conf | 223 ++++++++++++-------- .../fts/service/uniprot/UniProtFTSRestClient.java | 200 +++++++++++++++--- .../fts/service/uniprot/UniprotFTSPanel.java | 131 +++++++++++- 3 files changed, 425 insertions(+), 129 deletions(-) diff --git a/resources/fts/uniprot_data_columns.conf b/resources/fts/uniprot_data_columns.conf index 5eebd15..10f5043 100644 --- a/resources/fts/uniprot_data_columns.conf +++ b/resources/fts/uniprot_data_columns.conf @@ -1,106 +1,153 @@ -pdb_data_columns +uniprot_data_columns # _group.id _group.name _group.sort_order -g1;Quality Measures;1 +g1;Quality Measures;3 g2;Cross References;2 -g3;Names & Taxonomy;3 +g3;Names & Taxonomy;1 g4;Procedures & Softwares;4 g5;Date Of;5 g6;Miscellenous;6 +g7;Sequences;7 +g8;Function;8 +g9;Interaction;9 +g10;Expression;10 +g11;Gene Ontology;11 +g12;Pathology & Biotech;12 +g13;Subcellular location;13 +g14;PTM / Processing;14 +g15;Structure;15 +g16;Publications;16 +g17;Date of;17 +g18;Family & Domain;18 +# +_data_column.primary_key;entry name +_data_column.default_response_page_size;100 # _data_column.name _data_column.code _data_column.group_id +_data_column.data_type _data_column.min_col_width _data_column.max_col_width _data_column.preferred_col_width -_data_column.is_primary_key _data_column.is_shown_by_default _data_column.is_searchable -PDB Id;pdb_id;g2;40;60;45;true;true;true -Title;title;g6;300;1500;400;false;true;false -Molecule;molecule_name;g3;50;400;95;false;false;true -Molecule Type;molecule_type;g3;50;400;95;false;false;true -Sequence;molecule_sequence;g6;50;400;95;false;false;false -PFAM Accession;pfam_accession;g2;50;400;95;false;false;true -PFAM Name;pfam_name;g3;50;400;95;false;false;true -InterPro Name;interpro_name;g3;50;400;95;false;false;false -InterPro Accession;interpro_accession;g2;50;400;95;false;false;false -UniProt Id;uniprot_id;g2;50;400;95;false;false;true -UniProt Accession;uniprot_accession;g2;50;400;95;false;false;false -UniProt Coverage;uniprot_coverage;g6;50;400;95;false;false;false -Uniprot Features;uniprot_features;g6;50;400;95;false;false;false -R Factor;r_factor;g1;50;150;85;false;false;false -Resolution;resolution;g1;50;150;85;false;true;false -Data Quality;data_quality;g1;50;150;85;false;false;false -Overall Quality;overall_quality;g1;50;150;85;false;false;false -Number of Polymers;number_of_polymers;g6;50;400;95;false;false;false -Number of Protein Chains;number_of_protein_chains;g6;50;400;95;false;false;false -Number of Bound Molecule;number_of_bound_molecules;g6;50;400;95;false;false;false -Number of Polymer Residue;number_of_polymer_residues;g6;50;400;95;false;false;false -GENUS;genus;g3;50;400;95;false;false;true -Gene Name;gene_name;g3;50;400;95;false;false;true -Experimental Method;experimental_method;g4;50;400;95;false;false;false -GO Id;go_id;g2;50;400;95;false;false;false -Assembly Id;assembly_id;g2;50;400;95;false;false;false -Assembly Form;assembly_form;g6;50;400;95;false;false;false -Assembly Type;assembly_type;g6;50;400;95;false;false;false -Space Group;spacegroup;g6;50;400;95;false;false;false -Cath Code;cath_code;g2;50;400;95;false;false;false -Tax Id;tax_id;g2;50;400;95;false;false;false -Tax Query;tax_query;g2;50;400;95;false;false;false -Interacting Entity Id;interacting_entity_id;g2;50;400;95;false;false;false -Interacting Molecules;interacting_molecules;g6;50;400;95;false;false;false -Pubmed Id;pubmed_id;g2;50;400;95;false;false;false -Status;status;g6;50;400;95;false;false;false -Model Quality;model_quality;g1;50;150;85;false;false;false -Pivot Resolution;pivot_resolution;g1;50;150;85;false;false;false -Data reduction software;data_reduction_software;g4;50;400;95;false;false;false -Max observed residues;max_observed_residues;g6;50;400;95;false;false;false -Organism scientific name;organism_scientific_name;g3;50;400;95;false;false;false -Super kingdom;superkingdom;g3;50;400;95;false;false;false -Rank;rank;g3;50;400;95;false;false;false -Crystallisation Ph;crystallisation_ph;g6;50;400;95;false;false;false -Biological Function;biological_function;g6;50;400;95;false;false;false -Biological Process;biological_process;g6;50;400;95;false;false;false -Biological Cell Component;biological_cell_component;g6;50;400;95;false;false;false -Compound Name;compound_name;g3;50;400;95;false;false;false -Compound Id;compound_id;g2;50;400;95;false;false;false -Compound Weight;compound_weight;g6;50;400;95;false;false;false -Compound Systematic Name;compound_systematic_name;g3;50;400;95;false;false;false -Interacting Ligands;interacting_ligands;g6;50;400;95;false;false;false -Journal;journal;g6;50;400;95;false;false;false -All Authors;all_authors;g6;50;400;95;false;false;false -Experiment Data Available;experiment_data_available;g6;50;400;95;false;false;false -Diffraction Protocol;diffraction_protocol;g4;50;400;95;false;false;false -Refinement Software;refinement_software;g4;50;400;95;false;false;false -Structure Determination Method;structure_determination_method;g4;50;400;95;false;false;false -Synchrotron Site;synchrotron_site;g6;50;400;95;false;false;false -Sample Preparation Method;sample_preparation_method;g4;50;400;95;false;false;false -Entry Authors;entry_authors;g6;50;400;95;false;false;false -Citation Title;citation_title;g6;50;400;95;false;false;false -Structure Solution Software;structure_solution_software;g4;50;400;95;false;false;false -Entry Entity;entry_entity;g6;50;400;95;false;false;false -R Free;r_free;g1;50;150;85;false;false;false -Number of Polymer Entities;number_of_polymer_entities;g6;50;400;95;false;false;false -Number of Bound Entities;number_of_bound_entities;g6;50;400;95;false;false;false -Crystallisation Reservoir;crystallisation_reservoir;g6;50;400;95;false;false;false -Data Scalling Software;data_scaling_software;g4;50;400;95 ;false;false;false -Detector;detector;g6;50;400;95;false;false;false -Detector Type;detector_type;g6;50;400;95;false;false;false -Modified Residue Flag;modified_residue_flag;g6;50;400;95;false;false;false -Number of Copies;number_of_copies;g6;50;400;95;false;false;false -Struc Asym Id;struct_asym_id;g2;50;400;95;false;false;false -Homologus PDB Entity Id;homologus_pdb_entity_id;g2;50;400;95;false;false;false -Molecule Synonym;molecule_synonym;g6;50;400;95;false;false;false -Deposition Site;deposition_site;g6;50;400;95;false;false;false -Synchrotron Beamline;synchrotron_beamline;g6;50;400;95;false;false;false -Entity Id; entity_id;g2;50;400;95;false;false;false -Beam Source Name;beam_source_name;g3;50;400;95;false;false;false -Processing Site;processing_site;g6;50;400;95;false;false;false -Entity Weight;entity_weight;g6;50;400;95;false;false;false -Version;_version_;g6;50;400;95;false;false;false -ALL;text;g6;50;400;95;false;false;true +Entry Name;entry name;String;g3;80;100;85;true;true +Protein names;protein names;String;g3;300;1500;500;true;true +Gene Names;genes;String;g3;50;1000;95;true;true +Organism;organism;String;g3;50;1000;95;true;true +Organism ID;organism-id;int;g3;60;100;80;false;true +Proteomes;proteome;String;g3;50;1000;95;false;true +Taxonomic lineage (ALL);lineage(ALL);String;g3;50;400;95;false;false +Virus hosts;virus hosts;String;g3;50;1000;95;false;true +Fragment;fragment;String;g7;50;1000;95;false;true +Gene encoded by;encodedon;String;g7;50;1000;95;false;true +Alternative products (isoforms);comment(ALTERNATIVE PRODUCTS);String;g7;50;1000;95;false;false +Erroneous gene model prediction;comment(ERRONEOUS GENE MODEL PREDICTION);String;g7;50;1000;95;false;false +Erroneous initiation;comment(ERRONEOUS INITIATION);String;g7;50;1000;95;false;false +Erroneous translation;comment(ERRONEOUS TRANSLATION);String;g7;50;1000;95;false;false +Frameshift;comment(FRAMESHIFT);String;g7;50;1000;95;false;false +Mass spectrometry;comment(MASS SPECTROMETRY);String;g7;50;1000;95;false;false +Polymorphism;comment(POLYMORPHISM);String;g7;50;1000;95;false;false +RNA editing;comment(RNA EDITING);String;g7;50;1000;95;false;false +Sequence caution;comment(SEQUENCE CAUTION);String;g7;50;1000;95;false;false +Length;length;int;g7;50;100;95;false;true +Mass;mass;String;g7;50;100;80;false;true +Sequence;sequence;String;g7;50;1000;95;false;true +Alternative sequence;feature(ALTERNATIVE SEQUENCE);String;g7;50;1000;95;false;false +Natural variant;feature(NATURAL VARIANT);String;g7;50;1000;95;false;false +Non-adjacent residues;feature(NON ADJACENT RESIDUES);String;g7;50;1000;95;false;false +Non-standard residue;feature(NON STANDARD RESIDUE);String;g7;50;1000;95;false;false +Non-terminal residue;feature(NON TERMINAL RESIDUE);String;g7;50;1000;95;false;false +Sequence conflict;feature(SEQUENCE CONFLICT);String;g7;50;1000;95;false;false +Sequence uncertainty;feature(SEQUENCE UNCERTAINTY);String;g7;50;1000;95;false;false +Version (Sequence);version(sequence);String;g7;50;1000;95;false;false +EC number;ec;String;g8;50;1000;95;false;true +Absorption;comment(ABSORPTION);String;g8;50;1000;95;false;false +Catalytic activity;comment(CATALYTIC ACTIVITY);String;g8;50;1000;95;false;false +Cofactor;comment(COFACTOR);String;g8;50;1000;95;false;false +Enzyme regulation;comment(ENZYME REGULATION);String;g8;50;1000;95;false;false +Function [CC];comment(FUNCTION);String;g8;50;1000;95;false;false +Kinetics;comment(KINETICS);String;g8;50;1000;95;false;false +Pathway;comment(PATHWAY);String;g8;50;1000;95;false;false +Redox potential;comment(REDOX POTENTIAL);String;g8;50;1000;95;false;false +Temperature dependence;comment(TEMPERATURE DEPENDENCE);String;g8;50;1000;95;false;false +pH dependence;comment(PH DEPENDENCE);String;g8;50;1000;95;false;false +Active site;feature(ACTIVE SITE);String;g8;50;1000;95;false;false +Binding site;feature(BINDING SITE);String;g8;50;1000;95;false;false +DNA binding;feature(DNA BINDING);String;g8;50;1000;95;false;false +Metal binding;feature(METAL BINDING);String;g8;50;1000;95;false;false +Nucleotide binding;feature(NP BIND);String;g8;50;1000;95;false;false +Site;feature(SITE);String;g8;50;1000;95;false;false +Annotation;annotation score;String;g6;50;1000;95;false;true +Features;features;String;g6;50;1000;95;false;true +Caution;comment(CAUTION);String;g6;50;1000;95;false;false +Miscellaneous [CC];comment(GENERAL);String;g6;50;1000;95;false;false +Keywords;keywords;String;g6;50;1000;95;false;true +Protein existence;existence;String;g6;50;1000;95;false;true +Status;reviewed;String;g6;50;1000;95;false;true +ALL;entry name;String;g7;50;1000;95;false;true; +Subunit structure [CC];comment(SUBUNIT);String;g9;50;1000;95;false;false +Interacts with;interactor;String;g9;50;1000;95;false;true +Developmental stage;comment(DEVELOPMENTAL STAGE);String;g10;50;1000;95;false;false +Induction;comment(INDUCTION);String;g10;50;1000;95;false;false +Tissue specificity;comment(TISSUE SPECIFICITY);String;g10;50;1000;95;false;false +Gene ontology (GO);go;String;g11;50;1000;95;false;true +Gene ontology (biological process);go(biological process);String;g11;50;1000;95;false;false +Gene ontology (molecular function);go(molecular function);String;g11;50;1000;95;false;false +Gene ontology (cellular component);go(cellular component);String;g11;50;1000;95;false;false +Gene ontology IDs;go-id;String;g11;50;1000;95;false;true +Allergenic properties;comment(ALLERGEN);String;g12;50;1000;95;false;false +Biotechnological use;comment(BIOTECHNOLOGY);String;g12;50;1000;95;false;false +Disruption phenotype;comment(DISRUPTION PHENOTYPE);String;g12;50;1000;95;false;false +Involvement in disease;comment(DISEASE);String;g12;50;1000;95;false;false +Pharmaceutical use;comment(PHARMACEUTICAL);String;g12;50;1000;95;false;false +Toxic dose;comment(TOXIC DOSE);String;g12;50;1000;95;false;false +Subcellular location [CC];comment(SUBCELLULAR LOCATION);String;g13;50;1000;95;false;false +Intramembrane;feature(INTRAMEMBRANE);String;g13;50;1000;95;false;false +Topological domain;feature(TOPOLOGICAL DOMAIN);String;g13;50;1000;95;false;false +Transmembrane;feature(TRANSMEMBRANE);String;g13;50;1000;95;false;false +Post-translational modification;comment(PTM);String;g14;50;1000;95;false;false +Chain;feature(CHAIN);String;g14;50;1000;95;false;false +Cross-link;feature(CROSS LINK);String;g14;50;1000;95;false;false +Disulfide bond;feature(DISULFIDE BOND);String;g14;50;1000;95;false;false +Glycosylation;feature(GLYCOSYLATION);String;g14;50;1000;95;false;false +Initiator methionine;feature(INITIATOR METHIONINE);String;g14;50;1000;95;false;false +Lipidation;feature(LIPIDATION);String;g14;50;1000;95;false;false +Modified residue;feature(MODIFIED RESIDUE);String;g14;50;1000;95;false;false +Peptide;feature(PEPTIDE);String;g14;50;1000;95;false;false +Propeptide;feature(PROPEPTIDE);String;g14;50;1000;95;false;false +Signal peptide;feature(SIGNAL);String;g14;50;1000;95;false;false +Transit peptide;feature(TRANSIT);String;g14;50;1000;95;false;false +3D;3d;String;g15;50;1000;95;false;false +Beta strand;feature(BETA STRAND);String;g15;50;1000;95;false;false +Helix;feature(HELIX);String;g15;50;1000;95;false;false +Turn;feature(TURN);String;g15;50;1000;95;false;false +PubMed ID;citation;String;g16;50;1000;95;false;true +Date of creation;created;String;g17;80;150;100;true;true +Date of last modification;last-modified;String;g17;80;150;100;true;true +Date of last sequence modification;sequence-modified;String;g17;80;150;100;false;true +Version (entry);version(entry);int;g17;80;100;80;false;false +Domain [CC];comment(DOMAIN);String;g18;80;1000;95;false;false +Sequence similarities;comment(SIMILARITY);String;g18;50;1000;95;false;false +Protein families;families;String;g18;50;1000;95;false;true +Coiled coil;feature(COILED COIL);String;g18;50;1000;95;false;false +Compositional bias;feature(COMPOSITIONAL BIAS);String;g18;50;1000;95;false;false +Domain [FT];feature(DOMAIN EXTENT);String;g18;50;1000;95;false;false +Motif;feature(MOTIF);String;g18;50;1000;95;false;false +Region;feature(REGION);String;g18;50;1000;95;false;false +Repeat;feature(REPEAT);String;g18;50;1000;95;false;false +Zinc finger;feature(ZINC FINGER);String;g18;50;1000;95;false;false +Cross-reference (EMBL);database(EMBL);String;g2;50;1000;95;false;false +Cross-reference (PDB);database(PDB);String;g2;50;1000;95;false;false +Cross-reference (ENSEMBL);database(ENSEMBL);String;g2;50;1000;95;false;false +Cross-reference (PFAM);database(PFAM);String;g2;50;1000;95;false;false +Cross-reference (RFAM);database(RFAM);String;g2;50;1000;95;false;false +Cross-reference (CATH);database(CATH);String;g2;50;1000;95;false;false +Cross-reference (SCOPE);database(SCOPE);String;g2;50;1000;95;false;false +Cross-reference (GO);database(GO);String;g2;50;1000;95;false;false +Cross-reference (INTERPRO);database(INTERPRO);String;g2;50;1000;95;false;false +Mapped PubMed ID;citationmapping;String;g16;50;1000;95;false;true # diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index 2930468..310b1c6 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -1,10 +1,38 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.service.uniprot; +import jalview.fts.api.FTSData; +import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; import jalview.fts.core.FTSRestClient; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + import javax.ws.rs.core.MediaType; import com.sun.jersey.api.client.Client; @@ -13,63 +41,167 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; -public class UniProtRestClient extends FTSRestClient +public class UniProtFTSRestClient extends FTSRestClient { private static FTSRestClientI instance = null; public static final String UNIPROT_SEARCH_ENDPOINT = "http://www.uniprot.org/uniprot/?"; - private static int DEFAULT_RESPONSE_SIZE = 200; - @Override public FTSRestResponse executeRequest(FTSRestRequest uniportRestRequest) { ClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create(clientConfig); - @SuppressWarnings("unchecked") - // String wantedFields = - // getUniProtDocFieldsAsCommaDelimitedString((Collection) - // uniportRestRequest - // .getWantedFields()); - int responseSize = (uniportRestRequest.getResponseSize() == 0) ? DEFAULT_RESPONSE_SIZE + String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(uniportRestRequest + .getWantedFields()); + int responseSize = (uniportRestRequest.getResponseSize() == 0) ? getDefaultResponsePageSize() : uniportRestRequest.getResponseSize(); + String query = uniportRestRequest.getFieldToSearchBy() + ":" + + uniportRestRequest.getSearchTerm(); + // + (uniportRestRequest.isAllowUnpublishedEntries() ? "" + // : " AND status:REL"); + // System.out.println(">>>>> Query : " + query); + // System.out.println(">>>>> Columns : " + wantedFields); WebResource webResource = null; - webResource = client.resource(UNIPROT_SEARCH_ENDPOINT) .queryParam("format", "tab") - // .queryParam("columns", wantedFields) + .queryParam("columns", wantedFields) .queryParam("limit", String.valueOf(responseSize)) - .queryParam("query", "name:filaggrin"); + .queryParam("query", query); // Execute the REST request ClientResponse clientResponse = webResource .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); - String responseString = clientResponse.getEntity(String.class); - String[] results = responseString.split("\n"); - for (String result : results) - { - String[] columns = result.split("\t"); - System.out.println("Entry : " + columns[0]); - System.out.println("Entry name : " + columns[1]); - System.out.println("Status : " + columns[2]); - System.out.println("Protein names : " + columns[3]); - System.out.println("Gene name : " + columns[4]); - System.out.println("Organism : " + columns[5]); - System.out.println("Lenght : " + columns[6]); - System.out.println(""); - } - + String uniProtTabDelimittedResponseString = clientResponse + .getEntity(String.class); // Make redundant objects eligible for garbage collection to conserve // memory clientResponse = null; client = null; - return null; + // System.out.println(">>>>> response : " + // + uniProtTabDelimittedResponseString); + return parseUniprotResponse(uniProtTabDelimittedResponseString, + uniportRestRequest); - // Process the response and return the result to the caller. - // return parsePDBJsonResponse(responseString, pdbRestRequest); - // System.out.println(">>>>> " + responseString); + } + public FTSRestResponse parseUniprotResponse( + String uniProtTabDelimittedResponseString, + FTSRestRequest uniprotRestRequest) + { + FTSRestResponse searchResult = new FTSRestResponse(); + List result = null; + String[] foundDataRow = uniProtTabDelimittedResponseString.split("\n"); + if (foundDataRow != null && foundDataRow.length > 0) + { + result = new ArrayList(); + String titleRow = getDataColumnsFieldsAsTabDelimitedString(uniprotRestRequest + .getWantedFields()); + // System.out.println(">>>>Title row : " + titleRow); + for (String dataRow : foundDataRow) + { + if (dataRow.equalsIgnoreCase(titleRow)) + { + // System.out.println(">>>>>>>>>> matched!!!"); + continue; + } + // System.out.println(dataRow); + result.add(getFTSData(dataRow, uniprotRestRequest)); + } + searchResult.setNumberOfItemsFound(result.size()); + searchResult.setSearchSummary(result); + } + return searchResult; + } + + public static FTSData getFTSData(String tabDelimittedDataStr, + FTSRestRequest request) + { + String primaryKey = null; + + Object[] summaryRowData; + + Collection diplayFields = request.getWantedFields(); + int colCounter = 0; + summaryRowData = new Object[diplayFields.size()]; + String[] columns = tabDelimittedDataStr.split("\t"); + for (FTSDataColumnI field : diplayFields) + { + try + { + String fieldData = columns[colCounter]; + if (field.isPrimaryKeyColumn()) + { + primaryKey = fieldData; + summaryRowData[colCounter++] = primaryKey; + } + else if (fieldData == null || fieldData.isEmpty()) + { + summaryRowData[colCounter++] = null; + } + else + { + try + { + summaryRowData[colCounter++] = (field.getDataColumnClass() == Integer.class) ? Integer + .valueOf(fieldData) + : (field.getDataColumnClass() == Double.class) ? Double + .valueOf(fieldData) : fieldData; + } catch (Exception e) + { + e.printStackTrace(); + System.out.println("offending value:" + fieldData); + } + } + } catch (Exception e) + { + // e.printStackTrace(); + } + } + + final String primaryKey1 = primaryKey; + + final Object[] summaryRowData1 = summaryRowData; + return new FTSData() + { + @Override + public Object[] getSummaryData() + { + return summaryRowData1; + } + + @Override + public Object getPrimaryKey() + { + return primaryKey1; + } + + /** + * Returns a string representation of this object; + */ + @Override + public String toString() + { + StringBuilder summaryFieldValues = new StringBuilder(); + for (Object summaryField : summaryRowData1) + { + summaryFieldValues.append( + summaryField == null ? " " : summaryField.toString()) + .append("\t"); + } + return summaryFieldValues.toString(); + } + + /** + * Returns hash code value for this object + */ + @Override + public int hashCode() + { + return Objects.hash(primaryKey1, this.toString()); + } + }; } @@ -77,15 +209,15 @@ public class UniProtRestClient extends FTSRestClient { if (instance == null) { - instance = new UniProtRestClient(); + instance = new UniProtFTSRestClient(); } return instance; } @Override - public String getColumnDataConfigFile() + public String getColumnDataConfigFileName() { - return "fts/uniprot_data_columns.conf"; + return getResourceFile("fts/uniprot_data_columns.conf"); } } diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index 51d7735..dcef358 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -1,14 +1,44 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.service.uniprot; +import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; +import jalview.fts.core.FTSRestRequest; +import jalview.fts.core.FTSRestResponse; import jalview.fts.core.GFTSPanel; import jalview.gui.SequenceFetcher; import jalview.util.MessageManager; +import java.util.HashSet; + @SuppressWarnings("serial") public class UniprotFTSPanel extends GFTSPanel { + private static String defaultFTSFrameTitle = MessageManager + .getString("label.uniprot_sequence_fetcher"); + + private String ftsFrameTitle = defaultFTSFrameTitle; public UniprotFTSPanel(SequenceFetcher seqFetcher) { @@ -18,30 +48,117 @@ public class UniprotFTSPanel extends GFTSPanel } @Override - public void txt_search_ActionPerformed() + public void searchAction() { - // TODO Auto-generated method stub + new Thread() + { + @Override + public void run() + { + ftsFrameTitle = defaultFTSFrameTitle; + reset(); + if (getTypedText().length() > 0) + { + setSearchInProgress(true); + long startTime = System.currentTimeMillis(); + + String searchTarget = ((FTSDataColumnI) cmb_searchTarget + .getSelectedItem()).getCode(); + + wantedFields = UniProtFTSRestClient.getInstance() + .getAllDefaulDisplayedDataColumns(); + String searchTerm = txt_search.getText(); + + FTSRestRequest request = new FTSRestRequest(); + request.setFieldToSearchBy(searchTarget); + request.setSearchTerm(searchTerm); + request.setWantedFields(wantedFields); + FTSRestClientI uniProtRestCleint = UniProtFTSRestClient + .getInstance(); + FTSRestResponse resultList; + try + { + resultList = uniProtRestCleint.executeRequest(request); + } catch (Exception e) + { + e.printStackTrace(); + setErrorMessage(e.getMessage()); + checkForErrors(); + return; + } + + if (resultList.getSearchSummary() != null + && resultList.getSearchSummary().size() > 0) + { + getResultTable().setModel( + FTSRestResponse.getTableModel(request, + resultList.getSearchSummary())); + FTSRestResponse.configureTableColumn(getResultTable(), + wantedFields); + getResultTable().setVisible(true); + } + + long endTime = System.currentTimeMillis(); + int resultSetCount = resultList.getNumberOfItemsFound(); + String result = (resultSetCount > 1) ? MessageManager + .getString("label.results") : MessageManager + .getString("label.result"); + updateSearchFrameTitle(defaultFTSFrameTitle + " - " + + resultSetCount + " " + result + " (" + + (endTime - startTime) + " milli secs)"); + setSearchInProgress(false); + } + } + }.start(); } @Override - public void btn_ok_ActionPerformed() + public void okAction() { - // TODO Auto-generated method stub + disableActionButtons(); + StringBuilder selectedIds = new StringBuilder(); + HashSet selectedIdsSet = new HashSet(); + int primaryKeyColIndex = 0; + try + { + primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( + wantedFields, false); + } catch (Exception e) + { + e.printStackTrace(); + } + int[] selectedRows = getResultTable().getSelectedRows(); + for (int summaryRow : selectedRows) + { + String idStr = getResultTable().getValueAt(summaryRow, + primaryKeyColIndex).toString(); + selectedIdsSet.add(idStr); + } - } + for (String selectedId : selectedIdsSet) + { + selectedIds.append(selectedId).append(";"); + } + String ids = selectedIds.toString(); + // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids); + seqFetcher.getTextArea().setText(ids); + Thread worker = new Thread(seqFetcher); + worker.start(); + delayAndEnableActionButtons(); + } @Override public FTSRestClientI getFTSRestClient() { - return UniProtRestClient.getInstance(); + return UniProtFTSRestClient.getInstance(); } @Override public String getFTSFrameTitle() { - return MessageManager.getString("label.uniprot_sequence_fetcher"); + return ftsFrameTitle; } } -- 1.7.10.2