From 81e46a5f473a0c4fc48b91c21d90f12251f918ae Mon Sep 17 00:00:00 2001 From: sol Date: Fri, 17 Jul 2015 17:13:04 -0400 Subject: [PATCH] fix for a numerical overflow error with the enumerate command the issue was that for loci with more possible isoforms than can be represented by an integer variable the count would overflow before making the comparison with the user specified max_isoforms parameter. To fix this I replaced the counter with a BigInteger, which won't overflow. --- IsoSCM/src/splicegraph/ExonSpliceGraph.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/IsoSCM/src/splicegraph/ExonSpliceGraph.java b/IsoSCM/src/splicegraph/ExonSpliceGraph.java index 975a766..922fb08 100644 --- a/IsoSCM/src/splicegraph/ExonSpliceGraph.java +++ b/IsoSCM/src/splicegraph/ExonSpliceGraph.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; +import java.math.BigInteger; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -301,7 +302,7 @@ public static void iterateSpliceIsoforms(File assembly_gtf, GTFWriter isoform_gt Set skipped_ids = new HashSet(); for(AnnotatedRegion r : exon_5p){ - if(max_paths == null || countPaths(r, exon_3p, sj5p) < max_paths){ + if(max_paths == null || countPaths(r, exon_3p, sj5p).compareTo(new BigInteger(String.format("%d", max_paths))) < 0){ Stack isoform_exons = new Stack(); iterateIsoforms(isoform_count, isoform_exons, r, exon_3p, sj5p, isoform_gtf); } @@ -372,21 +373,22 @@ public static List listChildren(AnnotatedRegion r, StrandedGeno return children; } - public static Integer countPaths(AnnotatedRegion r, StrandedGenomicIntervalTree> exon_3p, StrandedGenomicIntervalTree> sj5p){ + public static BigInteger countPaths(AnnotatedRegion r, StrandedGenomicIntervalTree> exon_3p, StrandedGenomicIntervalTree> sj5p){ String path_att = "nPaths"; - Integer nPaths = (Integer) r.getAttribute(path_att); + BigInteger nPaths = (BigInteger) r.getAttribute(path_att); if(nPaths==null){ List children = listChildren(r, exon_3p, sj5p); if(children.size()==0){ - nPaths=1; + nPaths=new BigInteger("1"); } else{ - nPaths = 0; + nPaths = new BigInteger("0"); for(AnnotatedRegion c : children){ - nPaths += countPaths(c, exon_3p, sj5p); + nPaths = nPaths.add(countPaths(c, exon_3p, sj5p)); +// nPaths += countPaths(c, exon_3p, sj5p); } } @@ -420,7 +422,7 @@ public static void countSpliceIsoforms(File assembly_gtf) throws FileNotFoundExc } for(AnnotatedRegion r : exon_5p){ - int n = countPaths(r,exon_3p,sj5p); + int n = countPaths(r,exon_3p,sj5p).intValue(); System.out.printf("e5p %s %d\n", r,n); } }