Moved over to be a walker inside the GATK
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3313 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
78409dca0d
commit
0e58fb7cc0
|
|
@ -23,15 +23,18 @@
|
||||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.broadinstitute.sting.utils.tools;
|
package org.broadinstitute.sting.gatk.walkers;
|
||||||
|
|
||||||
import org.broadinstitute.sting.commandline.Argument;
|
import org.broadinstitute.sting.commandline.Argument;
|
||||||
import org.broadinstitute.sting.commandline.CommandLineProgram;
|
|
||||||
import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter;
|
import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter;
|
||||||
import org.broadinstitute.sting.utils.genotype.vcf.VCFReader;
|
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
||||||
|
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
||||||
|
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
|
||||||
import org.broad.tribble.vcf.VCFRecord;
|
import org.broad.tribble.vcf.VCFRecord;
|
||||||
|
import org.broad.tribble.vcf.VCFCodec;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.picard.liftover.LiftOver;
|
import net.sf.picard.liftover.LiftOver;
|
||||||
import net.sf.picard.util.Interval;
|
import net.sf.picard.util.Interval;
|
||||||
|
|
@ -41,19 +44,8 @@ import net.sf.samtools.SAMFileReader;
|
||||||
/**
|
/**
|
||||||
* Lifts a VCF file over from one build to another. Note that the resulting VCF could be mis-sorted.
|
* Lifts a VCF file over from one build to another. Note that the resulting VCF could be mis-sorted.
|
||||||
*/
|
*/
|
||||||
public class LiftoverVCF extends CommandLineProgram {
|
@Requires(value={},referenceMetaData=@RMD(name="vcf",type= VCFCodec.class))
|
||||||
|
public class LiftoverVCF extends RodWalker<Integer, Integer> {
|
||||||
public static void main(String args[]) {
|
|
||||||
LiftoverVCF LO = new LiftoverVCF();
|
|
||||||
CommandLineProgram.start( LO, args );
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Argument(fullName="vcf", shortName="vcf", doc="VCF file to lift over", required=true)
|
|
||||||
protected File VCF = null;
|
|
||||||
|
|
||||||
@Argument(fullName="out", shortName="out", doc="Output VCF file", required=true)
|
|
||||||
protected File OUT = null;
|
|
||||||
|
|
||||||
@Argument(fullName="chain", shortName="chain", doc="Chain file", required=true)
|
@Argument(fullName="chain", shortName="chain", doc="Chain file", required=true)
|
||||||
protected File CHAIN = null;
|
protected File CHAIN = null;
|
||||||
|
|
@ -61,41 +53,56 @@ public class LiftoverVCF extends CommandLineProgram {
|
||||||
@Argument(fullName="newSequenceDictionary", shortName="dict", doc="Sequence .dict file for the new build", required=true)
|
@Argument(fullName="newSequenceDictionary", shortName="dict", doc="Sequence .dict file for the new build", required=true)
|
||||||
protected File NEW_SEQ_DICT = null;
|
protected File NEW_SEQ_DICT = null;
|
||||||
|
|
||||||
@Override
|
private VCFWriter writer;
|
||||||
protected int execute() {
|
|
||||||
|
|
||||||
VCFReader reader = new VCFReader(VCF);
|
private LiftOver liftOver;
|
||||||
VCFWriter writer = new VCFWriter(OUT);
|
|
||||||
writer.writeHeader(reader.getHeader());
|
|
||||||
|
|
||||||
LiftOver liftOver = new LiftOver(CHAIN);
|
private long successfulIntervals = 0, failedIntervals = 0;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
liftOver = new LiftOver(CHAIN);
|
||||||
liftOver.setLiftOverMinMatch(LiftOver.DEFAULT_LIFTOVER_MINMATCH);
|
liftOver.setLiftOverMinMatch(LiftOver.DEFAULT_LIFTOVER_MINMATCH);
|
||||||
|
|
||||||
final SAMFileHeader toHeader = new SAMFileReader(NEW_SEQ_DICT).getFileHeader();
|
final SAMFileHeader toHeader = new SAMFileReader(NEW_SEQ_DICT).getFileHeader();
|
||||||
liftOver.validateToSequences(toHeader.getSequenceDictionary());
|
liftOver.validateToSequences(toHeader.getSequenceDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
long successfulIntervals = 0, failedIntervals = 0;
|
private void convertAndWrite(VCFRecord record) {
|
||||||
|
|
||||||
while ( reader.hasNext() ) {
|
final Interval fromInterval = new Interval(record.getChr(), record.getStart(), record.getEnd());
|
||||||
VCFRecord record = reader.next();
|
final Interval toInterval = liftOver.liftOver(fromInterval);
|
||||||
|
|
||||||
final Interval fromInterval = new Interval(record.getChr(), record.getStart(), record.getEnd());
|
if ( toInterval != null ) {
|
||||||
final Interval toInterval = liftOver.liftOver(fromInterval);
|
record.setLocation(toInterval.getSequence(), toInterval.getStart());
|
||||||
|
if ( writer == null ) {
|
||||||
if ( toInterval != null ) {
|
writer = new VCFWriter(out);
|
||||||
record.setLocation(toInterval.getSequence(), toInterval.getStart());
|
writer.writeHeader(record.getHeader());
|
||||||
writer.addRecord(record);
|
|
||||||
successfulIntervals++;
|
|
||||||
} else {
|
|
||||||
failedIntervals++;
|
|
||||||
}
|
}
|
||||||
|
writer.addRecord(record);
|
||||||
|
successfulIntervals++;
|
||||||
|
} else {
|
||||||
|
failedIntervals++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reader.close();
|
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
||||||
writer.close();
|
if ( tracker == null )
|
||||||
|
return 0;
|
||||||
|
|
||||||
System.out.println("Converted " + successfulIntervals + " intervals; failed to convert " + failedIntervals + " intervals.");
|
List<Object> rods = tracker.getReferenceMetaData("vcf");
|
||||||
|
|
||||||
|
for ( Object rod : rods )
|
||||||
|
convertAndWrite((VCFRecord)rod);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public Integer reduceInit() { return 0; }
|
||||||
|
|
||||||
|
public Integer reduce(Integer value, Integer sum) { return 0; }
|
||||||
|
|
||||||
|
public void onTraversalDone(Integer result) {
|
||||||
|
writer.close();
|
||||||
|
System.out.println("Converted " + successfulIntervals + " intervals; failed to convert " + failedIntervals + " intervals.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<package name="LiftoverVCF">
|
|
||||||
<executable name="LiftoverVCF">
|
|
||||||
<main-class name="org.broadinstitute.sting.utils.tools.LiftoverVCF" />
|
|
||||||
<resource-bundle file="StingText.properties" />
|
|
||||||
<dependencies>
|
|
||||||
</dependencies>
|
|
||||||
</executable>
|
|
||||||
</package>
|
|
||||||
Loading…
Reference in New Issue