Skip to main content

checking whether a document is a nucleotide or amino acid sequence

Comments

3 comments

  • Sean Johnson

    I figured out a solution that seems to work. There may be better ways to do this, but what I'm doing now is just doing try-catch blocks around the cast operations.

    For example:

    try {
        inputAASequence = (AminoAcidSequenceDocument) documents[0].getDocument();
        doctype = "amino acid";
    }
    catch (Exception e){
            try {
                inputNtSequence = (NucleotideSequenceDocument) documents[0].getDocument();
                doctype = "nucleotide";
            }
            catch (Exception e){
                throw (new DocumentOperationException("Cannot determine the type of the input document"));
            }
    }
    0
  • Sean Johnson

    I found another way to do this. I presume that this way is actually the preferred way.

    if (DocumentType.isAminoAcidSequence(documents[0].getDocument())) {
        //do amino acid stuff
    }
    else if (DocumentType.isNucleotideSequence(documents[0].getDocument())) {
        //do nucleotide stuff
    }
    else {
        throw (new DocumentOperationException("Input document must either be a nucleotide sequence or an amino acid sequence."));
    }
    0
  • Richard Moir

    I can confirm you found the right way to do it :)

    0

Please sign in to leave a comment.