LOOS  v2.3.2
sortfids.cpp
1 /*
2  sortfids
3 
4  Structural histogram, a la Lyman &
5  Zuckerman, Biophys J (2006) 91:164-172
6 
7  Usage- sortfids model selection fids hist newfidname
8 
9  Sorts fiducials based on decreasing histogram bin population
10 
11 */
12 
13 
14 
15 /*
16 
17  This file is part of LOOS.
18 
19  LOOS (Lightweight Object-Oriented Structure library)
20  Copyright (c) 2010, Tod D. Romo
21  Department of Biochemistry and Biophysics
22  School of Medicine & Dentistry, University of Rochester
23 
24  This package (LOOS) is free software: you can redistribute it and/or modify
25  it under the terms of the GNU General Public License as published by
26  the Free Software Foundation under version 3 of the License.
27 
28  This package is distributed in the hope that it will be useful,
29  but WITHOUT ANY WARRANTY; without even the implied warranty of
30  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31  GNU General Public License for more details.
32 
33  You should have received a copy of the GNU General Public License
34  along with this program. If not, see <http://www.gnu.org/licenses/>.
35 */
36 
37 
38 
39 #include <loos.hpp>
40 
41 using namespace std;
42 using namespace loos;
43 
44 
45 typedef vector<AtomicGroup> vGroup;
47 
48 // @cond TOOLS_INTERNAL
49 
50 
51 
52 string fullHelpMessage(void) {
53  string msg =
54  "\n"
55  "SYNOPSIS\n"
56  "\tSorts fiducial structures based on histogram bin population\n"
57  "\n"
58  "DESCRIPTION\n"
59  "\n"
60  "\tGiven a set of fiducials for a structural histogram, sort them based\n"
61  "on bin population. This can be useful when using fidpick, which selects\n"
62  "fiducials based on distance rather than bin probability.\n"
63  "\n"
64  "SEE ALSO\n"
65  "\tfidpick\n";
66 
67  return(msg);
68 }
69 
70 
71 // Sorts based on 3rd col of a matrix
72 
73 struct Adapter {
74  Adapter(const Matrix& M) : A(M) { }
75 
76  uint size() const { return(A.rows()); }
77  const double& operator[](const uint i) const {
78  return(A(i,2));
79  }
80 
81  const Matrix& A;
82 
83 };
84 
85 // @endcond
86 
87 int main(int argc, char *argv[]) {
88  string hdr = invocationHeader(argc, argv);
89 
90  if (argc != 6) {
91  cerr << "Usage- sortfids model sel fids hist newfids\n";
92  cerr << fullHelpMessage();
93  exit(-1);
94  }
95 
96  int opti = 1;
97 
98  AtomicGroup model = createSystem(argv[opti++]);
99  string selection(argv[opti++]);
100  AtomicGroup subset = selectAtoms(model, selection);
101  subset.renumber();
102 
103  pTraj fids = createTrajectory(argv[opti++], subset);
104  vGroup fiducials;
105  readTrajectory(fiducials, subset, fids);
106 
107  Matrix M;
108  readAsciiMatrix(argv[opti++], M);
109  vector<uint> indices = sortedIndex<Adapter, DescendingSort<Adapter> >(Adapter(M));
110 
111  vGroup sorted;
112 
113  Matrix A(M.rows(), M.cols());
114  for (uint i=0; i<M.rows(); ++i) {
115  sorted.push_back(fiducials[indices[i]]);
116  A(i,0) = i;
117  A(i,1) = M(indices[i], 1);
118  A(i,2) = M(indices[i], 2);
119  }
120 
121  DCDWriter(argv[opti++], sorted, hdr);
122  writeAsciiMatrix(cout, A, hdr);
123 }
Simple matrix template class using policy classes to determine behavior.
Definition: MatrixImpl.hpp:53
STL namespace.
void renumber(const int start=1, const int stride=1)
Renumber the atomid's of the contained atoms...
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
std::ostream & writeAsciiMatrix(std::ostream &os, const Math::Matrix< T, P, S > &M, const std::string &meta, const Math::Range &start, const Math::Range &end, const bool trans=false, F fmt=F())
Write a submatrix to a stream.
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
A very lightweight class for writing simple DCDs.
Definition: dcdwriter.hpp:48
Math::Matrix< T, P, S > readAsciiMatrix(std::istream &is)
Read in a matrix from a stream returning a newly created matrix.
Definition: MatrixRead.hpp:72
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.