Bsoft  2.1.0
Bernard's software package
rwgencode.cpp
Go to the documentation of this file.
1 
9 #include "rwgencode.h"
10 #include "rwstar.h"
11 #include "mol_tags.h"
12 #include "utilities.h"
13 
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16 
17 // Internal function prototypes
19 
20 
27 {
28  if ( verbose & VERB_DEBUG )
29  cout << "DEBUG get_genetic_code: Initializing atomic parameters" << endl;
30 
31  Bstring code;
32 
33  // Atom parameter file
34  Bstring gcfile = "gencode.star";
35  if ( filename.c_str() ) gcfile = filename;
36 
37  Bstring propfile = parameter_file_path(gcfile);
38  Bstring ext = gcfile.extension();
39  if ( ext.length() ) {
40  if ( ext.contains("star") )
41  code = read_gencode_star(propfile);
42  }
43 
44  if ( code.length() != 64 ) {
45  if ( verbose )
46  cout << "Genetic code file " << gcfile << " not opened! Using default code" << endl;
47  }
48 
49  if ( verbose & VERB_DEBUG )
50  cout << "DEBUG get_genetic_code: " << code << endl;
51 
52  return code;
53 }
54 
61 int write_genetic_code(Bstring& filename, Bstring& gc)
62 {
63 
64  return 0;
65 }
66 
68 {
69  int index;
70 
71  Bstar* star = init_star();
72 
73  read_star(propfile.c_str(), star);
74 
76  unsigned long ncode = item_get_number_for_block(block, RESPROP_CODON);
77  Bstar_item* item_res = item_find(block, RESPROP_CODE1);
78  Bstar_item* item_codon = item_find(block, RESPROP_CODON);
79  Bstring* data_res, *data_codon;
80 
81  if ( ncode != 64 ) {
82  cerr << "Error: File " << propfile << " does contain only " << ncode << " codons, 64 required!" << endl;
83  return "";
84  }
85 
86  if ( verbose & VERB_DEBUG )
87  cout << "DEBUG read_gencode_star: " << *(item_res->data) << endl << *(item_codon->data) << endl;
88 
89 // Bstring gc(64L, ' ');
90  Bstring gc(' ', 64L);
91 
92  for ( data_res = item_res->data, data_codon = item_codon->data; data_res && data_codon;
93  data_res = data_res->next, data_codon = data_codon->next ) {
94  index = index_from_codon(data_codon->c_str());
95  gc[index] = data_res[0][0];
96  }
97 
98  kill_star(star);
99 
100  if ( verbose & VERB_DEBUG )
101  cout << "DEBUG read_gencode_star: " << gc << endl;
102 
103  return gc;
104 }
105 
111 //int index_from_codon(const char* codon)
112 int index_from_codon(const char codon[3])
113 {
114  int i, j, index(0), e;
115  char acgt[8] = "ACGT";
116  char upcodon[4];
117 
118  for ( i=0; i<3; i++ ) {
119  upcodon[i] = toupper(codon[i]);
120  e = (int) pow(4.0, 2.0 - i);
121  for ( j=0; j<4; j++ ) {
122  if ( upcodon[i] == acgt[j] ) index += e*j;
123  }
124  }
125 
126  return index;
127 }
Bstar_item::data
Bstring * data
Definition: rwstar.h:43
Bstar_item
Definition: rwstar.h:36
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bstring
Definition: Bstring.h:29
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
parameter_file_path
Bstring parameter_file_path(Bstring filename)
Finds the parameter file path.
Definition: Bstring.cpp:795
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
mol_tags.h
All STAR file format tags for molecules and molecular parameters.
rwgencode.h
Header file for reading a genetic code from a file.
verbose
int verbose
item_get_number_for_block
long item_get_number_for_block(Bstar_block *block, const char *tag)
Gets the number of values associated with a tag in a STAR data block.
Definition: rwstar.cpp:1163
utilities.h
Header file for general utilities.
read_gencode_star
Bstring read_gencode_star(Bstring &propfile)
Definition: rwgencode.cpp:67
Bstring::length
long length() const
Definition: Bstring.cpp:263
read_star
int read_star(const char *filename, Bstar *star)
Reads paramaters and data into a STAR data base from a list of files.
Definition: rwstar.cpp:224
kill_star
int kill_star(Bstar *star)
Destroys a STAR data base.
Definition: rwstar.cpp:132
Bstring::next
Bstring * next
Definition: Bstring.h:31
index_from_codon
int index_from_codon(const char codon[3])
Gets the index associated with a specific codon.
Definition: rwgencode.cpp:112
get_genetic_code
Bstring get_genetic_code(Bstring &filename)
Gets the genetic code from a parameter file.
Definition: rwgencode.cpp:26
item_find
Bstar_item * item_find(Bstar_block *block, const char *tag)
Gets the STAR item associated with a tag in a STAR data block.
Definition: rwstar.cpp:1083
write_genetic_code
int write_genetic_code(Bstring &filename, Bstring &gc)
Writing genetic code.
Definition: rwgencode.cpp:61
rwstar.h
A header file for STAR format files.
RESPROP_CODE1
#define RESPROP_CODE1
Definition: mol_tags.h:81
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
RESPROP_CODON
#define RESPROP_CODON
Definition: mol_tags.h:80
Bstar_block
Definition: rwstar.h:55
init_star
Bstar * init_star()
Creates a STAR data base.
Definition: rwstar.cpp:111
Bstar
Definition: rwstar.h:78
block_find_with_tag
Bstar_block * block_find_with_tag(Bstar *star, const char *tag)
Gets the first block associated with a tag in a STAR data base.
Definition: rwstar.cpp:1050