Skip to content

Commit 1bb63a2

Browse files
committed
fixed Ubuntu link error, llvm compile errors; check for sorted input alns
1 parent 116ab3b commit 1bb63a2

10 files changed

Lines changed: 90 additions & 30 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ GDIR :=./gclib
66

77
SEARCHDIRS := -I. -I${GDIR} -I${BAM}
88

9-
#SYSTYPE := $(shell uname)
10-
9+
#CC := clang++
1110
CC := g++
1211

1312

@@ -48,6 +47,7 @@ BASEFLAGS := -Wall -Wextra ${SEARCHDIRS} $(MARCH) -D_FILE_OFFSET_BITS=64 \
4847

4948
# C/C++ linker
5049

50+
#LINKER := clang++
5151
LINKER := g++
5252

5353
LIBS := -lbam -lz

gclib/GBase.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ char* newEmptyStr() {
170170
char* Gstrdup(const char* sfrom, const char* sto) {
171171
if (sfrom==NULL || sto==NULL) return NULL;
172172
char *copy=NULL;
173-
if (sfrom[0]==0) return newEmptyStr();
173+
if (sfrom[0]==0 || sto<sfrom) return newEmptyStr();
174174
GMALLOC(copy, sto-sfrom+2);
175175
strncpy(copy, sfrom, sto-sfrom+1);
176176
copy[sto-sfrom+1]=0;
@@ -229,6 +229,25 @@ int Gmkdir(const char *path, bool recursive, int perms) {
229229
return 0;
230230
}
231231

232+
bool GstrEq(const char* a, const char* b) {
233+
if (a==NULL || b==NULL) return false;
234+
register int i=0;
235+
while (a[i]==b[i]) {
236+
if (a[i]==0) return true;
237+
++i;
238+
}
239+
return false;
240+
}
241+
242+
bool GstriEq(const char* a, const char* b) {
243+
if (a==NULL || b==NULL) return false;
244+
register int i=0;
245+
while (tolower((unsigned char)a[i])==tolower((unsigned char)b[i])) {
246+
if (a[i]==0) return true;
247+
}
248+
return false;
249+
}
250+
232251
int Gstricmp(const char* a, const char* b, int n) {
233252
if (a==NULL || b==NULL) return a==NULL ? -1 : 1;
234253
register int ua, ub;
@@ -537,7 +556,7 @@ char* strifind(const char* str, const char* substr) {
537556
char* p=(char*)str;
538557
while (p<=smax) {
539558
for (i=0; i<l && tolower(*(p+i))==tolower(*(substr+i)); i++) ;
540-
if (i==l) return p; //found!
559+
if (i==l) return p;
541560
p++;
542561
}
543562
return NULL;
@@ -553,6 +572,14 @@ bool startsWith(const char* s, const char* prefix) {
553572
return (prefix[i]=='\0');
554573
}
555574

575+
bool startsiWith(const char* s, const char* prefix) {
576+
if (prefix==NULL || s==NULL) return false;
577+
int i=0;
578+
while (prefix[i]!='\0' && tolower(prefix[i])==tolower(s[i])) i++;
579+
return (prefix[i]=='\0');
580+
}
581+
582+
556583
// tests if string s ends with given suffix
557584
bool endsWith(const char* s, const char* suffix) {
558585
if (suffix==NULL || s==NULL) return false;

gclib/GBase.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ int Gstrcmp(const char* a, const char* b, int n=-1);
185185
//same as strcmp but doesn't crash on NULL pointers
186186

187187
int Gstricmp(const char* a, const char* b, int n=-1);
188+
bool GstrEq(const char* a, const char* b);
189+
bool GstriEq(const char* a, const char* b);
188190

189191
//basic swap template function
190192
template<class T> void Gswap(T& lhs, T& rhs) {
@@ -259,14 +261,17 @@ char* rstrstr(const char* rstart, const char *lend, const char* substr);
259261
a pointer to the last (right) matching character in str */
260262

261263
char* strifind(const char* str, const char* substr);
262-
// the case insensitive version of strstr -- finding a string within a strin
263-
264+
// case insensitive version of strstr -- finding a string within another string
265+
// returns NULL if not found
264266

265267
//Determines if a string begins with a given prefix
266268
//(returns false when any of the params is NULL,
267269
// but true when prefix is '' (empty string)!)
268270
bool startsWith(const char* s, const char* prefix);
269271

272+
bool startsiWith(const char* s, const char* prefix); //case insensitive
273+
274+
270275
bool endsWith(const char* s, const char* suffix);
271276
//Note: returns true if suffix is empty string, but false if it's NULL
272277

gclib/GHash.hh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ template <class OBJ> OBJ* GHash<OBJ>::Replace(const char* ky,const OBJ* pdata,
326326
template <class OBJ> OBJ* GHash<OBJ>::Remove(const char* ky){
327327
register int p,x,h,n;
328328
if(!ky){ GError("GHash::remove: NULL key argument.\n"); }
329+
OBJ* removed=NULL;
329330
if(0<fCount){
330331
h=strhash(ky);
331332
GASSERT(0<=h);
@@ -342,18 +343,19 @@ template <class OBJ> OBJ* GHash<OBJ>::Remove(const char* ky){
342343
hash[p].mark=false;
343344
if (hash[p].keyalloc) GFREE((hash[p].key));
344345
if (FREEDATA) (*fFreeProc)(hash[p].data);
346+
else removed=(OBJ*)hash[p].data;
345347
hash[p].key=NULL;
346348
hash[p].data=NULL;
347349
fCount--;
348350
if((100*fCount)<=(MIN_LOAD*fCapacity)) Resize(fCount);
349351
GASSERT(fCount<fCapacity);
350-
return NULL;
352+
return removed;
351353
}
352354
p=(p+x)%fCapacity;
353355
n--;
354356
}
355357
}
356-
return NULL;
358+
return removed;
357359
}
358360

359361

gclib/GVec.hh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ template<class T> struct IsPrimitiveType {
2929

3030
template<> struct IsPrimitiveType<bool> { enum { VAL = 1 }; };
3131
template<> struct IsPrimitiveType<void*> { enum { VAL = 1 }; };
32+
template<> struct IsPrimitiveType<char*> { enum { VAL = 1 }; };
3233
template<> struct IsPrimitiveType<float> { enum { VAL = 1 }; };
3334
template<> struct IsPrimitiveType<double> { enum { VAL = 1 }; };
3435

@@ -73,6 +74,7 @@ template <class OBJ> class GVec {
7374
public:
7475
GVec(int init_capacity=2);
7576
GVec(int init_count, const OBJ init_val);
77+
GVec(int init_count, OBJ* init_val, bool delete_initval=true); //convenience constructor for complex vectors
7678
GVec(GVec<OBJ>& array); //copy constructor
7779
const GVec<OBJ>& operator=(GVec<OBJ>& array); //copy operator
7880
virtual ~GVec();
@@ -206,6 +208,7 @@ template <class OBJ> GVec<OBJ>::GVec(int init_capacity) {
206208
fCapacity=0;
207209
fArray=NULL;
208210
setCapacity(init_capacity);
211+
//if (set_count) fCount = init_capacity;
209212
}
210213

211214

@@ -219,6 +222,17 @@ template <class OBJ> GVec<OBJ>::GVec(int init_count, const OBJ init_val) {
219222
fArray[i]=init_val;
220223
}
221224

225+
template <class OBJ> GVec<OBJ>::GVec(int init_count, OBJ* init_val, bool delete_initval) {
226+
fCount=0;
227+
fCapacity=0;
228+
fArray=NULL;
229+
setCapacity(init_count);
230+
fCount = init_count;
231+
for (int i=0;i<fCount;i++)
232+
fArray[i]=*init_val;
233+
if (delete_initval) { delete init_val; }
234+
}
235+
222236

223237
template <class OBJ> GVec<OBJ>::GVec(GVec<OBJ>& array) { //copy constructor
224238
this->fCount=array.fCount;
@@ -741,7 +755,6 @@ template <class OBJ> void GPVec<OBJ>::Grow(int idx, OBJ* newitem) {
741755
}
742756

743757
template <class OBJ> int GPVec<OBJ>::IndexOf(pointer item) {
744-
int result=-1;
745758
for (int i=0;i<fCount;i++) {
746759
if (item==(pointer)fList[i]) return i;
747760
}

gclib/gff.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,13 @@ GffLine::GffLine(GffReader* reader, const char* l):_parents(NULL), _parents_len(
366366
} //exon feature?
367367
if (Parent==NULL) {
368368
//something is very wrong here, cannot parse the GTF ID
369-
GMessage("Warning: invalid GTF record, transcript_id not found:\n%s\n",
370-
l);
371-
}
372-
/* if (Parent==NULL && exontype>=exgffCDS &&
373-
(i=strcspn(info,"; \t\n\r"))<=(int)(strlen(info)+1)) {
374-
//one word ID ? really desperate attempt to parse it here
375-
Parent=Gstrdup(info,info+i-1);
376-
info=NULL; //discard anything else on the line
369+
if (is_transcript || exontype)
370+
GMessage("Warning: invalid GTF record, transcript_id not found:\n%s\n",
371+
l);
372+
else return; //skip unrecognized GTF line (from GTF we only care about transcripts for now)
373+
377374
}
378-
*/
379-
}
375+
} //Parent was NULL, attempted to find it
380376
if (Parent!=NULL) { //GTF transcript_id for exon/CDS feature
381377
_parents=Parent;
382378
GMALLOC(parents,sizeof(char*));

rlink.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ inline int edge(int min, int max, int gno) {
966966
return((gno-1)*(min+1)-min*(min-1)/2+max-min); // this includes source to node edges
967967
}
968968

969-
GBitVec traverse_dfs(int s,int g,CGraphnode *node,CGraphnode *sink,GBitVec parents,int gno,GVec<bool>& visit,
969+
GBitVec traverse_dfs(int s,int g,CGraphnode *node,CGraphnode *sink,GBitVec parents,int gno, GVec<bool>& visit,
970970
GPVec<CGraphnode> **no2gnode,GPVec<CTransfrag> **transfrag){
971971

972972
if(visit[node->nodeid]) {
@@ -1847,14 +1847,19 @@ void process_transfrags(int gno,GPVec<CGraphnode>& no2gnode,GPVec<CTransfrag>& t
18471847

18481848
//if(!EM) {
18491849
if(0) {
1850-
GVec<float> n[gno]; // abundances of all transfrags passing through node and leaving node
1851-
GVec<float> f[gno]; // abundances of all transfrags leaving node
1850+
GVec<float> f_init(gno, float(0));
1851+
GVec< GVec<float> > n(gno, &f_init, false);
1852+
//GVec<float> n[gno]; // abundances of all transfrags passing through node and leaving node
1853+
GVec< GVec<float> > f(gno, &f_init, false);
1854+
//GVec<float> f[gno]; // abundances of all transfrags leaving node
1855+
//GVec< GVec<int> > u(gno, new GVec<int>(gno,0) );
18521856
//GVec<int> u[gno]; // transfrags that are uncommited to a specific child; this is a more complicated issue -> ignore for now
1857+
/*
18531858
for(int i=1;i<gno-1;i++) {
18541859
n[i].Resize(gno,0);
18551860
f[i].Resize(gno,0);
18561861
}
1857-
1862+
*/
18581863
for(int t=0;t<transfrag.Count();t++)
18591864
if(transfrag[t]->nodes[0] && transfrag[t]->nodes.Count()) { // transfrag has more than one node, and doesn't start at source
18601865
for(int i=0;i<transfrag[t]->nodes.Count()-1;i++) { // for all nodes in transfrags that are not last
@@ -8732,7 +8737,7 @@ int print_cluster_inclusion(GPVec<CPrediction>& pred,GVec<int>& genes,GVec<int>&
87328737
// sort predictions from the one with the most exons to the one with the least:
87338738
pred.Sort(predexCmp);
87348739

8735-
GVec<int> included[pred.Count()];
8740+
GVec< GVec<int> > included(pred.Count()); included.Resize(pred.Count());
87368741
GVec<float> maxcov;
87378742
GVec<float> totalcov;
87388743

@@ -9000,7 +9005,7 @@ int printResults(BundleData* bundleData, int ngenes, int geneno, GStr& refname)
90009005
*/
90019006

90029007
// this version is more inclusive by stiching together single exons to reference guides that overlap them
9003-
GVec<int> reflink[npred];
9008+
GVec< GVec<int> > reflink(npred); reflink.Resize(npred);
90049009
for(int n=0;n<npred;n++) {
90059010

90069011
if(pred[n] && pred[n]->t_eq) {

rlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct CPrediction:public GSeg {
145145
}
146146
};
147147

148-
class CJunction;
148+
struct CJunction;
149149

150150
struct CReadAln:public GSeg {
151151
//DEBUG ONLY:

stringtie.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include "proc_mem.h"
1010
#endif
1111

12-
#define VERSION "1.0.1"
12+
#define VERSION "1.0.2"
13+
1314
//uncomment this to show DBGPRINT messages (for threads)
1415
//#define DEBUGPRINT 1
1516

@@ -188,12 +189,14 @@ int main(int argc, char * const argv[]) {
188189
GPVec<RC_ScaffData> refguides_RC_Data(true);
189190
GPVec<RC_Feature> refguides_RC_exons(true);
190191
GPVec<RC_Feature> refguides_RC_introns(true);
191-
192+
GVec<int> alncounts(30,0); //number of read alignments per chromosome [gseq_id]
192193

193194
#ifdef DEBUGPRINT
194195
verbose=true;
195196
#endif
196197

198+
const char* ERR_BAM_SORT="\nError: the input alignment file is not sorted!\n";
199+
197200
if(guided) { // read guiding transcripts from input gff file
198201
if (verbose) {
199202
printTime(stderr);
@@ -289,6 +292,7 @@ if (ballgown)
289292
#endif
290293
GBamRecord* brec=NULL;
291294
bool more_alns=true;
295+
int prev_pos=0;
292296
while (more_alns) {
293297
bool chr_changed=false;
294298
int pos=0;
@@ -308,7 +312,15 @@ if (ballgown)
308312
chr_changed=(lastref.is_empty() || lastref!=rname);
309313
if (chr_changed) {
310314
gseq_id=gseqNames->gseqs.addName(rname);
315+
if (alncounts.Count()<=gseq_id) {
316+
alncounts.Resize(gseq_id+1, 0);
317+
}
318+
else if (alncounts[gseq_id]>0) GError(ERR_BAM_SORT);
319+
prev_pos=0;
311320
}
321+
if (pos<prev_pos) GError(ERR_BAM_SORT);
322+
alncounts[gseq_id]++;
323+
prev_pos=pos;
312324
xstrand=brec->spliceStrand();
313325
if (xstrand=='+') strand=1;
314326
else if (xstrand=='-') strand=-1;
@@ -719,7 +731,7 @@ GStr Process_Options(GArgs* args) {
719731
}
720732
}
721733
if (ballgown && !guided)
722-
GError("Error: invalid -b usage, GFF reference not given (-G option required).\n");
734+
GError("Error: invalid -B/-b usage, GFF reference not given (-G option required).\n");
723735

724736
s=args->getOpt('P');
725737
if (!s.is_empty()) {

tablemaker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ FILE* rc_fwopen(const char* fname);
187187
FILE* rc_frenopen(const char* fname);
188188
void rc_frendel(const char* fname);
189189

190-
class BundleData;
190+
struct BundleData;
191191

192192
//void rc_write_counts(const char* refname, BundleData& bundle);
193193

0 commit comments

Comments
 (0)