~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to compare_sequences.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                compare_sequences.c
 
6
 
 
7
Purpose:
 
8
        Compare sequence fragment from the current macromolecular complex
 
9
        with the sequence from the sequence buffer.  The leading residues
 
10
        from both sequences were compared before,  so it is not necessary
 
11
        to compare these residues again.
 
12
 
 
13
Input:
 
14
        (1) Pointer to MolComplexS structure, with data about the current
 
15
            macromolecular complex, including the sequence fragment which
 
16
            should be compared with sequence from the sequence buffer.
 
17
        (2) The index of the first residue in the sequence fragment which
 
18
            is currently checked.
 
19
        (3) Number of residues in  the sequence which  is associated with
 
20
            the current  macromolecular complex.  The fragment  mentioned
 
21
            above belongs to this sequence.
 
22
        (4) Pointer to the first residue in the sequence buffer.
 
23
        (5) Number of residues in the sequence buffer.
 
24
 
 
25
Output:
 
26
        Return value.
 
27
 
 
28
Return value:
 
29
        (1) Positive, if two sequences match.
 
30
        (2) Negative, if two sequences do not match.
 
31
 
 
32
Notes:
 
33
        (1) Don't forget  to check are there  enough residues in the seq.
 
34
            fragment which is compared with the sequence buffer.  If this
 
35
            is not checked, a memory overflow may occur.
 
36
 
 
37
        (2) Use strncmp to compare residue names because residue names in
 
38
            the sequence buffer are not zero terminated!
 
39
 
 
40
========includes:============================================================*/
 
41
 
 
42
#include <stdio.h>
 
43
 
 
44
#include <string.h>
 
45
 
 
46
#include <X11/Xlib.h>
 
47
#include <X11/Xutil.h>
 
48
#include <X11/Xos.h>
 
49
#include <X11/Xatom.h>
 
50
 
 
51
#include "defines.h"
 
52
#include "typedefs.h"
 
53
 
 
54
/*======compare sequences:===================================================*/
 
55
 
 
56
int CompareSequences_ (MolComplexS *curr_mol_complexSP,
 
57
                       size_t start1I, size_t residues1N,
 
58
                       char *first_name2P, size_t residues2N)
 
59
{
 
60
int             max_length;
 
61
size_t          residue1I, residue2I;
 
62
ResidueS        *curr_residue1SP;
 
63
AtomS           *atom1SP;
 
64
char            *name1P;
 
65
char            *name2P;
 
66
 
 
67
/* If there is only one residue in the sequence buffer, the sequences match: */
 
68
if (residues2N == 1) return 1;
 
69
 
 
70
/* Check is the sequence fragment long enough to be */
 
71
/* compared with sequence from the sequence buffer: */
 
72
if (start1I + residues2N > residues1N) return -1;
 
73
 
 
74
/* The maximal residue name length: */
 
75
max_length = RESNAMESIZE - 1;
 
76
 
 
77
/* Scan the sequence fragment: */
 
78
residue2I = 1;
 
79
for (residue1I = start1I + 1; residue1I < start1I + residues2N; residue1I++)
 
80
        {
 
81
        /* Pointer to the current residue: */
 
82
        curr_residue1SP = curr_mol_complexSP->residueSP + residue1I;
 
83
 
 
84
        /* Pointer to the first atom of the current residue: */
 
85
        atom1SP = curr_mol_complexSP->atomSP +
 
86
                  curr_residue1SP->residue_startI;
 
87
 
 
88
        /* Pointer the the name of the current residue: */
 
89
        name1P = atom1SP->raw_atomS.pure_residue_nameA;
 
90
 
 
91
        /* Pointer to the name of the corresponding residue in the buffer: */
 
92
        name2P = first_name2P + residue2I * max_length;
 
93
 
 
94
        /* Compare residue names; if they do */
 
95
        /* not match, return negative value: */
 
96
        if (strncmp (name1P, name2P, max_length) != 0) return -1;
 
97
 
 
98
        /* Update the residue index which is scanning the sequence buffer: */
 
99
        residue2I++;
 
100
        }
 
101
 
 
102
/* If this point is reached, two sequences match! */
 
103
 
 
104
/* Return positive value on success: */
 
105
return 1;
 
106
}
 
107
 
 
108
/*===========================================================================*/
 
109
 
 
110