File: gnContigSpec.cpp

package info (click to toggle)
libgenome 1.3.1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,156 kB
  • ctags: 1,212
  • sloc: cpp: 10,910; sh: 8,264; makefile: 79
file content (77 lines) | stat: -rw-r--r-- 2,277 bytes parent folder | download | duplicates (8)
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
/////////////////////////////////////////////////////////////////////////////
// File:            gnContigSpec.cpp
// Purpose:         Abstract Contig Spec class
// Description:     Defines an interface for contig specs
// Changes:        
// Version:         libGenome 0.5.1 
// Author:          Aaron Darling 
// Modified by:     
// Copyright:       (c) Aaron Darling 
// Licenses:        See COPYING file for details
/////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "libGenome/gnContigSpec.h"
#include "libGenome/gnFilter.h"


using namespace std;
namespace genome {


void gnContigSpec::CropStart( gnSeqI cropLen ){
	m_start = m_reverseComplement ? (GetSourceLength() + m_start - cropLen) % GetSourceLength() : (m_start + cropLen) % GetSourceLength();
	m_length -= cropLen;
	return;
}

void gnContigSpec::CropEnd( gnSeqI cropLen ){
	m_length -= cropLen;
}

void gnContigSpec::SetReverseComplement( const boolean value )
{
	//translate coordinates if revComp has changed.
	if((m_reverseComplement != value) && (m_length > 0))
		m_start = (m_start + m_length) % GetSourceLength();
	m_reverseComplement = value;
}

boolean gnContigSpec::SeqRead(const gnSeqI start, gnSeqC* buf, gnSeqI& bufLen, const uint32 contigI ) const{
	boolean success;
	bufLen = bufLen < m_length - start? bufLen : m_length - start;	//trim the read down to size.
	gnSeqI readable = bufLen;
	gnSeqI read_start = start;	// coordinate translation

	if(contigI == ALL_CONTIGS)
		read_start = m_reverseComplement ? (m_start - start - readable + GetSourceLength()) % GetSourceLength() : start + m_start;

	success = Read(read_start, buf, readable);

	if(m_circular){
		gnSeqI beginread = bufLen - readable;  //read whatever couldn't be read before
		read_start = m_reverseComplement ? (m_start - readable + GetSourceLength()) % GetSourceLength() : m_start;
		success = Read(read_start , buf + readable, beginread);
		readable += beginread;
	}

	bufLen = readable;

	if(m_reverseComplement)
		gnFilter::DNAComplementFilter()->ReverseFilter(&buf, bufLen);

	return success;
}

void gnContigSpec::Clear(){
	gnBaseSpec::Clear();
	m_start = 0;
	m_length = 0;
	m_SourceContigIndex = ALL_CONTIGS;
}


}	// end namespace genome