Clover icon

Coverage Report

  1. Project Clover database Thu Jun 4 2026 14:16:38 BST
  2. Package jalview.gui

File AssociatePdbFileWithSeq.java

 

Coverage histogram

../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

20
31
4
1
141
87
18
0.58
7.75
4
4.5

Classes

Class Line # Actions
AssociatePdbFileWithSeq 43 31 18
0.509090950.9%
 

Contributing tests

This file is covered by 33 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import java.io.File;
24   
25    import jalview.api.StructureSelectionManagerProvider;
26    import jalview.bin.Console;
27    import jalview.datamodel.PDBEntry;
28    import jalview.datamodel.SequenceI;
29    import jalview.io.DataSourceType;
30    import jalview.io.StructureFile;
31    import jalview.structure.StructureImportSettings.TFType;
32    import jalview.structure.StructureSelectionManager;
33    import jalview.util.MessageManager;
34    import jalview.util.Platform;
35   
36    /**
37    * GUI related routines for associating PDB files with sequences. A single
38    * static method.
39    *
40    * @author JimP
41    *
42    */
 
43    public class AssociatePdbFileWithSeq
44    {
45   
 
46  0 toggle private AssociatePdbFileWithSeq()
47    {
48    // inaccessible
49    }
50   
51    /**
52    * Associate the given PDB file name or URL with a sequence. Do not map
53    * mouse-over events.
54    *
55    * @param fileName
56    * or URL
57    * @param type
58    * will be DataType.FILE or DataType.URL
59    * @param sequence
60    * to associate
61    * @param prompt
62    * true if the user should be asked what to do if the specified file
63    * does not seem to contain PDB information (StructureChooser only)
64    * @return null if file is not found
65    */
 
66  3 toggle public static PDBEntry associatePdbWithSeq(String fileName,
67    DataSourceType type, SequenceI sequence, boolean prompt)
68    {
69  3 return associatePdbWithSeq(fileName, type, sequence, null, prompt, Desktop.getInstance(),
70    TFType.DEFAULT, null, false);
71    }
 
72  67 toggle public static PDBEntry associatePdbWithSeq(String fileName, DataSourceType type,
73    SequenceI sequence,boolean prompt,
74    StructureSelectionManagerProvider ssmp, TFType tft,
75    String paeFilename, boolean doXferSettings)
76    {
77  67 return associatePdbWithSeq(fileName, type, sequence, null, prompt, ssmp,
78    tft, paeFilename, doXferSettings);
79    }
 
80  72 toggle public static PDBEntry associatePdbWithSeq(String fileName, DataSourceType type,
81    SequenceI sequence, String[] chains, boolean prompt,
82    StructureSelectionManagerProvider ssmp, TFType tft,
83    String paeFilename, boolean doXferSettings)
84    {
85  72 PDBEntry entry = new PDBEntry();
86   
87  70 SequenceI[] seqs= new SequenceI[chains==null ? 1 : chains.length];
88  144 for (int i=0;i<seqs.length;i++) {
89  72 seqs[i] = sequence;
90    }
91   
92  72 StructureFile pdbfile = StructureSelectionManager
93    .getStructureSelectionManager(ssmp)
94    .setMapping(false, seqs, chains, fileName, type, tft, paeFilename,
95    doXferSettings);
96  72 if (pdbfile == null)
97    {
98    // stacktrace already thrown so just return
99  0 return null;
100    }
101  72 String id = pdbfile.getId();
102  ? if (id == null && (id = (prompt
103    ? JvOptionPane.showInternalInputDialog(Desktop.getDesktopPane(),
104    MessageManager
105    .getString("label.couldnt_find_pdb_id_in_file"),
106    MessageManager.getString("label.no_pdb_id_in_file"),
107    JvOptionPane.QUESTION_MESSAGE)
108    : null)) == null)
109    {
110  0 return null;
111    }
112   
113    // TODO move this to a method in SequenceI and the comparator to PDBEntry
114  72 File sfile=new File(fileName);
115  72 if (sequence.getDatasetSequence()!=null && sequence.getDatasetSequence().hasPDBEntries()) {
116  72 for (PDBEntry pe: sequence.getDatasetSequence().getAllPDBEntries()) {
117  109 try {
118    // Normalise for local platform since we have just loaded this file. PASTED files will fail.
119  109 if (new File(pe.getFile()).getCanonicalPath().equals(sfile.getCanonicalPath())) {
120  72 if (chains==null || chains[0].equals(pe.getChainCode())) {
121  72 return pe;
122    }
123    } } catch (Exception ex) {
124  0 Console.error("Unexpected exception when examining structure file paths",ex);
125    }
126    }
127    }
128  0 entry.setId(id);
129  0 entry.setType(PDBEntry.Type.FILE);
130  0 entry.setFile(fileName);
131  0 sequence.getDatasetSequence().addPDBId(entry);
132  0 entry.setStructureFile(pdbfile);
133  0 StructureSelectionManager.getStructureSelectionManager(ssmp)
134    .registerPDBEntry(entry);
135  0 if (tft != null)
136  0 entry.setTempFacType(tft);
137  0 if (paeFilename != null)
138  0 entry.setPAEFile(paeFilename);
139  0 return entry;
140    }
141    }