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
|
/*
* Copyright (c) Medical Research Council 2001. All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose is hereby granted without fee, provided that
* this copyright and notice appears in all copies.
*
* This file was written as part of the Staden Package at the MRC Laboratory
* of Molecular Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
*
* MRC disclaims all warranties with regard to this software.
*
*/
#include <cassert>
#include <array.hpp>
#include <trace.hpp>
#include <align.hpp>
void TraceAlignInterpolate( char cPad, SimpleArray<char>& Envelope, Trace& Tin, int nClipL, Trace& Tout )
{
/*
This routine copies the input trace amplitudes to the output trace, interpolating
where indicated by pads in the envelope alignment sequence. Only the region of the
trace Tin from n1 to the length of the aligned sequence is copied to Tout.
*/
assert(Envelope.Length()==Tout.Samples());
int d, s, k, p, x;
double m[4];
int c[4];
// Any initial padding is copied over with a trace amplitude of zero
for( d=0; (d<Envelope.Length())&&(Envelope[d]==cPad); d++ )
{
Tout[0][d] = 0;
Tout[1][d] = 0;
Tout[2][d] = 0;
Tout[3][d] = 0;
}
// Copy and interpolate
for( d=d, s=nClipL; d<Envelope.Length(); d++ )
{
// If current character is a pad
if( Envelope[d] == cPad )
{
// Determine pad run length
for( k=d; (k<Envelope.Length())&&(Envelope[k]==cPad); k++ );
p = k - d;
// Determine equation of line y=mx+c parameters
// Slope = (LastNonPad - FirstNonPad) / (Pads+1)
c[0] = int(Tin[0][s-1]);
c[1] = int(Tin[1][s-1]);
c[2] = int(Tin[2][s-1]);
c[3] = int(Tin[3][s-1]);
m[0] = double(int(Tin[0][s]) - int(Tin[0][s-1])) / double(p+1);
m[1] = double(int(Tin[1][s]) - int(Tin[1][s-1])) / double(p+1);
m[2] = double(int(Tin[2][s]) - int(Tin[2][s-1])) / double(p+1);
m[3] = double(int(Tin[3][s]) - int(Tin[3][s-1])) / double(p+1);
// Do linear interpolation over padded region
for( x=1; x<=p; x++ )
{
Tout[0][d+(x-1)] = TRACE( m[0]*x + c[0] );
Tout[1][d+(x-1)] = TRACE( m[1]*x + c[1] );
Tout[2][d+(x-1)] = TRACE( m[2]*x + c[2] );
Tout[3][d+(x-1)] = TRACE( m[3]*x + c[3] );
}
d += p - 1;
}
else
{
// Just copy over values
Tout[0][d] = Tin[0][s];
Tout[1][d] = Tin[1][s];
Tout[2][d] = Tin[2][s];
Tout[3][d] = Tin[3][s];
s++;
}
}
Tout.Raw()->maxTraceVal = Tin.Raw()->maxTraceVal;
}
void TraceAlignInsertBases( char cPad, SimpleArray<char>& Envelope, Trace& Tin, Trace& Tout, int nOverlap[2] )
{
/*
Adds the base calls and base positions from 'Tin' into 'Tout' taking into
account the alignment.
*/
// Initialisation
int d;
int s;
int nOrigSamples;
int nOverlapL = nOverlap[0];
int nOverlapR = nOverlap[1];
int nBases = Tin.Raw()->NBases;
char* pSrcBase = Tin.Raw()->base;
char* pDstBase = Tout.Raw()->base;
uint_2* pSrcBasePos = Tin.Raw()->basePos;
uint_2* pDstBasePos = Tout.Raw()->basePos;
uint_2 nBasePos = 0;
// Skip over any initial padding
while( Envelope[nBasePos] == cPad )
nBasePos++;
// Insert bases
for( s=nOverlapL, d=0; s<=nOverlapR && s+1<nBases; s++, d++ )
{
pDstBase[d] = pSrcBase[s];
pDstBasePos[d] = nBasePos;
nOrigSamples = pSrcBasePos[s+1] - pSrcBasePos[s];
if( s < nOverlapR )
{
// Verify bases are not out of order, they can overlap!
assert(nOrigSamples>=0);
// Increment sample count, taking into account padding samples
while( nOrigSamples-- )
{
while( Envelope[nBasePos] == cPad )
nBasePos++;
nBasePos++;
}
}
}
}
|