Skip to content

Commit c1a9f76

Browse files
committed
Bugfix for lofreq vcf merge
1 parent 714f1a5 commit c1a9f76

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/analysis/MergeLoFreqVcfHandler.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import htsjdk.variant.vcf.VCFFileReader;
1212
import org.apache.commons.lang3.StringUtils;
1313
import org.apache.commons.lang3.tuple.Pair;
14+
import org.apache.log4j.Logger;
1415
import org.json.JSONObject;
1516
import org.labkey.api.module.ModuleLoader;
1617
import org.labkey.api.pipeline.PipelineJob;
@@ -142,7 +143,7 @@ public void doFinalize()
142143
if (_encounteredAlleles.keySet().size() == 1)
143144
{
144145
_ref = _encounteredAlleles.keySet().iterator().next();
145-
_alternates = new ArrayList<>(_encounteredAlleles.get(_ref));
146+
_alternates = Collections.unmodifiableList(_encounteredAlleles.get(_ref));
146147
_renamedAlleles = Collections.emptyMap();
147148

148149
return;
@@ -186,13 +187,26 @@ public void doFinalize()
186187
_renamedAlleles.put(ref, alleleMap);
187188
}
188189
}
189-
_alternates = finalAlleles;
190+
_alternates = Collections.unmodifiableList(finalAlleles);
190191
}
191192

192193
public boolean isMergedRef()
193194
{
194195
return _encounteredAlleles.size() > 1;
195196
}
197+
198+
public void checkValid(Logger log)
199+
{
200+
if (_alternates.isEmpty())
201+
{
202+
log.error("No alternate alleles found: " + _contig + "/" + _start + "/" + _ref);
203+
_encounteredAlleles.forEach((a, b) -> {
204+
log.error(a.getBaseString() + ": " + b.stream().map(Allele::getBaseString).collect(Collectors.joining(",")));
205+
});
206+
207+
throw new IllegalArgumentException("No alternate alleles found: " + _contig + "/" + _start + "/" + _ref);
208+
}
209+
}
196210
}
197211

198212
@Override
@@ -255,16 +269,7 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
255269

256270
siteToAllele.forEach((x, y) -> {
257271
y.doFinalize();
258-
259-
if (y._alternates.isEmpty())
260-
{
261-
ctx.getLogger().error("No alternate alleles found: " + y._contig + "/" + y._start + "/" + y._ref);
262-
y._encounteredAlleles.forEach((a, b) -> {
263-
ctx.getLogger().error(a.getBaseString() + ": " + b.stream().map(Allele::getBaseString).collect(Collectors.joining(",")));
264-
});
265-
266-
throw new IllegalArgumentException("No alternate alleles found: " + y._contig + "/" + y._start + "/" + y._ref);
267-
}
272+
y.checkValid(ctx.getLogger());
268273
});
269274

270275
ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenome(genomeIds.iterator().next());
@@ -300,7 +305,7 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
300305
line.add(String.valueOf(site.getRight() + siteDef._ref.length() - 1));
301306

302307
line.add(siteDef._ref.getBaseString());
303-
line.add(siteDef._alternates.stream().map(Allele::getBaseString).skip(1).collect(Collectors.joining(";")));
308+
line.add(siteDef._alternates.stream().map(Allele::getBaseString).collect(Collectors.joining(";")));
304309

305310
if (!it.hasNext())
306311
{
@@ -336,9 +341,15 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
336341
while (it.hasNext())
337342
{
338343
VariantContext vc = it.next();
339-
if (vc.getStart() != siteDef._start)
344+
345+
//This could occur with a deletion from the prior position
346+
if (vc.getStart() < siteDef._start)
347+
{
348+
ctx.getLogger().info("Variant start less than site def, probably indicates an upstream deletion: " + siteDef._start + " / " + vc.getStart() + " / " + so.getFile().getPath());
349+
}
350+
else if (vc.getStart() > siteDef._start)
340351
{
341-
throw new PipelineJobException("Iterating incorrect start: " + siteDef._start + " / " + vc.getStart() + " / " + so.getFile().getPath());
352+
throw new PipelineJobException("Unexpected variant start. site: " + siteDef._start + " / vc: " + vc.getStart() + " / " + so.getFile().getPath());
342353
}
343354

344355
refs.add(vc.getReference());

0 commit comments

Comments
 (0)