Clover icon

Coverage Report

  1. Project Clover database Wed Nov 12 2025 13:01:44 GMT
  2. Package jalview.bin.argparser

File StructuresFile.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

20
55
14
1
182
153
24
0.44
3.93
14
1.71

Classes

Class Line # Actions
StructuresFile 19 55 24
0.876404587.6%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    package jalview.bin.argparser;
2   
3    import java.io.File;
4    import java.util.ArrayList;
5    import java.util.List;
6   
7    import jalview.bin.Cache;
8    import jalview.bin.Console;
9    import jalview.datamodel.AlignmentI;
10    import jalview.datamodel.PDBEntry;
11    import jalview.datamodel.SequenceI;
12    import jalview.gui.AssociatePdbFileWithSeq;
13    import jalview.gui.Desktop;
14    import jalview.gui.StructureChooser;
15    import jalview.gui.StructureViewer.ViewerType;
16    import jalview.io.AppletFormatAdapter;
17    import jalview.io.DataSourceType;
18   
 
19    public class StructuresFile
20    {
21    private boolean superpose = Cache
22    .getDefault(StructureChooser.AUTOSUPERIMPOSE, true);
23   
24    private String viewerid = null;
25   
26    private ViewerType viewerType = ViewerType.JMOL;
27   
28    private List<StructureLine> structureLines;
29   
30    private List<SequenceI> seqs = new ArrayList<>();
31   
32    private List<PDBEntry> pdbs = new ArrayList<>();
33   
34    private AlignmentI alignment;
35   
 
36  5 toggle public StructuresFile(AlignmentI al, String filename)
37    {
38  5 alignment = al;
39  5 setStructureLines(parseStructuresFile(new File(filename)));
40    }
41   
 
42  5 toggle public boolean isSuperpose()
43    {
44  5 return superpose;
45    }
46   
 
47  5 toggle public void setSuperpose(boolean superpose)
48    {
49  5 this.superpose = superpose;
50    }
51   
 
52  20 toggle public String getViewerid()
53    {
54  20 return viewerid;
55    }
56   
 
57  5 toggle public void setViewerid(String viewerid)
58    {
59  5 this.viewerid = viewerid;
60    }
61   
 
62  5 toggle public ViewerType getViewerType()
63    {
64  5 return viewerType;
65    }
66   
 
67  5 toggle public void setViewerType(ViewerType viewerType)
68    {
69  5 this.viewerType = viewerType;
70    }
71   
 
72  0 toggle public List<StructureLine> getStructureLines()
73    {
74  0 return structureLines;
75    }
76   
 
77  5 toggle public void setStructureLines(List<StructureLine> structureLines)
78    {
79  5 this.structureLines = structureLines;
80    }
81   
 
82  5 toggle public List<StructureLine> parseStructuresFile(File structuresFile)
83    {
84  5 if (!structuresFile.exists())
85    {
86  0 String message = Arg.STRUCTURESFILE.argString() + ArgParser.EQUALS
87    + "\"" + structuresFile.getPath()
88    + "\": File does not exist.";
89  0 Console.warn(message);
90  0 return null;
91    }
92  5 List<String> lines = ArgParser.readArgFile(structuresFile);
93  5 List<StructureLine> structurelines = new ArrayList<>();
94  5 if (lines != null)
95    {
96  5 for (String line : lines)
97    {
98  28 if (line.startsWith(ArgParser.DOUBLEDASH))
99    {
100  13 String val = getArgVal(Arg.VIEWERID, line);
101  13 if (val != null)
102    {
103  3 setViewerid(val);
104  3 continue;
105    }
106  10 val = getArgVal(Arg.STRUCTUREVIEWER, line);
107  10 if (val != null)
108    {
109  5 setViewerType(ViewerType.getFromString(val));
110  5 continue;
111    }
112  5 Boolean b = getArgBoolean(Arg.SUPERPOSE, line);
113  5 if (b != null)
114    {
115  5 setSuperpose(b);
116  5 continue;
117    }
118    }
119  15 StructureLine sl = new StructureLine(line);
120  15 structurelines.add(sl);
121  15 String structureLocationRef = sl.getSource();
122  15 DataSourceType structureLocationType = AppletFormatAdapter
123    .checkProtocol(structureLocationRef);
124  15 if (DataSourceType.FILE.equals(structureLocationType))
125    {
126  15 structureLocationRef = new File(structureLocationRef)
127    .getAbsolutePath();
128    }
129  15 SequenceI seq = alignment.findName(sl.getSeqid());
130   
131    // TODO get global or subval values for TFT and notempfac
132   
133  15 PDBEntry pdbEntry = new AssociatePdbFileWithSeq()
134    .associatePdbWithSeq(structureLocationRef,
135    structureLocationType, seq, false, Desktop.instance,
136    null, null, false);
137   
138  15 pdbs.add(pdbEntry);
139  15 seqs.add(seq);
140   
141    }
142    }
143  5 return structurelines;
144    }
145   
 
146  10 toggle public SequenceI[] getSeqs()
147    {
148  10 SequenceI[] array = new SequenceI[seqs.size()];
149  10 return seqs.toArray(array);
150    }
151   
 
152  5 toggle public PDBEntry[] getPdbEntries()
153    {
154  5 PDBEntry[] array = new PDBEntry[pdbs.size()];
155  5 return pdbs.toArray(array);
156    }
157   
 
158  23 toggle private static String getArgVal(Arg a, String line)
159    {
160  23 String s = new StringBuilder(a.argString()).append(ArgParser.EQUALS)
161    .toString();
162  23 if (line.startsWith(s))
163    {
164  8 return line.substring(s.length());
165    }
166  15 return null;
167    }
168   
 
169  5 toggle private static Boolean getArgBoolean(Arg a, String line)
170    {
171  5 if (line.equals(a.argString()))
172    {
173  2 return true;
174    }
175  3 if (line.equals(a.negateArgString()))
176    {
177  3 return false;
178    }
179  0 return null;
180    }
181   
182    }