40

Aligning seqeunces with W-curve and SQL

Embed Size (px)

DESCRIPTION

The W-curve converts DNA character sequences to 3D geometry. This geometry can be stored in PostGIS and queried to perform fuzzy matching on the sequences. The alignments can be multi-pass to handle sub-sequences.

Citation preview

Page 1: Aligning seqeunces with W-curve and SQL
Page 2: Aligning seqeunces with W-curve and SQL

Standard tools analyze strings

● Blast, Fasta, and ClustalW combine strings with probability tables to compare sequences.– Assume that all differences are significant.

● This works well enough in most cases: Fly, chimp, and human genomes are easily comparable.

● Clustal­omega adds HMM to the mix.– Does a better job keeping sequences compact.

● Catch: They don't handle messy DNA.

Page 3: Aligning seqeunces with W-curve and SQL

“Messy” sequences● Several classes of important problems 

break the string­based approaches:– Sequences which break probability tables.– Large indels.– Crossovers, inversions, and CNV's.– Discontinuous epitopes.– Microbiome studies with many source 

mappings.

● These break  basic assumptions required for character­string comparisons.

Page 4: Aligning seqeunces with W-curve and SQL

Example: Cancer and CNV's

● At a smaller scale, CNV's look like crossovers.– Shotgun sequencing gets partial matches on 

multiple genes at the CNV boundary.

● Cancer is often messy.– Nature, radiation, or chemical insults leave 

the sequences scrambled.– Large indels or crossovers between 

chromosomes are common.

Page 5: Aligning seqeunces with W-curve and SQL

Dealing with HIV-1

● Non­correcting RNA virus: uniform rate of variation.– High rate of SNP's.– Also high rate of gaps.– Strains run from 8000+ to 10 000+ bases.

● Dual­strand package in viron:– Multi­strain crossovers are common.

Page 6: Aligning seqeunces with W-curve and SQL

Example: gp120 & CD4 Site

● Try this: Align HXB2's gp120 sequence its HXB2's genome using ClustalW2.– gp120 is ~1500 bases long.

– Alignment using ClustalW2 stretches the gene past 5000 bases.

● Now try to analyze the CD4 binding site.– 60+ bases spread across a 1500­base gene in 

7 groups of 6­12 bases each.– Clades based on gene use largely white noise.

Page 7: Aligning seqeunces with W-curve and SQL

CD4 binding site in gp120

Page 8: Aligning seqeunces with W-curve and SQL

Clades Based on gp120

Page 9: Aligning seqeunces with W-curve and SQL

Combined work cycle

● Part of the problem is combining stages.– Alignment and comparison happen in one 

step.

● Tools only compare full sequences rather than subsets.– Messy sequences require multi­stage 

alignment.– This doesn't work with partial matches 

required for crossovers, CNV's, or really large indels.

Page 10: Aligning seqeunces with W-curve and SQL

Alignments with the W-curve

● The W­curve was originally developed for visual analysis of long sequences.

● Later adapted to computed alignments.● The process converts DNA strings to 3D 

geometry.– Local state gives more detail for analysis than 

character strings.– Comparing geometry produces alignments.

Page 11: Aligning seqeunces with W-curve and SQL

Mapping DNA to Geometry● Geometry is produced from DNA sequence.● Successive points move halfway to the corner 

associated with a DNA base.

Page 12: Aligning seqeunces with W-curve and SQL

Example:“CG”● First point 

is halfway from origin to (0,­1).

● Second point is halfway to (­1,0).

Page 13: Aligning seqeunces with W-curve and SQL

Important Properties

● The W­curve balances variation and convergence.● Curves vary locally due to differences in sequence 

that produce them.● SNP's changes the surrounding curve.● After the sequences converge, so do the curves.● This leaves a few bases of differences after a SNP 

or GAP.

Page 14: Aligning seqeunces with W-curve and SQL

Convergence aftera SNP● Blue & 

Green curves converge within a few bases of the SNP at base 3.

Page 15: Aligning seqeunces with W-curve and SQL

Global view: Wild, D-R HIV-1 POL

Page 16: Aligning seqeunces with W-curve and SQL

Local view: Wild, D-R HIV-1 POL

Page 17: Aligning seqeunces with W-curve and SQL

SQL & Alignments

● This approach is for alignment only.– Sub­sequences can be aligned in a second 

pass.– Produces clades based on clinically 

significant subsets of the sequence. 

● While this can be done manually with Clustal, the W­curve can automate the cycle.– Final alignments can be further processed for 

scoring by any available method.

Page 18: Aligning seqeunces with W-curve and SQL

Storing Geometry

● The internals of most “geocoding” rely on geometric extensions to SQL. 

● The standard is called “GIS”, implemented as “PostGIS” with the Postgres database.

● This allows storing W­curves in a database and querying them.– Global convergence allows for comparison.– Fuzzy matching deals with variation.

Page 19: Aligning seqeunces with W-curve and SQL

W-curve & GIS

● Due to SNP's and gaps, we need some way to make a fuzzy comparison of the curves.

● Our current approach uses simple geometry to analyze the distances.– Template and sample vertexes are queried by 

geometry.– Ultimately, the approach permits multiple 

ways to store and query the curves.

Page 20: Aligning seqeunces with W-curve and SQL

Fixed templates, fuzzy samples

● We have many, often long templates.● There is one sample, which is often short.● Solution: Attach “fuzzyness” to the 

sample:– Store template vertexes as points.– Store samples as circles or polygons.– Ask which template points are within the 

sample circles.

Page 21: Aligning seqeunces with W-curve and SQL

Fuzzy Matching

Page 22: Aligning seqeunces with W-curve and SQL

Query output: ID, base, offset

● Select uses 'within' lookup on X­Y plane.– Extracts template sequence ID and Z­axis (base no).– Computes the difference of sample and template base 

numbers (“offset”).

● Results are sorted by ID, offset, and template base.– Sequences of adjacent template base numbers with the 

same offset are alignments.– No need for the sample bases since they can be re­

computed from template base + offset.

Page 23: Aligning seqeunces with W-curve and SQL

SQL for extraction is readable

● Only three values are required from the initial query.

● From two tables.

● Where the fuzzy vertex contains the fixed one.

select b.seq_id, b.base_no, a.base – b.base as 'delta',from fuzzy a, fixed bwhere st_contains ( a.vertex, b.vertex )order by b.seq_id, b.delta, b.base_no;

Page 24: Aligning seqeunces with W-curve and SQL

Query result: “chunks”

● Runs of template base numbers are collapsed into “chunks” of alignment.– [ SeqID, Start, Stop, Offset ] describe the alignment.– Process makes allowances for small (<7 b.p.) gaps.

● Amenable to parallel processing:– Database nodes perform “within” query.– Summarized into chunks.– Gathered for final processing.

Page 25: Aligning seqeunces with W-curve and SQL

Post-processing chunks

● Sort by:

start base + offset ascending.

stop base  + offset descending

● Chunks are ordered along the sample, longest to shortest.

● Now the chunks can be filtered depending on their source and expected use.

Page 26: Aligning seqeunces with W-curve and SQL

Filtering the Chunks

● Short reads, crossovers, CNV's, tag searches will all present different patterns in the chunks.– Short reads look for start­to­end matches.

– Crossovers are tiled end­to­end matches from different sequences.

– CNV's have two sequences with a break in the offsets equal to the CNV size.

– Tags show up as multiple matches of the same length from multiple templates.

– Inversions match a reversed copy of the sasmple.

Page 27: Aligning seqeunces with W-curve and SQL

Crossovers: Adjacent Chunks● Crossovers will have two chunks from 

different sequences.● Whatever their offsets, the two chunks 

add up to the full sample's length with minimal gap or overlap.

Page 28: Aligning seqeunces with W-curve and SQL

Example: crossover gp120

● Sequences with adjacent bases and the same offset. 

...1 6880 +931 6881 +931 6882 +93 ... 1 7665 +93 ...2 6307 -822 6308 -822 6310 -822 6311 -82 ... 2 7054 -82

Page 29: Aligning seqeunces with W-curve and SQL

Example: crossover gp120

● Sequences with adjacent bases and the same offset.

● Get collapsed into chunks.

[ 1 6880 7665 +93 ]

[ 2 6307 7054 -82 ]

Page 30: Aligning seqeunces with W-curve and SQL

Example: crossover gp120

● Sequences with adjacent bases and the same offset. 

● Get collapsed into chunks.

● Sort by sample bases from start+offset and stop + offset.

[ 2 6225 6972 -82 ][ 1 6973 7758 +93 ]

Page 31: Aligning seqeunces with W-curve and SQL

Example: crossover gp120

● Sequences with adjacent bases and the same offset. 

● Get collapsed into chunks.

● Sort by sample bases from start+offset and stop + offset.

● Result is a tiling of gp120: 6225 – 7758.

[ 2 6225 6972 -82 ][ 1 6973 7758 +93 ]

Page 32: Aligning seqeunces with W-curve and SQL

Working with short reads

● The previous example shows the bases on a known sequence, gp120.

● For short reads the sample base numbering will be 1..N.– Same basic results, with chunk start and 

stop from 1 .. N and large offsets.– Known sample bases simplify searches for 

tags or relative positions.

Page 33: Aligning seqeunces with W-curve and SQL

CNV's have a similar pattern

● Three chunks with A­B­A sequence.● Base offset in second block of A is the 

same size as the chunk between them.

Page 34: Aligning seqeunces with W-curve and SQL

Other filters

● Inversions can be detected by reversing the sample sequence.

● Copies of genes will show up as multiple sequences with full coverage.

Page 35: Aligning seqeunces with W-curve and SQL

Occam's Razor

● All of this is done with the simple arithmetic:– Numeric sort.

– Comparing integers to 1 or 7.

– Subtract base numbers.

– Adding offsets.

● This keeps the algorithm easy to program and validate.

Page 36: Aligning seqeunces with W-curve and SQL

Aligning sub-sequences

● Aligning sub­sequences simply reduces the chunk sizes.– Start with chunks that overlap the sub­sequence.– Generate new chunks with more restrictive start and 

stop values.– The sequence, and offset do not change.

● Again, nothing more than simple arithmetic is required for the sub­alignments.

Page 37: Aligning seqeunces with W-curve and SQL

Samples start extra-fuzzy

● The leading few bases of a sample are generated from (0,0,0).

● Template sequences begin at a point within the curve.

● This can be easily handled by using a slightly larger radius for the first few sample bases.

Page 38: Aligning seqeunces with W-curve and SQL

Indeterminate bases

● FASTQ data includes indeterminate bases and quality stores.– We can generate multiple points for a base.– These can be stored as “multipoint” in GIS.– Compared using a  convex hull or nearest­

neighbor to the template.– Explicit use of fuzzy math to combined with 

quality values?

Page 39: Aligning seqeunces with W-curve and SQL

Parallel processing

● Recursive algorithms in Blast, Fasta,  Clustal are not amenable to piecewise or parallel processing.

● The query used here is trivial to distribute across mulitple servers.

● Compressing rows into chunks is also suitable for multi­node processing.

● The cycle is suitable for parallel or cloud computing environments.

Page 40: Aligning seqeunces with W-curve and SQL

Summary

● Using a stand­alone alignment step is more flexible for messy DNA.

● The W­curve adds enough state to the DNA sequence that we can query nearby vertexes.

● A simple query and filtering allows us to query sequences for alignment, including post­processing for sub­sequence alignment.

● This is a tool for automating alignment of messy sequences.