Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.structure

File AtomSpecModel.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

12
24
6
1
128
63
12
0.5
4
6
2

Classes

Class Line # Actions
AtomSpecModel 33 24 12
0.928571492.9%
 

Contributing tests

This file is covered by 45 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.structure;
22   
23    import java.util.ArrayList;
24    import java.util.BitSet;
25    import java.util.List;
26    import java.util.Map;
27    import java.util.TreeMap;
28   
29    /**
30    * A class to model a set of models, chains and atom range positions
31    *
32    */
 
33    public class AtomSpecModel
34    {
35    /*
36    * { modelId, {chainCode, List<from-to> ranges} }
37    */
38    private Map<String, Map<String, BitSet>> atomSpec;
39   
40    /**
41    * Constructor
42    */
 
43  1691 toggle public AtomSpecModel()
44    {
45  1691 atomSpec = new TreeMap<>();
46    }
47   
48    /**
49    * Adds one contiguous range to this atom spec
50    *
51    * @param model
52    * @param startPos
53    * @param endPos
54    * @param chain
55    */
 
56  8444 toggle public void addRange(String model, int startPos, int endPos, String chain)
57    {
58    /*
59    * Get/initialize map of data for the colour and model
60    */
61  8444 Map<String, BitSet> modelData = atomSpec.get(model);
62  8444 if (modelData == null)
63    {
64  1720 atomSpec.put(model, modelData = new TreeMap<>());
65    }
66   
67    /*
68    * Get/initialize map of data for colour, model and chain
69    */
70  8443 BitSet chainData = modelData.get(chain);
71  8444 if (chainData == null)
72    {
73  1753 chainData = new BitSet();
74  1753 modelData.put(chain, chainData);
75    }
76   
77    /*
78    * Add the start/end positions
79    */
80  8444 chainData.set(startPos, endPos + 1);
81    }
82   
 
83  1785 toggle public Iterable<String> getModels()
84    {
85  1785 return atomSpec.keySet();
86    }
87   
 
88  0 toggle public int getModelCount()
89    {
90  0 return atomSpec.size();
91    }
92   
 
93  1840 toggle public Iterable<String> getChains(String model)
94    {
95  1841 return atomSpec.containsKey(model) ? atomSpec.get(model).keySet()
96    : null;
97    }
98   
99    /**
100    * Returns a (possibly empty) ordered list of contiguous atom ranges for the
101    * given model and chain.
102    *
103    * @param model
104    * @param chain
105    * @return
106    */
 
107  1967 toggle public List<int[]> getRanges(String model, String chain)
108    {
109  1966 List<int[]> ranges = new ArrayList<>();
110  1967 if (atomSpec.containsKey(model))
111    {
112  1965 BitSet bs = atomSpec.get(model).get(chain);
113  1965 int start = 0;
114  1965 if (bs != null)
115    {
116  1964 start = bs.nextSetBit(start);
117  1964 int end = 0;
118  10051 while (start != -1)
119    {
120  8087 end = bs.nextClearBit(start);
121  8086 ranges.add(new int[] { start, end - 1 });
122  8087 start = bs.nextSetBit(end);
123    }
124    }
125    }
126  1967 return ranges;
127    }
128    }