broadinstitute / pilon

Pilon is an automated genome assembly improvement and variant detection tool
GNU General Public License v2.0
340 stars 60 forks source link

VCF output exception "Can't fetch base outside region" #48

Closed pd3 closed 5 years ago

pd3 commented 7 years ago

I've encountered the same problem as described in https://github.com/broadinstitute/pilon/issues/4.

A test case to reproduce the problem can be downloaded from here ftp://ngs.sanger.ac.uk/scratch/project/team145/pd3/pilon-crash.tgz

Briefly, this is the command

 java -Xms8000m -Xmx8000m -jar pilon-1.22.jar --diploid --changes --vcf \
    --chunksize 1000000 --nostrays --genome ref.fa --frags test.bam  \
    --targets 000033F:1000001-1359045 --outdir out/ 2>&1 | tee out.log

and it ends with this exception

Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.simontuffs.onejar.Boot.run(Boot.java:340) at com.simontuffs.onejar.Boot.main(Boot.java:166) Caused by: java.lang.IllegalArgumentException: requirement failed: can't fetch base outside region at scala.Predef$.require(Predef.scala:224) at org.broadinstitute.pilon.GenomeRegion.refBase(GenomeRegion.scala:735) at org.broadinstitute.pilon.Vcf.writeRecord(Vcf.scala:94) at org.broadinstitute.pilon.GenomeRegion$$anonfun$writeVcf$1.apply$mcVI$sp(GenomeRegion.scala:592) at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:160) at org.broadinstitute.pilon.GenomeRegion.writeVcf(GenomeRegion.scala:577) at org.broadinstitute.pilon.GenomeFile$$anonfun$processRegions$5$$anonfun$apply$5.apply(GenomeFile.scala:151) at org.broadinstitute.pilon.GenomeFile$$anonfun$processRegions$5$$anonfun$apply$5.apply(GenomeFile.scala:148) at scala.collection.immutable.List.foreach(List.scala:381) at org.broadinstitute.pilon.GenomeFile$$anonfun$processRegions$5.apply(GenomeFile.scala:148) at org.broadinstitute.pilon.GenomeFile$$anonfun$processRegions$5.apply(GenomeFile.scala:141) at scala.collection.immutable.List.foreach(List.scala:381) at org.broadinstitute.pilon.GenomeFile.processRegions(GenomeFile.scala:141) at org.broadinstitute.pilon.Pilon$.main(Pilon.scala:101) at org.broadinstitute.pilon.Pilon.main(Pilon.scala) ... 6 more

w1bw commented 7 years ago

Belated thanks for making this reasonably-sized test case! I'll look into it as soon as I get a chance!

pd3 commented 7 years ago

For now I've been running pilon with this temporary fix

diff --git a/src/main/scala/org/broadinstitute/pilon/GenomeRegion.scala b/src/main/scala/org/broadinstitute/pilon/GenomeRegion.scala
index e1a00e5..05a9d16 100644
--- a/src/main/scala/org/broadinstitute/pilon/GenomeRegion.scala
+++ b/src/main/scala/org/broadinstitute/pilon/GenomeRegion.scala
@@ -732,9 +732,13 @@ class GenomeRegion(val contig: ReferenceSequence, start: Int, stop: Int)
   }

   def refBase(locus: Int) = {
-    require(inRegion(locus), "can't fetch base outside region")
-    //bases(index(locus)).toChar.toUpper
-    contigBases(locus - 1).toChar.toUpper
+    if ( !inRegion(locus) )
+    {
+        log("Warning: can't fetch base "+locus+", it is outside of the region: "+contig.getName+":"+start+"-"+stop+", replacing with N\n")
+        "N";
+    }
+    else
+        contigBases(locus - 1).toChar.toUpper
lijingbu commented 6 years ago

Same error message. But if remove the "--vcf" option, everything works. You can use other tools to generate vcf.