Commits

jfinkels committed 0502f25 Merge

merged changes

  • Participants
  • Parent commits 65a48d5, 35e2583

Comments (0)

Files changed (18)

 # executable files resulting from build
 matt
 
+# temporary test files
+MattAlignment.*
+
 # hidden files
 .*
 
 *~
 
 # core dumps
-core.*
+core.*
 	return problems;
 }
 
-int CountAlphaCarbons(PDBChain *c) {
+unsigned int CountAlphaCarbons(PDBChain *c) {
 	unsigned int i;
 	unsigned int count = 0;
 	for (i=0; i<c->length; i++) {

MultipleAlignment.c

 
 double CalcStructalScore(MultipleAlignment *ma) {
 	double score = 0;
-	int i, j, k;
+	unsigned int i, j, k;
 	for (i = 0; i<ma->numResidues; i++) {
 		double weights = 0;
 		double sum = 0;
-		int gapCount = 0;
+		unsigned int gapCount = 0;
 		if (i) {
 			j = ma->numChains;
 			while (j) {
 
 ResiduePositions *Distill(PDBChain *c, int id) {
 	ResiduePositions *out = (ResiduePositions*) malloc(sizeof(ResiduePositions));
-	int i;
+	unsigned int i;
 	out->res = (ResiduePosition*) malloc(sizeof(ResiduePosition)*c->length);
 	out->id = id;
 	out->pdb = c;
 	return out;
 }
 
-void CalcWeights(MultipleAlignment *ma, int exclude) {
+void CalcWeights(MultipleAlignment *ma, unsigned int exclude) {
 	int max = ma->numChains;
-	int i;
-	if (exclude<0) exclude = ma->numChains;
-	else if (exclude < ma->numChains) max--;
+	unsigned int i;
+	/*if (exclude<0) exclude = ma->numChains;*/
+	/*else*/ if (exclude < ma->numChains) max--;
 	for (i=0; i<ma->numChains; i++) {
 		if (i == exclude) ma->residues[i].weight = 0;
 		else ma->residues[i].weight = 1.0/max;
 	}
 }
 
-void RealignChain(MultipleAlignment *ma, int c, Matrix *matrices) {
-	int i, j, k;
+void RealignChain(MultipleAlignment *ma, unsigned int c, Matrix *matrices) {
+	unsigned int i, j;
+  int k;
 	WeightedResiduePositions tempResidues;
 
 	CalcWeights(ma, c);
 }
 
 Matrix ** Realign(MultipleAlignment *ma) {
-	int block, k, chain;
+	unsigned int block;
+  int k;
+  unsigned int chain;
 	Matrix ** matrices = (Matrix **) malloc(sizeof(Matrix*) * ma->numChains);
 	matrices[0] = (Matrix *) malloc(ma->numChains*ma->numBlocks * sizeof(Matrix));
 	if (ma->numChains == 1) {
 
 	/* Recalculate alignments.of all blocks. */
 	for (k=0; k<2; k++) {
-		for (chain=ma->numChains-1; chain>=0; chain--) {
-			RealignChain(ma, chain, matrices[chain]);
+		for (chain=ma->numChains; chain>0; chain--) {
+			RealignChain(ma, chain - 1, matrices[chain - 1]);
 		}
 	}
 
 	/* Calculate new (And final) weights. */
-	CalcWeights(ma, -1);
+	CalcWeights(ma, ma->numChains);
 	return matrices;
 }
 
 void RealignExtendAndWeight(MultipleAlignment *ma) {
 	/* Rotate alignment to coordinates of first chain. */
-	int i, j, k;
+	unsigned int i, j, k;
 	Matrix ** matrices = Realign(ma);
 	Extend(ma, matrices, 1);
 
 	/* Realign and rotate alignment to coordinates of first chain. */
 	Matrix **matrices = Realign(ma);
 
-	int i;
+	unsigned int i;
 	/* Rotate residues of each chain. */
 	for (i=0; i<ma->numChains; i++) {
-		int block = 0;
+		unsigned int block = 0;
 		int pos = 0;
 		Atom *atoms = ma->chains[i]->pdb->atoms;
 		int numAtoms = ma->chains[i]->pdb->numAtoms;
 		while (pos < numAtoms) {
-			int newGroup = block+1;
+			unsigned int newGroup = block+1;
 			Vector v;
 			if (newGroup<ma->numBlocks) {
 				int temp = ma->blocks[newGroup].first;
 	WeightedResiduePositions tempResidues;
 	ResiduePositions *tempChain;
 	MultipleAlignment *ma = (MultipleAlignment*) memdup(srcMA, sizeof(MultipleAlignment));
-	int i;
+	unsigned int i;
 
 	ma->order = DuplicateAssemblyOrder(srcMA->order);
 	ma->chains = (ResiduePositions **)memdup(srcMA->chains, srcMA->numChains * sizeof(ResiduePositions *));
 
 MultipleAlignment *CreateSingleStrandAlignment(ResiduePositions *chain) {
 	MultipleAlignment *ma = (MultipleAlignment*) calloc(1, sizeof(MultipleAlignment));
-	int i;
+	unsigned int i;
 	ma->order = MakeAssemblyOrder(chain->id);
 	ma->numChains = 1;
 	ma->chains = (ResiduePositions **)memdup(&chain, sizeof(ResiduePositions *));
 	double displacementRange = s.displacement * 2;
 	int best = 0;
 	int i;
-	int pos;
+	unsigned int pos;
 	OctTreeNode *trees = (OctTreeNode *) calloc(a2->numResidues, sizeof(OctTreeNode));
 	double maxBonus = MAX_BONUS;
 	double maxPosBonus = MAX_POS_BONUS;
 	int maxMatches = 10240;
 	int numMatches = 0;
 
-	int i, block1, p1, block2, p2, len;
+  unsigned int block1;
+  unsigned int p1;
+	int i, block2, p2, len;
 	/* time[2] -= timeGetTime(); */
 
 	for (i=1; i<=MAX_FRAGMENT_LEN; i++) {
 	return ma;
 }
 
-double AlignOrder (MultipleAlignment *ma, AssemblyNode *n, int *count, WeightedResiduePositions *r, int *indices, Matrix *matrices) {
-	int i, j, k, chain;
+double AlignOrder (MultipleAlignment *ma, AssemblyNode *n, unsigned int *count, WeightedResiduePositions *r, int *indices, Matrix *matrices) {
+	unsigned int i, j, k, chain;
 	/* If only one chain, just find the index in ma->residues and copy the data over. */
 	if (n->left == 0) {
-		int index;
+		unsigned int index;
 		for (index = 0; index < ma->numChains-1; index++) {
 			if (ma->chains[index]->id == n->id) break;
 		}
 		WeightedResiduePositions tempResidues;
 		WeightedResiduePositions *r2;
 		double test;
-		int count1, count2;
+		unsigned int count1, count2;
 
 		/* Get aligned sets of residues from both children. */
 		AlignOrder(ma, n->left, &count1, r, indices, matrices);
 
 		count1 = *count;
 		for (j=0; j<2; j++) {
-			for (chain = count1-1; chain>=0; chain--) {
+			for (chain = count1; chain>0; chain--) {
+        unsigned int chaintemp = chain - 1;
 				for (i=0; i<count1; i++)
 					r[i].weight = 1 / (double) (count1-1);
-				r[chain].weight = 0;
+				r[chaintemp].weight = 0;
 
-				tempResidues.res = r[chain].res;
+				tempResidues.res = r[chaintemp].res;
 				for (k=0; k<ma->numResidues; k++) {
-					tempResidues.res[k].coords = ma->chains[indices[chain]]->res[tempResidues.res[k].index].coords;
+					tempResidues.res[k].coords = ma->chains[indices[chaintemp]]->res[tempResidues.res[k].index].coords;
 				}
 				AlignAlignmentBlocks(0, 0, count1, 1, r, &tempResidues, ma->numResidues, &m);
-				matrices[indices[chain]] = m;
+				matrices[indices[chaintemp]] = m;
 				for (k=0; k<ma->numResidues; k++) {
-					transformVect(&tempResidues.res[k].coords, &m, &ma->chains[indices[chain]]->res[tempResidues.res[k].index].coords);
+					transformVect(&tempResidues.res[k].coords, &m, &ma->chains[indices[chaintemp]]->res[tempResidues.res[k].index].coords);
 				}
 			}
 		}
 	WeightedResiduePositions *residuesTemp = (WeightedResiduePositions *)malloc(ma->numChains * sizeof(WeightedResiduePositions));
 	int* indices = (int*) malloc(sizeof(int) * ma->numChains);
 	Matrix *matrices = (Matrix*) malloc(sizeof(Matrix) * ma->numChains);
-	int i, j;
+	unsigned int i, j;
 	for (i=0; i<ma->numChains; i++) {
 		for (j=0; j<ma->numResidues; j++) {
 			ma->residues[i].res[j] = ma->chains[i]->res[ma->residues[i].res[j].index];
 
 double CalcNonWeightedRMSD(MultipleAlignment *ma) {
 	double total = 0;
-	int i, j, k;
+	unsigned int i, j, k;
 	if (ma->numChains <= 1) return ma->rmsd = 0;
 
 	for (i=0; i<ma->numResidues; i++) {
 
 
 void CleanupAlignment(MultipleAlignment *ma) {
-	int i;
+	unsigned int i;
 
 	free(ma->chains);
 	free(ma->order);
 
 
 
-MultipleAlignment* Align(PDBChain **chains, int numChains, int displayStatus, int singleThreaded) {
-	int i, j;
+MultipleAlignment* Align(PDBChain **chains, unsigned int numChains, int displayStatus, int singleThreaded) {
+	unsigned int i, j;
 
-	int numAlignments = numChains;
+	unsigned int numAlignments = numChains;
 	MultipleAlignment** alignments = (MultipleAlignment**) malloc(numAlignments * sizeof(MultipleAlignment*));
-	int numAlignedAlignments = numChains * (numChains-1)/2;
+	unsigned int numAlignedAlignments = numChains * (numChains-1)/2;
 	MultipleAlignment** alignedAlignments = (MultipleAlignment**) malloc(numAlignedAlignments * sizeof(MultipleAlignment*));
 	double *pairScores;
 	int numTotalAlignments = (numChains-1) * (numChains-1);
 		 */
 		index1 = ma->chains[0]->id;
 		index2 = ma->chains[ma->numChains-1]->id;
-		for (i=numAlignedAlignments-1; i >= 0; i--) {
-			for (j=0; j<alignedAlignments[i]->numChains; j++) {
-				if (alignedAlignments[i]->chains[j]->id == index1 ||
-					alignedAlignments[i]->chains[j]->id == index2) {
+		for (i=numAlignedAlignments; i > 0; i--) {
+      unsigned int ii = i - 1;
+			for (j=0; j<alignedAlignments[ii]->numChains; j++) {
+				if (alignedAlignments[ii]->chains[j]->id == index1 ||
+					alignedAlignments[ii]->chains[j]->id == index2) {
 
-					CleanupAlignment(alignedAlignments[i]);
-					alignedAlignments[i] = alignedAlignments[--numAlignedAlignments];
+					CleanupAlignment(alignedAlignments[ii]);
+					alignedAlignments[ii] = alignedAlignments[--numAlignedAlignments];
 					break;
 				}
 			}
 		}
 
-		for (i=numAlignments-1; i >= 0; i--) {
-			for (j=0; j<alignments[i]->numChains; j++) {
-				if (alignments[i]->chains[j]->id == index1 ||
-					alignments[i]->chains[j]->id == index2) {
+		for (i=numAlignments; i > 0; i--) {
+      unsigned int ii = i - 1;
+			for (j=0; j<alignments[ii]->numChains; j++) {
+				if (alignments[ii]->chains[j]->id == index1 ||
+					alignments[ii]->chains[j]->id == index2) {
 
-					CleanupAlignment(alignments[i]);
-					alignments[i] = alignments[--numAlignments];
+					CleanupAlignment(alignments[ii]);
+					alignments[ii] = alignments[--numAlignments];
 					break;
 				}
 			}
 #ifdef _OPENMP
 		if (singleThreaded) {
 			/* Run all the new alignments and add ma to the list of alignments I've kept. */
-			for (i=numAlignments-1; i >= 0; i--) {
+			for (i=numAlignments; i > 0; i--) {
+        unsigned int ii = i - 1;
 				double bestScore = 0;
 				int best1=0, best2=0;
 
 				/* Need private (thread) variables. */
-				int j, k;
-				for (j=0; j<alignments[i]->numChains; j++) {
+				unsigned int j, k;
+				for (j=0; j<alignments[ii]->numChains; j++) {
 					for (k=0; k<ma->numChains; k++) {
-						double score = pairScores[ma->chains[k]->id * numChains + alignments[i]->chains[j]->id];
+						double score = pairScores[ma->chains[k]->id * numChains + alignments[ii]->chains[j]->id];
 						if (score > bestScore) {
 							bestScore = score;
 							best1 = j;
 					}
 				}
 
-				alignedAlignments[numAlignedAlignments+i] = AlignAlignments(alignments[i], ma, best1, best2, 0);
+				alignedAlignments[numAlignedAlignments+ii] = AlignAlignments(alignments[ii], ma, best1, best2, 0);
 				if (displayStatus) {
 					DisplayProgress(&backspace, progressTemplate, ++count);
 				}
 			#pragma omp parallel for default(shared) schedule(dynamic, 1)
 #endif
 			/* Run all the new alignments and add ma to the list of alignments I've kept. */
-			for (i=numAlignments-1; i >= 0; i--) {
+			for (i=numAlignments; i > 0; i--) {
+        unsigned int ii = i - 1;
 				double bestScore = 0;
 				int best1=0, best2=0;
 
 				/* Need private (thread) variables. */
-				int j, k;
-				for (j=0; j<alignments[i]->numChains; j++) {
+				unsigned int j, k;
+				for (j=0; j<alignments[ii]->numChains; j++) {
 					for (k=0; k<ma->numChains; k++) {
-						double score = pairScores[ma->chains[k]->id * numChains + alignments[i]->chains[j]->id];
+						double score = pairScores[ma->chains[k]->id * numChains + alignments[ii]->chains[j]->id];
 						if (score > bestScore) {
 							bestScore = score;
 							best1 = j;
 					}
 				}
 
-				alignedAlignments[numAlignedAlignments+i] = AlignAlignments(alignments[i], ma, best1, best2, 0);
+				alignedAlignments[numAlignedAlignments+ii] = AlignAlignments(alignments[ii], ma, best1, best2, 0);
 				if (displayStatus) {
 #ifdef _OPENMP
 #pragma omp critical

MultipleAlignment.h

 struct RESIDUE_POSITIONS {
 	ResiduePosition *res;
 	PDBChain *pdb;
-	int length;
+	unsigned int length;
 	int id;
 };
 typedef struct RESIDUE_POSITIONS ResiduePositions;
 void UnbentRMSDAlign(MultipleAlignment *ma);
 
 /* Main function */
-MultipleAlignment* Align(PDBChain **chains, int numChains, int displayStatus, int singleThreaded);
+MultipleAlignment* Align(PDBChain **chains, unsigned int numChains, int displayStatus, int singleThreaded);
 
 
 
 	float bestAssembledScore;
 
 	/* Block start positions */
-	int p1, p2;
+	unsigned int p1, p2;
 
-	int len;
+	unsigned int len;
 	int bestPreviousMatch;
 };
 typedef struct MATCHED_BLOCK_PAIR MatchedBlockPair;

MultipleAlignmentOutput.c

 #include <time.h>
 
 void ReorderAlignment(MultipleAlignment *ma, int *order) {
-	int i, j;
+	unsigned int i, j;
 	for (i=0; i<ma->numChains; i++) {
 		for (j=i; 1; j++) {
 			if (order[i] == ma->chains[j]->id) {
  */
 SequenceAlignment *GetSequenceAlignment(MultipleAlignment *ma) {
 	SequenceAlignment *out = (SequenceAlignment *) malloc(sizeof(SequenceAlignment));
-	int chain, block, chain2;
-	int *indices = (int*) calloc(ma->numChains, sizeof(int));
+	unsigned int chain, block, chain2;
+	unsigned int *indices = (unsigned int*) calloc(ma->numChains, sizeof(unsigned int));
 	out->numSeqs = ma->numChains;
 	out->seqs = (Sequence**) malloc(sizeof(Sequence*) * ma->numChains);
 
 		int last = ma->blocks[block].last;
 		for (chain=0; chain<ma->numChains; chain++) {
 			int find = first;
-			int index;
+			unsigned int index;
 			while (find <= last && !ma->residues[chain].res[find].existence.exists) find++;
 			if (find > last) break;
 			index = ma->residues[chain].res[find].index;
 
 int OutputAlignmentBentPDB(MultipleAlignment *ma, const char *fileName, int *order) {
 	Atom **atoms = (Atom**) malloc(sizeof(Atom*)*ma->numChains);
-	int i;
+	unsigned int i;
 	int result = 0;
 	for (i=0; i<ma->numChains; i++) {
 		atoms[i] = (Atom*) memdup(ma->chains[i]->pdb->atoms, sizeof(Atom) * ma->chains[i]->pdb->numAtoms);
 }
 
 int OutputAlignmentPDB(MultipleAlignment *ma, const char *filename, int *order) {
-	int i, j;
+	unsigned int i, j;
 	PDBChain **tempChains;
 	FILE *out;
 	if (!order) return 0;
 int OutputAlignmentRasmol(MultipleAlignment *ma, const char *filename) {
 	static const char *colors[] = {"red", "blue", "green", "purple", "cyan", "orange", "yellow", "greenblue", "magenta", "[255,171,187]"};
 	FILE *out = fopen(filename, "wb");
-	int i, j, k;
+	unsigned int i, j, k;
 
 	if (!out) return 0;
 
 int OutputAlignmentSpdbv(MultipleAlignment *ma, const char *filename) {
 	static const char *colors[] = {"red", "blue", "green", "purple", "cyan", "orange", "yellow", "<0.18,0.54,0.34>", "<1.0,0.0,1.0>", "<1.0,0.67,0.73>"};
 	FILE *out = fopen(filename, "wb");
-	int i, j, k;
+	unsigned int i, j, k;
 
 	if (!out) return 0;
 
 int OutputAlignmentMsf(MultipleAlignment *ma, char *filename) {
 	FILE *out = fopen(filename, "wb");
 	SequenceAlignment *sa;
-	int i, j, k;
+	unsigned int i, j, k;
 	if (out) {
 		char t[100];
 		time_t now = time(0);
 			memset(names[i], ' ', 13 * sizeof(char));
 			memcpy(names[i], id, len);
 		}
-		for (i=ma->numChains-1; i>=0; i--) {
-			char *id = ma->chains[i]->pdb->idString;
+		for (i=ma->numChains; i>0; i--) {
+      unsigned int ii = i - 1;
+			char *id = ma->chains[ii]->pdb->idString;
 			int chainCount = 0;
-			for (j=i-1; j>=0; j--) {
-				if (!strcmp(names[i], names[j])) {
-					names[j][14] = 1;
-					names[i][14] = 1;
-					if (ma->chains[i]->pdb->chainName == ma->chains[j]->pdb->chainName) {
+			for (j=ii; j>0; j--) {
+        unsigned int jj = j - 1;
+				if (!strcmp(names[ii], names[jj])) {
+					names[jj][14] = 1;
+					names[ii][14] = 1;
+					if (ma->chains[ii]->pdb->chainName == ma->chains[jj]->pdb->chainName) {
 						chainCount++;
-						names[j][15] = 1;
-						names[i][15] = 1;
+						names[jj][15] = 1;
+						names[ii][15] = 1;
 					}
 				}
 			}
-			if (names[i][15] || names[i][14]) {
+			if (names[ii][15] || names[ii][14]) {
 				int len = 13;
 				char *end = strchr(id, ':');
-				char chain = ma->chains[i]->pdb->chainName;
+				char chain = ma->chains[ii]->pdb->chainName;
 				if (!chain || chain == 0) chain = '_';
 				if (!end) end = strchr(id, ' ');
 				if (end) len = (int)(end-id);
-				if (names[i][15]) {
+				if (names[ii][15]) {
 					if (len > 8) len = 8;
 					if (chainCount > 100) len --;
 					if (chainCount > 1000) len --;
 					if (chainCount > 10000) len --;
 					chainCount %= 100000;
-					sprintf(names[i] + len, ":%c%i", ma->chains[i]->pdb->chainName, chainCount);
+					sprintf(names[ii] + len, ":%c%i", ma->chains[ii]->pdb->chainName, chainCount);
 				}
 				else {
 					if (len > 10) len = 10;
-					sprintf(names[i] + len, ":%c", ma->chains[i]->pdb->chainName);
+					sprintf(names[ii] + len, ":%c", ma->chains[ii]->pdb->chainName);
 				}
 			}
 		}
 }
 
 void OutputAlignmentOrder(MultipleAlignment *ma, FILE *file, const AssemblyNode *node) {
-	int i;
+	unsigned int i;
 	if (node->id >= 0) {
 		for (i=0; i<ma->numChains; i++) {
 			if (ma->chains[i]->id == node->id) {
 
 int OutputAlignmentText(MultipleAlignment *ma, const char *filename, int ref) {
 	FILE *out = fopen(filename, "wb");
-	int i;
+	unsigned int i;
 	int nameLen = 0;
 	int coreCount = 0;
 	char format[30];
 	}
 
 	for (i=0; i<ma->numResidues;i++) {
-		int chain;
+		unsigned int chain;
 		for (chain=0; chain<ma->numChains; chain++) {
 			if (!ma->residues[chain].res[i].existence.exists) break;
 		}
 
 	sa = GetSequenceAlignment(ma);
 	for (i = 0; i<sa->seqs[0]->length; i+=60) {
-		int end = i + 60;
-		int j;
+		unsigned int end = i + 60;
+		unsigned int j;
 
 		if (end > sa->seqs[0]->length) end = sa->seqs[0]->length;
 		for (j=0; j<ma->numChains; j++) {
 			char *seq = sa->seqs[j]->seq;
 			int p = 0;
-			int k;
+			unsigned int k;
 			fprintf(out, format, ma->chains[j]->pdb->idString);
 			for (k = 0; k < i; k++) p += (seq[k] != '-');
 
 int OutputAlignmentSsi(MultipleAlignment *ma, const char *filename) {
 	FILE *out = fopen(filename, "wb");
 	SequenceAlignment *sa;
-	int i;
-	int nameLen = 0;
+	unsigned int i;
+	unsigned int nameLen = 0;
 	if (!out) return 0;
 	sa = GetSequenceAlignment(ma);
 	for (i=0; i<ma->numChains; i++) {
-		int len = (int)strlen(ma->chains[i]->pdb->idString);
+		unsigned int len = strlen(ma->chains[i]->pdb->idString);
 		if (len > nameLen) nameLen = len;
 	}
 
 	fprintf(out, "# STOCKHOLM 1.0\n\n");
 	for (i=0; i<sa->numSeqs; i++) {
 		char *s = ma->chains[i]->pdb->idString;
-		int j;
+		unsigned int j;
 		for (j=0; j<nameLen; j++) {
 			if (!*s) {
 				fputc(' ', out);
 }
 
 int GetAtomIndex(PDBChain *chain, int pos, char*desc) {
-	int i;
+	unsigned int i;
 	if (pos >= chain->length || pos < 0 || chain->residues[pos].firstAtom==-1) return -1;
 	for (i=chain->residues[pos].firstAtom; i <= chain->residues[pos].lastAtom; i++) {
 		if (strcmp(desc, chain->atoms[i].name) == 0)
 
 		/* Match up atom records with residues. */
 		for (i=0; i<chain->numAtoms; i++) {
-			while (!(chain->residues[pos].resNum == chain->atoms[i].res && chain->residues[pos].resLetter == chain->atoms[i].resLetter)) {
+			while (!(chain->residues[pos].resNum == chain->atoms[i].res 
+		&& chain->residues[pos].resLetter == chain->atoms[i].resLetter)) {
 				pos++;
 			}
 
 
 	/* resNum and resLetter are the PDB number and letter used to identify the
 	   residue.  No letter is kept as a space */
-	int resNum;
+	unsigned int resNum;
 	char resLetter;
 };
 
 	int atomIndex;
 
 	/* Number of the residue or het block this is a part of. */
-	int res;
+	unsigned int res;
 
 	/* Real 0-based residue index. */
 	int resIndex;
 struct TEMP_RESIDUE {
 	int finalIndex;
 
-	int res;
+	unsigned int res;
 	char resLetter;
 
 	/* if this is in a het block or atom entry. */
 /* Checks if res1 and res2 are aligned in a beta sheet.  Returns 0 if they aren't,
  * 1 if they are and are parallel, -1 for antiparallel.
  */
-int AreAlignedPairs(PDBChain *chain, int res1, int res2);
+int AreAlignedPairs(PDBChain *chain, unsigned int res1, unsigned int res2);
 void CalcChainSecondary(PDBChain *chain);
 
 PDBChain *CreateChain(char *name, char chain);
  * to give the first occurence.  Takes O(log n) if numbering is sequential
  * and finds something.  Otherwise, takes O(n).
  */
-int GetResidueIndex(PDBChain *chain, int *position, int pdbPosition, char insertionCode);
+int GetResidueIndex(PDBChain *chain, int *position, unsigned int pdbPosition, char insertionCode);
 
 /* Guaranteed to give the first occurance with the given codes. */
-int GetResidueFirstIndex(PDBChain *chain, int *position, int pdbPosition, char insertionCode);
+int GetResidueFirstIndex(PDBChain *chain, int *position, unsigned int pdbPosition, char insertionCode);
 /* Does the same thing, but works with a portion of a string from a raw PDB line. */
 int GetResidueFirstIndexString(PDBChain *chain, int *position, char * rawString);
 void AddAlphaHelix(PDBChain *chain, AlphaHelix *helix);
 
 			strncpy(atom->name, &line[12],4);
 
-			if (!ReadInt(&line[22], 4, &atom->res)) continue;
+			if (!ReadUnsignedInt(&line[22], 4, &atom->res)) continue;
 
 			ReadInt(&line[6], 5, &atom->atomIndex);
 			atom->altLoc = line[16];
 
 #include "secondary.h"
 
-int FindFirstMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair) {
+int FindFirstMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair) {
 	if (betaPair->start1 <= pos && pos < betaPair->start1+betaPair->length) {
 		residuePair->res1 = pos;
 		residuePair->res2 = betaPair->start2+(pos-betaPair->start1)*betaPair->direction;
 	return 0;
 }
 
-int FindSecondMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair) {
+int FindSecondMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair) {
 	if (betaPair->direction == 1) {
 		if (betaPair->start2 <= pos && pos < betaPair->start2+betaPair->length) {
 			residuePair->res1 = pos;
 	}
 }
 
-int FindMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair) {
+int FindMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair) {
 	if (FindFirstMatch(betaPair, pos, residuePair)) return 1;
 	return FindSecondMatch(betaPair, pos, residuePair);
 }
  * as sheets can split, etc.
  */
 struct BETA_PAIR {
-	int start1, start2;
+	unsigned int start1, start2;
 	int direction;
 	unsigned int length;
 };
 typedef struct BETA_PAIR BetaPair;
 
-int FindFirstMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair);
-int FindSecondMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair);
-int FindMatch(BetaPair *betaPair, int pos, BetaResiduePair *residuePair);
+int FindFirstMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair);
+int FindSecondMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair);
+int FindMatch(BetaPair *betaPair, unsigned int pos, BetaResiduePair *residuePair);
 void FlipPair(BetaPair *betaPair);
 
 /* Used in beta sheets corresponding to sheets in PDB file */
+pdbs/pdb1v5l.ent.gz:A
+pdbs/pdb1uit.ent.gz:A
+pdbs/pdb1ihj.ent.gz:B
+pdbs/pdb1wif.ent.gz:A

test/pdbs/pdb1ihj.ent.gz

Binary file added.

test/pdbs/pdb1uit.ent.gz

Binary file added.

test/pdbs/pdb1v5l.ent.gz

Binary file added.

test/pdbs/pdb1wif.ent.gz

Binary file added.

test/test-matt.sh

+#!/bin/sh
+
+../matt -L ./pdblist
+
+exit 0
 	return success;
 }
 
+int ReadUnsignedInt(char *s, int len, unsigned int *out) {
+	int success;
+	char c = s[len];
+	s[len] = 0;
+	success = (1 == sscanf(s, "%u", out));
+	if (!success) *out = 0;
+	s[len] = c;
+	return success;
+}
+
 
 /* Curiously, seems to flicker less (At least on Windows) if done 3 characters at a time,
  * rather than with a single buffer. */
 int ReadDouble(char *s, int len, double *out);
 int ReadFloat(char *s, int len, float *out);
 int ReadInt(char *s, int len, int *out);
+int ReadUnsignedInt(char *s, int len, unsigned int *out);
 
 void *memdup (const void *mem, int size);