From 4567ee2f18f8c16ce6800ec7f888638bd4fe731a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 2 Oct 2017 18:52:23 +0100 Subject: [PATCH] JAL-2738 code tidy up, null checks &c --- src/jalview/io/vcf/VCFLoader.java | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/jalview/io/vcf/VCFLoader.java b/src/jalview/io/vcf/VCFLoader.java index 89b1d2a..8dab1d6 100644 --- a/src/jalview/io/vcf/VCFLoader.java +++ b/src/jalview/io/vcf/VCFLoader.java @@ -181,7 +181,7 @@ public class VCFLoader /* * note offset of CSQ ALLELE_NUM field if it is declared */ - findAlleleNumberFieldIndex(); + locateCsqFields(); // check if reference is wrt assembly19 (GRCh37) // todo may need to allow user to specify reference assembly? @@ -239,15 +239,20 @@ public class VCFLoader } /** - * If the CSQ INFO header declares that ALLELE_NUM is included in the data, - * record its (pipe-delimited) offset in each (comma-delimited) consequence - * block; CSQ fields are declared in the CSQ INFO Description e.g. + * Records the position of fields for ALLELE_NUM and Feature defined in the + * CSQ INFO header (if there is one). CSQ fields are declared in the CSQ INFO + * Description e.g. *

* Description="Consequence ...from ... VEP. Format: Allele|Consequence|... */ - protected void findAlleleNumberFieldIndex() + protected void locateCsqFields() { VCFInfoHeaderLine csqInfo = header.getInfoHeaderLine(CSQ); + if (csqInfo == null) + { + return; + } + String desc = csqInfo.getDescription(); if (desc != null) { @@ -303,7 +308,6 @@ public class VCFLoader /* * nucleotide-to-nucleotide mapping e.g. transcript to CDS */ - // TODO no DBRef to CDS is added to transcripts List features = seq.getFeatures() .getPositionalFeatures(SequenceOntologyI.SEQUENCE_VARIANT); for (SequenceFeature sf : features) @@ -689,8 +693,17 @@ public class VCFLoader * these may be per alternate allele (INFO[key].Number = 'A') * or per allele including reference (INFO[key].Number = 'R') */ - VCFHeaderLineCount number = header.getInfoHeaderLine(key) - .getCountType(); + VCFInfoHeaderLine infoHeader = header.getInfoHeaderLine(key); + if (infoHeader == null) + { + /* + * can't be sure what data belongs to this allele, so + * play safe and don't take any + */ + continue; + } + + VCFHeaderLineCount number = infoHeader.getCountType(); int index = altAlelleIndex; if (number == VCFHeaderLineCount.R) { -- 1.7.10.2