Framework for generalized association testing. Heavy lifting done in implementation of the AssociationContext(s) and AssociationContextAtom(s). Nothing really implemented.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5306 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
chartl 2011-02-24 18:12:39 +00:00
parent 6db3210387
commit 292b421113
10 changed files with 360 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* @Author chartl
* @Date 2011-02-23
* A general context for windowed association
*/
public abstract class AssociationContext<X extends AssociationContextAtom> {
private Class<? extends AssociationContextAtom> clazz;
private List<X> window;
public AssociationContext( Class<X> zclaz ) {
window = new ArrayList<X>(getWindowSize());
clazz = zclaz;
}
public X map(MapExtender e) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassCastException {
return (X) clazz.getConstructor().newInstance(e);
}
public boolean filter(MapExtender m) { return true; }
public void reduce(X context) {
window.add(context);
}
public abstract int getWindowSize();
public abstract int slideByValue();
public boolean isFull() {
return window.size() >= getWindowSize();
}
public void slide() {
window = window.subList(slideByValue(),window.size());
}
}

View File

@ -0,0 +1,13 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
/**
* @Author chartl
* @Date 2011-02-23
* general class for calculating base data for generalized association tests
*/
public abstract class AssociationContextAtom {
public AssociationContextAtom(MapExtender e) {
}
}

View File

@ -0,0 +1,44 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import java.util.ArrayList;
import java.util.List;
import org.broadinstitute.sting.oneoffprojects.walkers.association.interfaces.*;
/**
* Created by IntelliJ IDEA.
* User: chartl
* Date: Feb 24, 2011
* Time: 11:48:26 AM
* To change this template use File | Settings | File Templates.
*/
public class AssociationTestRunner {
public static List<String> runTests(AssociationContext context) {
List<String> results = new ArrayList<String>();
if ( context.getClass().isInstance(TStatistic.class)) {
results.add(runStudentT(context));
}
if ( context.getClass().isInstance(ZStatistic.class)) {
results.add(runZ(context));
}
if ( context.getClass().isInstance(FisherExact.class) ) {
results.add(runFisherExact(context));
}
return results;
}
public static String runStudentT(AssociationContext context) {
return "Test not yet implemented";
}
public static String runZ(AssociationContext context) {
return "Test not yet implemented";
}
public static String runFisherExact(AssociationContext context) {
return "Test not yet implemented";
}
}

View File

@ -0,0 +1,52 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.contexts.StratifiedAlignmentContext;
import org.broadinstitute.sting.gatk.datasources.sample.Sample;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import java.util.Map;
/**
* @Author chartl
* @Date 2011-02-23
* Holds multiple map contexts for use in the regional association walker
*/
public class MapExtender {
private MapHolder previous = null;
private MapHolder current = null;
public MapExtender() {
// no need to do anything
}
public void set(MapHolder holder) {
previous = current;
current = holder;
}
public Map<Sample,StratifiedAlignmentContext> getPreviousContext() {
return previous.getContext();
}
public ReferenceContext getPreviousRef() {
return previous.getRef();
}
public RefMetaDataTracker getPreviousTracker() {
return previous.getTracker();
}
public Map<Sample,StratifiedAlignmentContext> getContext() {
return current.getContext();
}
public ReferenceContext getReferenceContext() {
return current.getRef();
}
public RefMetaDataTracker getTracker() {
return current.getTracker();
}
}

View File

@ -0,0 +1,33 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.contexts.StratifiedAlignmentContext;
import org.broadinstitute.sting.gatk.datasources.sample.Sample;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import java.util.Map;
public class MapHolder {
private RefMetaDataTracker tracker;
private ReferenceContext ref;
private Map<Sample, StratifiedAlignmentContext> alignments;
public MapHolder(RefMetaDataTracker t, ReferenceContext r, AlignmentContext a) {
tracker = t;
ref = r;
alignments = StratifiedAlignmentContext.splitContextBySample(a.getBasePileup());
}
public Map<Sample, StratifiedAlignmentContext> getContext() {
return alignments;
}
public ReferenceContext getRef() {
return ref;
}
public RefMetaDataTracker getTracker() {
return tracker;
}
}

View File

@ -0,0 +1,62 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import org.broadinstitute.sting.utils.GenomeLoc;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* @Author chartl
* @Date 2011-02-23
* A general context for windowed association
*/
public class RegionalAssociationHandler {
private MapExtender maps;
// todo -- the correct way to do this is via the PluginManager (a la VariantEval) but this is a QND implementation
private Set<AssociationContext> associations;
public RegionalAssociationHandler(Set<AssociationContext> contexts) {
maps = null;
associations = contexts;
}
public void updateExtender(MapHolder mapHolder) {
maps.set(mapHolder);
}
/**
* Once the instances are collected; run map-reduce
* @map: MapExtender --> A child of AssociationContextAtom
* @implementation: Indirect construction via newinstance
* @reduce: (List<AssociationContext>,AssociationContext) --> List<AssociationContextAtom>
* @implementation: just append
*/
public void runMapReduce() throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
for ( AssociationContext w : associations ) {
if ( w.filter(maps) ) {
w.reduce(w.map(maps));
}
}
}
/**
* For those AssociationContexts with full windows:
* 1) Run their associated test(s)
* 2) Slide the windows
*/
public List<String> runTests() {
List<String> testResults = new ArrayList<String>(associations.size());
for ( AssociationContext w : associations ) {
if ( w.isFull() ) {
testResults.addAll(AssociationTestRunner.runTests(w));
w.slide();
}
}
return testResults;
}
public GenomeLoc getLocation() {
return maps.getReferenceContext().getLocus();
}
}

View File

@ -0,0 +1,78 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association;
import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.Output;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
import org.broadinstitute.sting.gatk.walkers.TreeReducible;
import org.broadinstitute.sting.utils.exceptions.StingException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @Author chartl
* @Date 2011-02-23
* Generalized framework for regional (windowed) associations
*/
public class RegionalAssociationWalker extends LocusWalker<MapHolder, RegionalAssociationHandler> implements TreeReducible<RegionalAssociationHandler> {
@Argument(doc="foo",shortName="AT",fullName="associationType",required=false)
public String[] associationsToUse = null;
@Output
PrintStream out;
public RegionalAssociationHandler reduceInit() {
Set<AssociationContext> validAssociations = getAssociations();
RegionalAssociationHandler wac = new RegionalAssociationHandler(validAssociations);
return wac;
}
public MapHolder map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
return new MapHolder(tracker,ref,context);
}
public RegionalAssociationHandler reduce(MapHolder map, RegionalAssociationHandler rac) {
rac.updateExtender(map);
try {
rac.runMapReduce();
} catch (Exception e) {
throw new StingException("Error in map reduce",e);
}
List<String> testsHere = rac.runTests();
// todo -- really awful shitty formatting
out.printf("%s%n",rac.getLocation().toString());
for ( String s : testsHere ) {
out.printf("%s%n",s);
}
return rac;
}
private AssociationContext stringToAssociationContext(String s) {
return null;
}
private Set<AssociationContext> getAssociations() {
// todo -- this should use the package handler like variant eval
Set<AssociationContext> validAssociations = new HashSet<AssociationContext>();
for ( String s : associationsToUse ) {
validAssociations.add(stringToAssociationContext(s));
}
return validAssociations;
}
public RegionalAssociationHandler treeReduce(RegionalAssociationHandler left, RegionalAssociationHandler right) {
// for now be dumb; in future fix the fact that left-most intervals of a 16kb shard won't see the context from
// the right-most locus of the previous shard
return right;
}
public void onTraversalDone(RegionalAssociationHandler rac) {
// do nothing
}
}

View File

@ -0,0 +1,14 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association.interfaces;
/**
* Created by IntelliJ IDEA.
* User: chartl
* Date: Feb 24, 2011
* Time: 12:58:56 PM
* To change this template use File | Settings | File Templates.
*/
public interface FisherExact {
public abstract int[][] getCounts();
public abstract String[] getRowNames();
public abstract String[] getColNames();
}

View File

@ -0,0 +1,12 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association.interfaces;
/**
* Created by IntelliJ IDEA.
* User: chartl
* Date: Feb 24, 2011
* Time: 12:58:16 PM
* To change this template use File | Settings | File Templates.
*/
public interface TStatistic {
public abstract double getTStatistic();
}

View File

@ -0,0 +1,12 @@
package org.broadinstitute.sting.oneoffprojects.walkers.association.interfaces;
/**
* Created by IntelliJ IDEA.
* User: chartl
* Date: Feb 24, 2011
* Time: 12:58:38 PM
* To change this template use File | Settings | File Templates.
*/
public interface ZStatistic {
public abstract double getZStatistic();
}