org.jdom.IllegalDataException Java Examples

The following examples show how to use org.jdom.IllegalDataException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static void addSanitizedContent(final Element e, final String val) {
  try {
    e.addContent(val);
  } catch (final IllegalDataException ide) {
    LOGGER.warn("Unable to add content", ide);
    // Unless a better idea can be found, we need to replace all
    // unparseable characters with a space as a placeholder
    final StringBuffer newVal = new StringBuffer();
    for (int i = 0, len = val.length(); i < len; i++) {
      if (Verifier.isXMLCharacter(val.charAt(i))) {
        newVal.append(val.charAt(i));
      } else {
        newVal.append(' ');
      }
    }
    e.addContent(newVal.toString());
  }
}
 
Example #2
Source File: LikelihoodFunctions.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
static double ChiSqFromLogLik(double nullLogLik, double altLogLik){
    
    double chiSq = 2.0 * (nullLogLik - altLogLik);
    
    //chi sq distribution below cannot handle infinity values.
    //However we just give it the 
    if(chiSq == Double.POSITIVE_INFINITY){
        chiSq = Double.MAX_VALUE;
    }
    if(chiSq < 0){
        //sometimes the value is not really 0 but something in the order 10e-15,
        //probably due to floating point errors.
        //throws an exception if the negative value is far from 0
        if(chiSq < -0.00001){
            //This was done because Freerk encountered this error.
            System.err.println(Double.toString(chiSq));
            throw new IllegalDataException("ChiSq value is lower than 1.");
        }
        chiSq = 0.0;
    }
    return chiSq;

}
 
Example #3
Source File: IndividualSnpData.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public IndividualSnpData(String SAMPLENAME, String snpLine ){
    
    sampleName = SAMPLENAME;
    String[] values = snpLine.split("\t");
    
    if(values.length != 9){
        System.out.println(snpLine);
        throw new IllegalDataException("The SNP line printed above did not contain 9 elements.");
    }
    
    chromosome = values[0];
    position   = values[1];
    snpName    = values[2];
    
    reference    = values[3].charAt(0); 
    alternative  = values[4].charAt(0);
    
    refNum = Integer.parseInt(values[5]);
    altNum = Integer.parseInt(values[6]);
    noNum  = Integer.parseInt(values[7]);

    genotype = values[8];
}
 
Example #4
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the startPosition
 */
public int getStartPosition() {
    
    if(startPosition < 0){
        throw new IllegalDataException("startPosition was negative, is wrong.");
    }
    
    return startPosition;
}
 
Example #5
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param startPosition the startPosition to set
 */
public void setStartPosition(int startPosition) throws IllegalDataException {
    
    if(startPosition < 0){
        throw new IllegalDataException("startPosition cannot be negative");
    }
    
    this.startPosition = startPosition;
}
 
Example #6
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the endPosition
 */
public int getEndPosition() {
    
    if(endPosition < 0){
        throw new IllegalDataException("endPosition was negative, invalid value");
    }
    return endPosition;
}
 
Example #7
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param endPosition the endPosition to set
 */
public void setEndPosition(int endPosition) {
  
    if(endPosition < 0){
        throw new IllegalDataException("endPosition cannot be negative");
    }
    
    this.endPosition = endPosition;
}
 
Example #8
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the testStart
 */
public int getTestStart() {
    
    if(testStart < 0){
        throw new IllegalDataException("testStart was negative, is wrong.");
    }
    
    return testStart;
}
 
Example #9
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param testStart the testStart to set
 */
public void setTestStart(int testStart) throws IllegalDataException {
    
    if(testStart < 0){
        throw new IllegalDataException("startPosition cannot be negative");
    }
    
    this.testStart = testStart;
}
 
Example #10
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the testStart
 */
public int getTestEnd() {
    
    if(testEnd < 0){
        throw new IllegalDataException("testEnd was negative, is wrong.");
    }
    
    return testEnd;
}
 
Example #11
Source File: GenomicRegion.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param testEnd the testStart to set
 */
public void setTestEnd(int testEnd) throws IllegalDataException {
    
    if(testEnd < 0){
        throw new IllegalDataException("testEnd cannot be negative");
    }
    
    this.testEnd = testEnd;
}
 
Example #12
Source File: ReadAsLinesIntoIndividualSNPdata.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<IndividualSnpData> getIndividualsFromNextLine() throws IOException, IllegalDataException, IllegalArgumentException{
    
    ArrayList<String> allData = read_data_line();
     
    ArrayList<IndividualSnpData> theseSnps = UtilityMethods.parse_AS_lines(allData, all_files);
    
    if(theseSnps.isEmpty()){
        return theseSnps;
    }
    
    
    //Now do some checks to make sure everything is correct.
    String refSnpName    = theseSnps.get(0).getSnpName();
    String refChromosome = theseSnps.get(0).getChromosome();
    String refPosition   = theseSnps.get(0).getPosition();    
    for(IndividualSnpData iSnp: theseSnps){
        
        if(!refSnpName.equals(iSnp.getSnpName())){
            throw new IllegalDataException("refSnp was not the same across AS files");
        }
        if(!refChromosome.equals(iSnp.getChromosome())){
            throw new IllegalDataException("snp chromosome was not the same across AS files");
        }
        if(!refPosition.equals(iSnp.getPosition())){
            throw new IllegalDataException("snp position was not the same across AS files");
        }
    
    }
    
    //if no exceptions are thrown then everything is correct and we move on.
    return theseSnps;
}
 
Example #13
Source File: ReadAsLinesIntoIndividualSNPdata.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
private ArrayList<String> read_data_line() throws IOException, IllegalDataException {

        ArrayList<String> all_lines = new ArrayList<String>();
        
        //This for loop is also implicitly used to make sure there are no (partially) empty files. 
        for (BufferedReader iFile : all_file_readers) {

            String line = iFile.readLine();

            if (line != null) {
                all_lines.add(line);
            }
            
        }
        
        if(all_lines.isEmpty()){
            return new ArrayList<String>();
        } else if(all_lines.size() != all_file_readers.size()){
            throw new IllegalDataException("The AS files are of different length");
        }
        
        
        return all_lines;
    }
 
Example #14
Source File: ReadGenoAndAsFromIndividual.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public static String get_allele_specific_overlap_at_snp(GeneticVariant this_variant,
                                                        int sample_index, 
                                                        String chromosome,
                                                        String position, 
                                                        SamReader bam_file){
    
    int pos_int = Integer.parseInt(position);
    
    Alleles all_variants = this_variant.getVariantAlleles();
    Character ref_allele_char = all_variants.getAllelesAsChars()[0];
    String ref_allele = ref_allele_char.toString(); 
    //System.out.println("ref_allele: " + ref_allele);
    Character alt_allele_char = all_variants.getAllelesAsChars()[1];
    String alt_allele = alt_allele_char.toString(); 
    //System.out.println("alt_allele: " + alt_allele);
   
    
    
    int ref_overlap = 0;
    int alt_overlap = 0;
    int no__overlap = 0;
    
    

   
    // now determine per individual the sample variants.
    // I'm assuming the ordering is the same as the individual names created 
    // by the  getSampleNames() method. 
    // Otherwise the data will be nicely permuted, and I will have to convert some stuff.
    
    int position_of_snp = Integer.parseInt(position);                       
    
    //Check to make sure the variant position is not 0.
    if(position_of_snp <= 0){
        System.out.println("A SNP was read with a position lower than 1. This is illegal");
        System.out.println("Please adapt your genotype files by removing SNPs with these illegal positions");
        System.out.println("\tchr: " + chromosome + " pos: " + position);
        throw new IllegalDataException("Variant Position was less than 1");
    }
    
    SAMRecordIterator all_reads_in_region;
    try{
        all_reads_in_region = bam_file.queryOverlapping(chromosome, position_of_snp, position_of_snp);
    } catch(IllegalArgumentException e){
        System.out.println("Found an error when trying the following input:");
        System.out.println("chr:\t"+chromosome);
        System.out.println("pos:\t"+ position);
        System.out.println("If these values look correct, please make sure your bam file is sorted AND indexed by samtools.");
        System.out.println("If the problem persists, perhaps the chromosome (or sequence) are not the same in the genotype or bam file");
        all_reads_in_region = null;
        System.exit(0);
        
    }
    
    String bases = "";
    
    while(all_reads_in_region.hasNext()){
        
        SAMRecord read_in_region = all_reads_in_region.next();
        
        Character base_in_read = get_base_at_position(read_in_region, pos_int);
        if(GlobalVariables.verbosity >= 100){
            System.out.println("base_in_read: " + base_in_read);
        }
        
        if( base_in_read == ref_allele.charAt(0) ){
            ref_overlap++;            
        } else if(base_in_read == alt_allele.charAt(0) ){
            alt_overlap++;
        }else if(base_in_read == '!'  || base_in_read == 'N'){
            continue;
        }else{
            no__overlap++;
        }
    }
    
    //This line below cost me a day to figure out the error.
    all_reads_in_region.close();
    
    String string_for_output;
    string_for_output = Integer.toString(ref_overlap) + "\t" + 
                        Integer.toString(alt_overlap) + "\t" + 
                        Integer.toString(no__overlap);
    
    return(string_for_output);
}
 
Example #15
Source File: FindBamTranscribedRegions.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public FindBamTranscribedRegions(byte[] tabix_bytes) throws IllegalDataException{
    
    int iArray = 0;
    String magic;
    
    if( (tabix_bytes[0] != 'B') || 
        (tabix_bytes[1] != 'A') || 
        (tabix_bytes[2] != 'I') || 
        (tabix_bytes[3] != '\1')){
        throw new IllegalDataException("The tabix magic string did not start with the expected BAI\1 string");
    }
    iArray +=4;
    
    num_reference_sequences = decode32IntFromArray(tabix_bytes, iArray);
    iArray +=4;
    
    //Do for every chromosome (reference)
    for(int refs=0; refs < num_reference_sequences; refs++){
        
        int empty=0;
        int full=0;
        
        
        int nBinsThisRef = decode32IntFromArray(tabix_bytes, iArray);
        iArray+=4;
        
        boolean[] tempList = new boolean[37451];
        for(int n=0; n < 37451; n++){
            tempList[n] = false;
        }
        
        //do for every bin in the chromosome (reference)
        for(int refBins=0; refBins < nBinsThisRef; refBins++ ){
            //no need to do anything for the bin 37450, as it will be processed correctly.
           
            int bin = (int) decode32uIntFromArray(tabix_bytes, iArray);
            iArray +=4;
            
            int n_chunks = decode32IntFromArray(tabix_bytes, iArray);
            iArray +=4;
            
            byte[] startValue = Arrays.copyOfRange(tabix_bytes, iArray, iArray+8);
            byte[] endValue   = Arrays.copyOfRange(tabix_bytes, iArray + 16*(n_chunks-1), iArray + 16*(n_chunks-1)+ 8);
            iArray += 16*n_chunks;
            
            //if the bin is empty, show it.
            if(Arrays.equals(startValue,endValue)){
                tempList[bin] = true;
                empty++;
            }else{
                tempList[bin] = false;
                full++;
            }
            
        }
        
        int num_intervals = decode32IntFromArray(tabix_bytes, iArray);
        iArray+=4;
        iArray+= num_intervals*8;
        
        referenceList.add(tempList);
        
        //System.out.printf("If I'm correct. Sequence %d contains %d empty and %d full bins.\n", refs, empty, full );
    }
    
    
   
    
}
 
Example #16
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void exportResults(@Nonnull final CommonProblemDescriptor[] descriptors, @Nonnull RefEntity refEntity, @Nonnull Element parentNode) {
  for (CommonProblemDescriptor descriptor : descriptors) {
    @NonNls final String template = descriptor.getDescriptionTemplate();
    int line = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getLineNumber() : -1;
    final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null;
    @NonNls String problemText = StringUtil.replace(StringUtil.replace(template, "#ref", psiElement != null ? ProblemDescriptorUtil
            .extractHighlightedText(descriptor, psiElement) : ""), " #loc ", " ");

    Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
    if (element == null) return;
    @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
    problemClassElement.addContent(myToolWrapper.getDisplayName());
    if (refEntity instanceof RefElement){
      final RefElement refElement = (RefElement)refEntity;
      final HighlightSeverity severity = getSeverity(refElement);
      ProblemHighlightType problemHighlightType = descriptor instanceof ProblemDescriptor
                                                  ? ((ProblemDescriptor)descriptor).getHighlightType()
                                                  : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
      final String attributeKey = getTextAttributeKey(refElement.getRefManager().getProject(), severity, problemHighlightType);
      problemClassElement.setAttribute("severity", severity.myName);
      problemClassElement.setAttribute("attribute_key", attributeKey);
    }
    element.addContent(problemClassElement);
    if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
      final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper)myToolWrapper).getTool();
      final QuickFix[] fixes = descriptor.getFixes();
      if (fixes != null) {
        @NonNls Element hintsElement = new Element("hints");
        for (QuickFix fix : fixes) {
          final String hint = globalInspectionTool.getHint(fix);
          if (hint != null) {
            @NonNls Element hintElement = new Element("hint");
            hintElement.setAttribute("value", hint);
            hintsElement.addContent(hintElement);
          }
        }
        element.addContent(hintsElement);
      }
    }
    try {
      Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
      descriptionElement.addContent(problemText);
      element.addContent(descriptionElement);
    }
    catch (IllegalDataException e) {
      //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
      System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName());
    }
  }
}