Commits

jfinkels  committed 1a3a20e

started splitting out structs into classes

  • Participants
  • Parent commits 61b7a92
  • Branches cplusplus

Comments (0)

Files changed (15)

File matt-cpp/src/AlignedBlock.hpp

+#ifndef ALIGNED_BLOCK_HPP_
+#define ALIGNED_BLOCK_HPP_
+
+class AlignedBlock {
+private:
+  unsigned int first;
+  unsigned int last;
+};
+
+#endif // ALIGNED_BLOCK_HPP_

File matt-cpp/src/AssemblyNode.cpp

+AssemblyNode::AssemblyNode(int id, AssemblyNode * left, AssemblyNode * right)
+  : id(id), left(right), right(right) {
+  // intentionally unimplemented
+}
+
+AssemblyNode * AssemblyNode::clone() {
+  AssemblyNode * clone = new AssemblyNode(this->id);
+  if (this->left != NULL) {
+    clone->left = this->left->clone();
+  }
+  if (this->right != NULL) {
+    clone->right = this->right->clone();
+  }
+
+  return clone;
+}
+
+int AssemblyNode::getId() {
+  return this->id;
+}
+
+void AssemblyNode::setLeft(AssemblyNode * newLeft) {
+  this->left = newLeft;
+}
+
+void AssemblyNode::setRight(AssemblyNode * newRight) {
+  this->right = newRight;
+}
+
+void AssemblyNode::setId(int newId) {
+  this->id = newId;
+}

File matt-cpp/src/AssemblyNode.hpp

+#ifndef ASSEMBLY_NODE_HPP_
+#define ASSEMBLY_NODE_HPP_
+
+class AssemblyNode {
+private:
+  int id;
+  AssemblyNode * left;
+  AssemblyNode * right;
+public:
+  AssemblyNode(int id, AssemblyNode * left = NULL, AssemblyNode * right = NULL);
+
+  AssemblyNode * clone();
+
+  int getId();
+
+  void setLeft(AssemblyNode * newLeft);
+  void setRight(AssemblyNode * newRight);
+  void setId(int newId);
+};
+
+#endif // ASSEMBLY_NODE_HPP_

File matt-cpp/src/AssemblyOrder.cpp

+#include "AssemblyOrder.hpp"
+
+AssemblyOrder::AssemblyOrder(int numNodes, AssemblyNode * root)
+  : numNodes(numNodes), root(root) {
+  // intentionally unimplemented
+}
+
+AssemblyOrder::AssemblyOrder(int id) 
+  : numNodes(1), root(new AssemblyNode(id)) {
+  // intentionally unimplemented
+}
+
+AssemblyOrder * AssemblyOrder::clone() {
+  AssemblyOrder * clone = new AssemblyOrder(this->root->getId());
+  clone->root = this->root->clone();
+  clone->numNodes = this->numNodes;
+  return clone;
+}
+
+AssemblyOrder * AssemblyOrder::cloneAndCombine(AssemblyOrder * left, AssemblyOrder * right) {
+  AssemblyNode * newRoot = new AssemblyNode(this->root->getId(), left->clone(),
+                                            right->clone());
+  return new AssemblyOrder(left->numNodes + right->numNodes + 1, newRoot);
+}
+

File matt-cpp/src/AssemblyOrder.hpp

+#ifndef ASSEMBLY_ORDER_HPP_
+#define ASSEMBLY_ORDER_HPP_
+
+class AssemblyOrder {
+private:
+  unsigned int numNodes;
+  AssemblyNode * root;
+
+  AssemblyOrder(AssemblyNode * root);
+
+public:
+  AssemblyOrder(int id);
+
+  AssemblyOrder * clone();
+  AssemblyOrder * cloneAndCombine(AssemblyOrder * left, AssemblyOrder * right);
+};
+
+#endif // ASSEMBLY_ORDER_HPP_

File matt-cpp/src/Heap.hpp

+#ifndef HEAP_HPP_
+#define HEAP_HPP_
+
+class Heap {
+private:
+  unsigned int size;
+  unsigned int used;
+  char * memory;
+public:
+  void freeAllMemory();
+};
+
+#endif // HEAP_HPP_

File matt-cpp/src/MatchedBlockPair.hpp

+#ifndef MATCHED_BLOCK_PAIR_HPP_
+#define MATCHED_BLOCK_PAIR_HPP_
+
+class MatchedBlockPair {
+private:
+  Vector last;
+  Matrix m;
+  Quaternion q;
+
+  float score;
+  float bestAssembledScore;
+  
+  unsigned int p1;
+  unsigned int p2;
+  
+  unsigned int len;
+  int bestPreviousMatch;
+};
+
+#endif // MATCHED_BLOCK_PAIR_HPP_

File matt-cpp/src/MemoryManagementInfo.cpp

+#include "MemoryManagementInfo.hpp"
+
+void * MemoryManagementInfo::getMemory(size) {
+  void * result;
+	if (this->numHeaps == 0 
+      or this->heaps[this->numHeaps - 1].size < 
+      this->heaps[this->numHeaps - 1].used + size) {
+
+		if (this->numHeaps % 16 == 0) {
+			this->heaps = (Heap *) realloc(this->heaps,
+                                     (16 + this->numHeaps) * sizeof(Heap));
+		}
+
+		this->heaps[this->numHeaps].memory = (char *) malloc(1024 * 512);
+		this->heaps[this->numHeaps].size = 1024 * 512;
+		this->heaps[this->numHeaps++].used = 0;
+	}
+
+	result = this->heaps[this->numHeaps - 1].memory 
+    + this->heaps[this->numHeaps - 1].used;
+	this->heaps[this->numHeaps - 1].used += size;
+
+	return result;
+}
+
+void freeAllMemory() {
+  for (unsigned int i = 0; i < this->numHeaps; ++i) {
+    this->heaps[i]->freeAllMemory();
+  }
+  free(this->heaps);
+  this->heaps = NULL;
+  this->numHeaps = 0;
+}

File matt-cpp/src/MemoryManagementInfo.hpp

+#ifndef MEMORY_MANAGEMENT_INFO_HPP_
+#define MEMORY_MANAGEMENT_INFO_HPP_
+
+class MemoryManagementInfo {
+private:
+  unsigned int numHeaps;
+  Heap * heaps;
+public:
+  void * getMemory(unsigned int size);
+  void freeAllMemory();
+};
+
+#endif // MEMORY_MANAGEMENT_INFO_HPP_

File matt-cpp/src/MultipleAlignment.hpp

+#ifndef MULTIPLE_ALIGNMENT_HPP_
+#define MULTIPLE_ALIGNMENT_HPP_
+
+class MultipleAlignment {
+private:
+  AssemblyOrder * order;
+  
+  ResiduePositions ** chains;
+  unsigned int numChains;
+
+  WeightedResiduePositions ** residues;
+  unsigned int numResidues;
+
+  AlignedBlock * blocks;
+  unsigned int numBlocks;
+
+  int ** conflictMap;
+
+  double score;
+  double rmsd;
+  double pvalue;
+};
+
+#endif // MULTIPLE_ALIGNMENT_HPP_

File matt-cpp/src/OctTreeNode.cpp

+#include "OctTreeNode.hpp"
+
+#include <cmath>
+
+#include "Vector.hpp"
+#include "MatchedBlockPair.hpp"
+#include "MemoryManagementInfo.hpp"
+
+const unsigned int OctTreeNode::MAX_VERTICES = 8;
+
+OctTreeNode::OctTreeNode(const Vector * minCorner, const Vector * maxCorner) 
+  : baseQuaternion(NULL), invCosHalfTest(0), radius(0), radius2(0), 
+    numVertices(0) {
+
+  this->corners[0] = *minCorner;
+  this->corners[1] = *maxCorner;
+
+  this->center.v[0] = MathUtils::mean(minCorner->v[0], maxCorner->v[0]);
+  this->center.v[1] = MathUtils::mean(minCorner->v[0], maxCorner->v[0]);
+  this->center.v[2] = MathUtils::mean(minCorner->v[0], maxCorner->v[0]);
+
+  for (unsigned int i = 0; i < 8; ++i) {
+    this->children[i] = NULL;
+    this->vertices[i] = NULL;
+  }
+}
+
+OctTreeNode::addEntry(MatchedBlockPair * coords, MemoryManagementInfo * info, 
+                      double radius) {
+  Vector diff = coords->last - this->center;
+  double r3 = diff.lengthSquared() + 0.000000001;
+  if (r3 > pow(this->radius, 2)) {
+		r3 = this->radius = sqrt(r3);
+		this->radius2 = pow(r3 + radius, 2);
+	}
+
+	if (node->numVertices == 0) {
+		//int add = (diff.v[0]>=0) + ((diff.v[1]>=0) << 1) + ((diff.v[2]>=0) << 2);
+    int add = 0;
+    for (unsigned int i = 0; i < 3; ++i) {
+      if (diff.v[i] >= 0) {
+        add += (1 << i);
+      }
+    }
+
+		if (node->children[add] == NULL) {
+			Vector c[2];
+			c[0] = this->center;
+			c[1] = this->center;
+
+			if (add & (1 << 0)) {
+				c[1].v[0] = this->corners[1].v[0];
+			} else {
+				c[0].v[0] = this->corners[0].v[0];
+			}
+
+			if (add & (1 << 1))  {
+				c[1].v[1] = this->corners[1].v[1];
+			} else {
+				c[0].v[1] = this->corners[0].v[1];
+			}
+
+			if (add & (1 << 2))  {
+				c[1].v[2] = this->corners[1].v[2];
+			} else {
+				c[0].v[2] = this->corners[0].v[2];
+			}
+
+			// this->children[add] = (OctTreeNode*) GetMemory(info, sizeof(OctTreeNode));
+			// InitOctTreeNode(node->children.children[add], c, c+1);
+			// node->children.children[add]->numVertices = 1;
+			// node->children.children[add]->children.vertices[0] = coords;
+      this->children[add] = new OctTreeNode(c, c + 1);
+      this->children[add]->numVertices = 1;
+      this->children[add]->vertices[0] = coords;
+			//subVect(&diff, &coords->last, &node->children.children[add]->center);
+      diff = coords->last - this->children[add]->center;
+			//r3 = node->children.children[add]->radius = lengthVect(&diff) + 0.0000001;
+      r3 = this->children[add]->radius = diff.length() + 0.0000001;
+			//node->children.children[add]->radius2 = (radius+r3)*(radius+r3);
+      this->children[add]->radius2 = pow(radius + r3, 2);
+		} else {
+			//AddEntry(node->children.children[add], coords, info, radius);
+      this->children[add]->addEntry(coords, info, radius);
+    }
+	} else if (this->numVertices == MAX_VERTICES) {
+		MatchedBlockPair * vertices[MAX_VERTICES];
+		// for (unsigned int i = MAX_OCT_TREE_VERTICES; i > 0; i--) {
+		// 	vertices[i - 1] = this->vertices[i - 1];
+		// 	this->vertices[i - 1] = NULL;
+		// }
+    memcpy(vertices, this->vertices, sizeof(MatchedBlockPair *) * MAX_VERTICES);
+    memset(this->vertices, NULL, sizeof(MatchedBlockPair *) * MAX_VERTICES);
+		this->numVertices = 0;
+		this->addEntry(coords, info, radius);
+
+		for (unsigned int i = MAX_VERTICES; i > 0; i--) {
+			this->addEntry(vertices[i], info, radius);
+		}
+	} else {
+		this->vertices[this->numVertices++] = coords;
+	}
+}
+

File matt-cpp/src/OctTreeNode.hpp

+#ifndef OCT_TREE_NODE_HPP_
+#define OCT_TREE_NODE_HPP_
+
+class OctTreeNode {
+private:
+  Vector center;
+  Vector corners[2];
+
+  OctTreeNode * children[MAX_VERTICES];
+  MatchedBlockPair * vertices[MAX_VERTICES];
+  unsigned int numVertices;
+
+  Quaternion * baseQuaternion;
+  double invCosHalfTest;
+  double radius;
+  double radius2;
+public:
+  static const unsigned int MAX_VERTICES;
+
+  OctTreeNode(const Vector * minCorner, const Vector * maxCorner);
+
+  addEntry(MatchedBlockPair * coords, MemoryManagementInfo * info, 
+           double radius);
+};
+
+#endif // OCT_TREE_NODE_HPP_

File matt-cpp/src/ResiduePosition.hpp

+#ifndef RESIDUE_POSITION_HPP_
+#define RESIDUE_POSITION_HPP_
+
+class ResiduePosition {
+private:
+  Vector coords;
+  int index;
+  char residue;
+  bool hasCoords;
+  bool exists;
+};
+
+#endif // RESIDUE_POSITION_HPP_

File matt-cpp/src/ResiduePositions.hpp

+#ifndef RESIDUE_POSITIONS_HPP_
+#define RESIDUE_POSITIONS_HPP_
+
+class ResiduePositions {
+private:
+  ResiduePosition * res;
+  unsigned int length;
+  PDBChain * pdb;
+  int id;
+};
+
+#endif // RESIDUE_POSITIONS_HPP_

File matt-cpp/src/WeightedResiduePositions.hpp

+#ifndef WEIGHTED_RESIDUE_POSITIONS_HPP_
+#define WEIGHTED_RESIDUE_POSITIONS_HPP_
+
+class WeightedResiduePositions {
+private:
+  ResiduePosition * res;
+  double weight;
+};
+
+#endif // WEIGHTED_RESIDUE_POSITIONS_HPP_