@@ -224,28 +224,45 @@ struct RC_BundleData {
224224 int init_lmin;
225225 int lmin;
226226 int rmax;
227- GPVec<RC_TData> tdata; // all transcripts in this bundle (not used unless -B)
228- GList<RC_Feature> g_exons; // all unique guide exons in this bundle, sorted by their start coordinate
229- GList<RC_Feature> g_introns; // all unique guide introns in this bundle, sorted by their start coordinate
227+ GPVec<RC_TData> g_tdata; // raw counting data for all transcripts in this bundle
228+ // RC_TData::t_id-1 = the element index in this array
229+ GList<RC_Feature> g_exons; // set of guide exons in this bundle, sorted by their start coordinate
230+ GList<RC_Feature> g_introns; // set of guide introns in this bundle, sorted by their start coordinate
230231 // RC_FeatIt xcache; //cache the first exon overlapping xcache_pos to speed up exon-overlap queries (findOvlExons())
231232 int xcache; // exons index of the first exon overlapping xcache_pos
232233 int xcache_pos; // left coordinate of last cached exon overlap query (findOvlExons())
234+
233235 // the following coverage arrays will only used with Ballgown data (-B)
234236 vector<float > f_mcov; // coverage data, multi-map aware, per strand
235237 vector<int > f_cov;
236238 vector<float > r_mcov; // coverage data on the reverse strand
237239 vector<int > r_cov;
238- //
239- RC_BundleData (int t_l=0 , int t_r=0 ):init_lmin(0 ), lmin(t_l), rmax(t_r),
240- tdata (false ), // features:(sorted, free, unique)
240+
241+ // -- when no global Ballgown data is to be generated, these are
242+ // local (bundle) stable order tables of guide features
243+ GPVec<RC_TData>* guides_RC_tdata; // just a pointer to the current RC tdata table
244+ // RC_Feature::id-1 = the index in these arrays:
245+ GPVec<RC_Feature>* guides_RC_exons;
246+ GPVec<RC_Feature>* guides_RC_introns;
247+ uint c_exon_id;
248+ uint c_intron_id;
249+ // --
250+ RC_BundleData (int t_l=0 , int t_r=0 , GPVec<RC_TData>* rc_tdata=NULL ,
251+ GPVec<RC_Feature>* rc_exons=NULL ,GPVec<RC_Feature>* rc_introns=NULL ):
252+ init_lmin (0 ), lmin(t_l), rmax(t_r), g_tdata(false ),
253+ // features:(sorted, free, unique)
241254 g_exons (true , false , true ), g_introns(true , false , true ),
242- xcache(0 ), xcache_pos(0 )
243- {
255+ xcache (0 ), xcache_pos(0 ),
256+ guides_RC_tdata (rc_tdata), guides_RC_exons(rc_exons), guides_RC_introns(rc_introns),
257+ c_exon_id (0 ), c_intron_id(0 )
258+ {
244259 if (ballgown) {
245260 if (rmax>lmin) updateCovSpan ();
246- }else { // this will be deallocated when the bundle is cleared
247- g_exons.setFreeItem (true );
248- g_introns.setFreeItem (true );
261+ }else {
262+ g_tdata.setFreeItem (true );
263+ guides_RC_tdata = &g_tdata;
264+ guides_RC_exons = new GPVec<RC_Feature>(true );
265+ guides_RC_introns= new GPVec<RC_Feature>(true );
249266 }
250267 }
251268
@@ -254,6 +271,10 @@ struct RC_BundleData {
254271 f_mcov.clear ();
255272 r_cov.clear ();
256273 r_mcov.clear ();
274+ if (!ballgown) {
275+ delete guides_RC_exons;
276+ delete guides_RC_introns;
277+ }
257278 }
258279
259280 // for non-ballgown tracking of guide features
@@ -269,28 +290,42 @@ struct RC_BundleData {
269290 }
270291 }
271292
272- void addTranscript (GffObj& t) {
293+ uint addTranscript (GffObj& t) { // shouuld return the guide index in *guides_RC_tdata
273294 // if (!ps.rc_id_data()) return;
274295 // RC_ScaffIds& sdata = *(ps.rc_id_data());
275296 bool boundary_changed=false ;
276297 if (lmin==0 || lmin>(int )t.start ) { lmin=t.start ; boundary_changed=true ; }
277298 if (rmax==0 || rmax<(int )t.end ) { rmax=t.end ; boundary_changed=true ; }
278- if (t.uptr ) { // ballgown case
279- RC_TData& sdata=*(RC_TData*)(t.uptr );
280- // tdata.insert(sdata);
281- tdata.Add (&sdata);
282- if (boundary_changed) updateCovSpan ();
283- // for (vector<RC_ScaffSeg>::iterator it=sdata.exons.begin();it!=sdata.exons.end();++it) {
284- for (int i=0 ;i<sdata.t_exons .Count ();i++) {
285- g_exons.Add (sdata.t_exons [i]);
286- }
287- // store introns:
288- for (int i=0 ;i<sdata.t_introns .Count ();i++) {
289- g_introns.Add (sdata.t_introns [i]);
299+ RC_TData* tdata=NULL ;
300+ if (ballgown) {
301+ tdata=(RC_TData*)(t.uptr );
302+ }
303+ else {
304+ // int c_tid=g_tdata.Count();
305+ // add RC transcript data locally for the bundle
306+ tdata=new RC_TData (t, g_tdata.Count ()+1 );
307+ t.uptr =tdata;
308+ // guides_RC_Data.Add(tdata);
309+ tdata->rc_addFeatures (c_exon_id, g_exons, *guides_RC_exons,
310+ c_intron_id, g_introns, *guides_RC_introns);
311+ }
312+ // if (ballgown) { //ballgown case
313+ // RC_TData& sdata=*(RC_TData*)(t.uptr);
314+ g_tdata.Add (tdata);
315+ if (ballgown) {
316+ if (boundary_changed) updateCovSpan ();
317+ // need to add exons and introns because rc_addFeatures()
318+ // was NOT using g_exons and g_introns as unique sets if ballgown
319+ for (int i=0 ;i<tdata->t_exons .Count ();i++) {
320+ g_exons.Add (tdata->t_exons [i]);
321+ }
322+ for (int i=0 ;i<tdata->t_introns .Count ();i++) {
323+ g_introns.Add (tdata->t_introns [i]);
324+ }
290325 }
291- }
292- else {
293- // non-ballgown, regular storage of bundle guides data
326+ // } //if ballgown
327+ /*
328+ else { //non-ballgown, regular storage of bundle guides data
294329 //use GffObj::udata as tid, it's the index in bundledata::keepguides
295330 for (int i=0;i<t.exons.Count();++i) {
296331 addTranscriptFeature(t.exons[i]->start, t.exons[i]->end, t.strand, g_exons, t);
@@ -300,6 +335,8 @@ struct RC_BundleData {
300335 }
301336 }
302337 } //no ballgown coverage
338+ */
339+ return tdata->t_id ;
303340 }
304341
305342 void updateCovSpan () {
0 commit comments