NCBI C++ ToolKit
read_trna.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: read_trna.cpp 91324 2020-10-09 14:48:11Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Azat Badretdin
27 *
28 * File Description:
29 *
30 * ===========================================================================
31 */
32 #include <ncbi_pch.hpp>
33 #include "read_blast_result.hpp"
34 
35 int CReadBlastApp::ReadTRNA2(const string& file)
36 {
37  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): start" << NcbiEndl;
38  int n=0;
39  ifstream is(file.c_str());
40  if(!is.good())
41  {
42  NcbiCerr << "CReadBlastApp::ReadTRNA2(" << file << "): ERROR: cannot open " << NcbiEndl;
43  }
44  map <string, int> last_for_type;
45  while(is.good())
46  {
47  char line[0x1000];
48  is.getline(line, 0xFFF);
49  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): line: " << line << NcbiEndl;
50  if(!is.good()) break;
51 // gnl|uianeuro|1003 1 19274 19345 Glu TTC 0 0 0.00
52  char *token = strtok(line, " \t");
53  int icol=1;
54  int from=0, to=0;
55  int from_i=0, to_i=0;
56  string type3 = "";
57  double score = 0.0;
58  // int key=0;
59  string codon="";
60  string genome_name="";
61  while(token != 0)
62  {
63  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): token[" << icol << "]: " << token << NcbiEndl;
64  switch(icol)
65  {
66  case 1: genome_name = token; break;
67  // case 2: key = atoi(token); break;
68  case 3: from = atoi(token); break;
69  case 4: to = atoi(token); break;
70  case 5: type3= token; if(type3=="SeC") type3="Sec"; break;
71  case 6: codon = token;
72  case 7: from_i = atoi(token); break;
73  case 8: to_i = atoi(token); break;
74  case 9: score = atof(token); break;
75  default: break;
76  }
77  token = strtok(0, " \t");
78  icol++;
79  }
80  if(score<m_trnascan_scoreThreshold) continue;
81  ENa_strand strand = eNa_strand_plus;
82  bool reverse=to<from;
83  if(reverse) {int t=to; to=from;from=t; strand=eNa_strand_minus; }
84  reverse=to_i<from_i;
85  if(reverse) {int t=to_i; to_i=from_i;from_i=t; }
86  last_for_type[type3]++;
87  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): type3 = " << type3 << NcbiEndl;
88  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): last_for_type[type3] = " << last_for_type[type3] << NcbiEndl;
89  int ilast_for_type = last_for_type[type3];
90  CNcbiStrstream namestr;
91  namestr << genome_name << "|calculated|" << type3 << "_" << ilast_for_type << '\0';
92  CNcbiStrstream descstr;
93  descstr << "tRNA for " << type3 << ", codon " << codon << " predicted by tRNAscan" << '\0';
94  TSimpleSeq ext_rna;
95 // lot of tRNAs seems to be having left position just one bp off, assuming that it is a difference in naming
96  ext_rna.exons.resize(1);
97  ext_rna.exons[0].from = from-1;
98  ext_rna.exons[0].strand = strand;
99  if(from_i)
100  {
101  ext_rna.exons.resize(2);
102  ext_rna.exons[0].to=from_i-1;
103  ext_rna.exons[1].from=to_i+1;
104  ext_rna.exons[1].to =to;
105  ext_rna.exons[1].strand = strand;
106  }
107  else
108  {
109  ext_rna.exons[0].to = to - 1;
110  }
111  ext_rna.type = "tRNA";
112  ext_rna.type = "tRNA";
113  ext_rna.type3 = type3;
114  ext_rna.key = from;
115  ext_rna.name = namestr.str();
116  ext_rna.description = descstr.str();
117  m_extRNAtable2.push_back(ext_rna);
118  n++;
119  }
120 
121  if(PrintDetails()) NcbiCerr << "ReadTRNA2(" << file << "): end" << NcbiEndl;
122  return n;
123 }
124 
static bool PrintDetails(int current_verbosity=m_current_verbosity)
static double m_trnascan_scoreThreshold
TSimpleSeqs m_extRNAtable2
int ReadTRNA2(const string &file)
Definition: read_trna.cpp:35
#define NcbiEndl
Definition: ncbistre.hpp:548
#define NcbiCerr
Definition: ncbistre.hpp:544
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
FILE * file
yy_size_t n
EIPRangeType t
Definition: ncbi_localip.c:101
TSimplePairs exons
Modified on Tue May 14 16:16:12 2024 by modify_doxy.py rev. 669887