Bsoft  2.1.0
Bernard's software package
bcormut.cpp
Go to the documentation of this file.
1 
9 #include "seq_analysis.h"
10 #include "rwmolecule.h"
11 #include "rwimg.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bcormut [options] input.pir output.pir",
23 "---------------------------------------------",
24 "Analyzes for correlated mutations in aligned protein sequences.",
25 "The -cutoff option must be used to do the correlated mutation analysis.",
26 "All sequence numbers and position numbers start at 1.",
27 "Sequence numbering is according to the input, including gaps.",
28 " ",
29 "Actions:",
30 "-cutoff 0.3 Correlated mutations: cutoff to report.",
31 "-limit Limit output to reference sequence.",
32 " ",
33 "Parameters:",
34 "-verbose 7 Verbosity of output.",
35 "-datatype b Set the output image data type.",
36 "-reference HUMAN Reference sequence identifier (substring).",
37 " ",
38 "Input:",
39 "-properties file.star Property file (default = internal values).",
40 " ",
41 "Output:",
42 "-matrix file.mat Correlation coefficient matrix.",
43 "-image file.map Correlation coefficient matrix as an image.",
44 " ",
45 "Examples:",
46 "bcormut -verbose 7 -cutoff 0.4 -image coeff.map -datatype byte seq.pir",
47 " ",
48 NULL
49 };
50 
51 int main(int argc, char **argv)
52 {
53  // Initialize variables
54  DataType nudatatype(Unknown_Type); // Conversion to new type
55  Bstring refseq; // Reference sequence ID
56  int limit(0); // Flag to limit to reference
57  double cutoff(0.8); // Cutoff for scoring functions
58  Bstring atom_select("ALL"); // Selection/options
59 
60  // Initialize the file names and image structure
61  Bstring matfile;
62  Bstring imgfile;
63  Bstring propfile;
64 
65  int i, j, optind;
66  Boption* option = get_option_list(use, argc, argv, optind);
67  Boption* curropt;
68  for ( curropt = option; curropt; curropt = curropt->next ) {
69  if ( curropt->tag == "datatype" )
70  nudatatype = curropt->datatype();
71  if ( curropt->tag == "reference" ) {
72  refseq = curropt->value;
73  if ( refseq.length() < 1 )
74  cerr << "-reference: A reference sequence ID must be specified!" << endl;
75  }
76  if ( curropt->tag == "limit" ) limit = 1;
77  if ( curropt->tag == "cutoff" )
78  if ( ( cutoff = curropt->value.real() ) < 1e-10 )
79  cerr << "-cutoff: A cutoff must be specified!" << endl;
80  if ( curropt->tag == "properties" )
81  propfile = curropt->filename();
82  if ( curropt->tag == "matrix" )
83  matfile = curropt->filename();
84  if ( curropt->tag == "image" )
85  imgfile = curropt->filename();
86  }
87  option_kill(option);
88 
89  double ti = timer_start();
90 
91  // Read the molecule file
92  Bstring filename(argv[optind++]);
93  Bmolgroup* molgroup = read_molecule(filename, atom_select, propfile);
94  if ( !molgroup ) {
95  cerr << "Error: No input file read!" << endl;
96  bexit(-1);
97  }
98 
99  if ( limit ) seq_limit(molgroup, refseq);
100 
101  for ( i=j=0; i<molgroup->maxlen; i++ )
102  j += molgroup->seqflag[i];
103 
104  if ( verbose & VERB_PROCESS )
105  cout << "Alignment positions flagged: " << j << endl;
106 
107  Matrix mat = seq_correlated_mutation(molgroup, refseq, cutoff, propfile);
108 
109  if ( optind < argc )
110  write_molecule(argv[optind], molgroup);
111 
112  molgroup_kill(molgroup);
113 
114  if ( matfile.length() && mat.rows() )
115  mat.write(matfile);
116 
117  if ( imgfile.length() && mat.rows() ) {
118  Bimage* pimg = new Bimage(mat, 1);
119  pimg->change_type(nudatatype);
120  write_img(imgfile, pimg, 0);
121  delete pimg;
122  }
123 
124  if ( verbose & VERB_TIME )
125  timer_report(ti);
126 
127  bexit(0);
128 }
129 
Boption
A class for a command line input option.
Definition: options.h:26
main
int main(int argc, char **argv)
Definition: bcormut.cpp:51
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bmolgroup::seqflag
int * seqflag
Definition: rwmolecule.h:188
Bstring
Definition: Bstring.h:29
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
Bstring::real
double real()
Definition: Bstring.cpp:553
read_molecule
Bmolgroup * read_molecule(const char *filename, const char *select, const char *paramfile)
The generalized function for reading molecular files.
Definition: rwmolecule.cpp:818
options.h
Header file for option handlers.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
seq_limit
long seq_limit(Bmolgroup *molgroup, Bstring &refseq)
Limits the selection to the reference sequence in an aligned set.
Definition: seq_analysis.cpp:36
Boption::tag
Bstring tag
Definition: options.h:29
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Matrix::rows
long rows()
Definition: Matrix.h:153
verbose
int verbose
rwmolecule.h
Header file for reading reflection files.
Boption::value
Bstring value
Definition: options.h:30
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Bmolgroup::maxlen
long maxlen
Definition: rwmolecule.h:180
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
utilities.h
Header file for general utilities.
seq_analysis.h
Header file for sequence analysis functions.
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
seq_correlated_mutation
Matrix seq_correlated_mutation(Bmolgroup *molgroup, Bstring &refseqid, double cutoff, Bstring &simfile)
Correlated mutation analysis of an alignment.
Definition: seq_analysis.cpp:933
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
rwimg.h
Header file for 2D and 3D image I/O.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
Matrix::write
void write(Bstring &filename)
Definition: Matrix.h:95
Bmolgroup
Definition: rwmolecule.h:170
use
const char * use[]
Definition: bcormut.cpp:20
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
Matrix
Definition: Matrix.h:22