JAL-3829 JAL-3865 StructureChooserQuerySource implementation now dependent on the...
[jalview.git] / src / jalview / gui / structurechooser / StructureChooserQuerySource.java
index 733e6fc..4faa2de 100644 (file)
@@ -206,4 +206,36 @@ public abstract class StructureChooserQuerySource
    *         will be constructed with 'addSeparator==true'
    */
   public abstract List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER);
+
+  /**
+   * construct a structure chooser query source for the given set of sequences
+   * @param selectedSeqs
+   * @return PDBe or 3DB query source
+   */
+  public static StructureChooserQuerySource getQuerySourceFor(
+          SequenceI[] selectedSeqs)
+  {
+    ThreeDBStructureChooserQuerySource tdbSource = new ThreeDBStructureChooserQuerySource();
+    boolean hasUniprot=false;
+    boolean hasNA=false,hasProtein=false;
+    for (SequenceI seq:selectedSeqs)
+    {
+      hasNA|=!seq.isProtein();
+      hasProtein |= seq.isProtein();
+      if (seq.isProtein())
+      {
+        String query = tdbSource.buildQuery(seq);
+        if (query!=null && query.length()>0)
+        {
+          hasUniprot=true;
+        }
+      }
+    }
+    if (hasProtein && hasUniprot && !hasNA)
+    {
+      return tdbSource;
+    }
+    return new PDBStructureChooserQuerySource();
+  }
+
 }
\ No newline at end of file