File: IsoformAugment.cc

package info (click to toggle)
trinityrnaseq 2.6.6%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 346,416 kB
  • sloc: perl: 47,542; cpp: 20,209; java: 12,484; python: 2,766; sh: 1,665; makefile: 895; ansic: 90; xml: 83
file content (156 lines) | stat: -rw-r--r-- 3,349 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 #include <string>

#include "base/CommandLineParser.h"
#include "analysis/DNAVector.h"
#include "base/FileParser.h"

#include "aligns/KmerAlignCore.h"




int main(int argc,char** argv)
{

  
  commandArg<string> aStringCmmd("-t","fasta transcript file");
  commandArg<string> bStringCmmd("-i","inchworm file");
  commandArg<string> oStringCmmd("-o","output fasta file");
  commandLineParser P(argc,argv);
  P.SetDescription("Maps chrysalis components to a reference.");
  P.registerArg(aStringCmmd);
  P.registerArg(bStringCmmd);
  P.registerArg(oStringCmmd);

  P.parse();

  string aString = P.GetStringValueFor(aStringCmmd);
  string bString = P.GetStringValueFor(bStringCmmd);
  string outFile = P.GetStringValueFor(oStringCmmd);
  
  vecDNAVector ref;
  vecDNAVector iworm;
  vecDNAVector out;
  
  cout << "Reading files..." << endl;
  ref.Read(aString);
  iworm.Read(bString);
  cout << "done!" << endl;
  //test.ReverseComplement();


  TranslateBasesToNumberExact trans;
  KmerAlignCore core;
  core.SetTranslator(&trans);
  core.SetNumTables(2);
  core.AddData(ref);
  //core.SortAll();

  size_t i, j;

  int min = 24;
  int k = 24;


  for (i=0; i<iworm.size(); i++) {
    const DNAVector & d = iworm[i];
    //if  (d.isize() > 300)
    //  continue;

    vec<KmerAlignCoreRecord> matchesLeft, matchesRight, matchesMiddle;
    int l = d.isize();
    core.GetMatches(matchesMiddle, d, l/2-k/2);

    if (matchesMiddle.isize() != 0) {
      //cout << "Middle match." << endl;
      continue;
    }

    core.GetMatches(matchesLeft, d, 0);
    core.GetMatches(matchesRight, d, l-k);

    //cout << "left=" << matchesLeft.isize() << " right=" << matchesRight.isize() << endl;

    if (matchesLeft.isize() == 0 || matchesRight.isize() == 0)
      continue;
    if (matchesLeft.isize() > 8 || matchesRight.isize() > 8)
      continue;

    bool bBad = false;

    svec<int> matches;
    svec<int> posLeft;
    svec<int> posRight;

    int diff = d.isize()-k;

    for (j=0; j<matchesLeft.isize(); j++) {
      int c = matchesLeft[j].GetContig();
      int p = matchesLeft[j].GetPosition();
      for (int x = 0; x<matchesRight.isize(); x++) {
	int cR = matchesRight[x].GetContig();
	int pR = matchesRight[x].GetPosition();
	if (c != cR)
	  continue;

	//if (iworm.Name(i) == ref.Name(c))
	//continue;

	int cDiff = pR-p;
	int dist = cDiff - diff;
	if (dist < 0)
	  dist = -dist;
	

	if (dist < min) {
	  bBad = true;
	  break;
	} else {
	  //cout << "Found dist=" << dist << endl;
	  matches.push_back(c);
	  posLeft.push_back(p);
	  posRight.push_back(pR);
	}

      }
    }
    if (bBad)
      continue;
    if (matches.isize() == 0)
      continue;
    
    for (j=0; j<matches.isize(); j++) {
      //if (j == 1)
      //break;

      cout << ref.Name(matches[j]) << "_alt" << endl;
      const DNAVector & orig = ref[matches[j]];
      DNAVector nn;
      nn.resize(orig.isize() + d.isize() - 2*k);
      int c = 0;
      for (int y=0; y<posLeft[j]; y++) {
	cout << orig[y];
	//nn[c] = orig[y];
	//c++;
      }
      for (int y=0; y<d.isize(); y++) {
	cout << d[y];
	//nn[c] = d[y];
	//c++;
      }
      for (int y=posRight[j]+k; y<orig.isize(); y++) {
	cout << orig[y];
	//nn[c] = orig[y];
	//c++;
      }
      cout << endl;
      //out.push_back(nn, ref.Name(matches[j])+"_alt");
    }
  }

  out.Write(outFile);

  return 0;

}