File: CloneManager.cpp

package info (click to toggle)
gentle 1.9+cvs20100605+dfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 12,264 kB
  • ctags: 5,235
  • sloc: cpp: 41,571; ansic: 3,978; sh: 1,420; makefile: 291
file content (119 lines) | stat: -rw-r--r-- 2,466 bytes parent folder | download | duplicates (6)
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
#include "CloneManager.h"

TCloneManager::TCloneManager ()
{
	_success = false ;
}

TCloneManager::~TCloneManager ()
{
}

int TCloneManager::scan_item ( unsigned char *t , int a , TVector *v )
{
	int b ;
	wxString name , desc ;
	a += 4 ;
//	unsigned int strange1 = *((unsigned int*)(t+a)) ;
	a += 4 ;
	if ( t[a] == 8 )
	{
		while ( t[a] != 255 || t[a+1] != 255 ) a += 4 ;
		return a ;
	}
//	unsigned int strange2 = *((unsigned int*)(t+a)) ;
	a += 4 ;
	unsigned int from = *((unsigned int*)(t+a)) ;
	a += 4 ;
	unsigned int to = *((unsigned int*)(t+a)) ;
	a += 4 ;
	for ( b = a ; t[b] >= 32 && b < a+8 ; b++ ) name += t[b] ;
	a += 8 ;
	for ( b = a ; t[b] ; b++ ) desc += t[b] ;
	a = b ;
	while ( a % 4 > 0 ) a++ ;
	while ( t[a] != 255 && ( t[a] < 'A' || t[a] > 'Z' ) ) a += 4 ; // Ugly hack!
	
	int dir = 1 ;
	if ( to < from )
	{
		dir = -1 ;
		int x = from ;
		from = to ;
		to = x ;
	}
	int type = VIT_MISC ;
	if ( to - from > 80 ) type = VIT_GENE ;
	else if ( name.Left(3).Lower() == _T("ori") ) type = VIT_REP_ORI ;
	TVectorItem vi ( name , desc , from , to , type ) ;
	vi.setDirection ( dir ) ;
	v->items.push_back ( vi ) ;
	
	return a ;
}

void TCloneManager::load ( wxString file )
{
	wxFile f ( file , wxFile::read ) ;
	long l = f.Length() ;
	unsigned char *t = new unsigned char [l+5] ;
	f.Read ( t , l ) ;
	f.Close() ;
	
	if ( t[0] != 26 || t[1] != 'S' || t[2] != 'E' || t[3] != 'S' )
	{
		delete t ;
		return ;
	}
	
	int a ;
	TVector *v = new TVector ;
	wxString name = file.AfterLast('/').AfterLast('\\').BeforeLast('.') ;
	wxString seq , desc ;
	
	// Items
	a = 12 ;
	while ( t[a+2] == 0 && t[2+3] == 0 )
	{
		unsigned char a1 = t[a] ;
		unsigned char a2 = t[a+1] ;
		if ( a1 == 255 && a2 == 255 ) a = scan_item ( t , a , v ) ;
		else
		{
			a += 8 ;
		}
	}
	
	// Sequence
	while ( t[a] >= 65 ) seq += t[a++] ;
	
	// Rest
	for ( a = l - 1 ; t[a-1] || t[a-2] ; a-- ) ;
	for ( ; a < l ; a++ )
	{
		if ( t[a] == 10 ) continue ;
		if ( t[a] == 13 || t[a] == 0 ) desc += '\n' ;
		else desc += t[a] ;
	}

	// Set vector
	v->setName ( name ) ;
	v->setSequence ( seq ) ;
	v->setDescription ( desc ) ;
	if ( seq.length() > 3000 ) v->setCircular () ; // Guessing
	
	_v.push_back ( v ) ;
	_success = true ;
	delete t ;
}

int TCloneManager::countVectors ()
{
	return _v.size() ;
}

TVector *TCloneManager::getVector ( int a )
{
	return _v[a] ;
}