private String getSequence(Location cdna) { DNASequence rawParent; if (!cdna.isComplex()) { try { rawParent = getRawParentSequence(cdna.getAccession().getID()); return cdna.getSubSequence(rawParent).getSequenceAsString(); } catch (IOException e) { // return null logger.error("Caught IOException when getting DNA sequence for id {}. Error: {}", cdna.getAccession().getID(), e.getMessage()); return null; } } else { // in case of complex StringBuilder sb = new StringBuilder(); for (Location sub : cdna.getSubLocations()) { String sebStr = getSequence(sub); sb.append((sebStr == null ? "" : sebStr)); } return sb.toString(); } }
private String getSequence(Location cdna) { DNASequence rawParent; if (!cdna.isComplex()) { try { rawParent = getRawParentSequence(cdna.getAccession().getID()); return cdna.getSubSequence(rawParent).getSequenceAsString(); } catch (IOException e) { // return null logger.error("Caught IOException when getting DNA sequence for id {}. Error: {}", cdna.getAccession().getID(), e.getMessage()); return null; } } else { // in case of complex StringBuilder sb = new StringBuilder(); for (Location sub : cdna.getSubLocations()) { String sebStr = getSequence(sub); sb.append((sebStr == null ? "" : sebStr)); } return sb.toString(); } }
/** * A protein sequence where the storage of the sequence is somewhere else * with user defined set of amino acids. Could be loaded from a large Fasta * file or via a Uniprot Proxy reader via Uniprot ID * * @param proxyLoader * @param compoundSet */ public ProteinSequence(ProxySequenceReader<AminoAcidCompound> proxyLoader, CompoundSet<AminoAcidCompound> compoundSet) { super(proxyLoader, compoundSet); // do protein-specific tasks // add source if found List<FeatureInterface<AbstractSequence<AminoAcidCompound>, AminoAcidCompound>> CDSFeatures = getFeaturesByType("CDS"); // cases if a protein has more than 1 parent are not supported yet if (CDSFeatures.size() == 1) { Qualifier codedBy = CDSFeatures.get(0).getQualifiers().get("coded_by").get(0); if (codedBy != null) { String codedBySeq = codedBy.getValue(); InsdcParser parser = new InsdcParser(DataSource.GENBANK); Location location = parser.parse(codedBySeq); try { DNASequence dnaSeq = new DNASequence(getSequence(location), DNACompoundSet.getDNACompoundSet()); setParentDNASequence(dnaSeq, location.getStart().getPosition(), location.getEnd().getPosition()); } catch (CompoundNotFoundException e) { // TODO is there another solution to handle this exception? logger.error("Could not add 'coded_by' parent DNA location feature, unrecognised compounds found in DNA sequence: {}", e.getMessage()); } } } }
/** * A protein sequence where the storage of the sequence is somewhere else * with user defined set of amino acids. Could be loaded from a large Fasta * file or via a Uniprot Proxy reader via Uniprot ID * * @param proxyLoader * @param compoundSet */ public ProteinSequence(ProxySequenceReader<AminoAcidCompound> proxyLoader, CompoundSet<AminoAcidCompound> compoundSet) { super(proxyLoader, compoundSet); // do protein-specific tasks // add source if found List<FeatureInterface<AbstractSequence<AminoAcidCompound>, AminoAcidCompound>> CDSFeatures = getFeaturesByType("CDS"); // cases if a protein has more than 1 parent are not supported yet if (CDSFeatures.size() == 1) { Qualifier codedBy = CDSFeatures.get(0).getQualifiers().get("coded_by").get(0); if (codedBy != null) { String codedBySeq = codedBy.getValue(); InsdcParser parser = new InsdcParser(DataSource.GENBANK); Location location = parser.parse(codedBySeq); try { DNASequence dnaSeq = new DNASequence(getSequence(location), DNACompoundSet.getDNACompoundSet()); setParentDNASequence(dnaSeq, location.getStart().getPosition(), location.getEnd().getPosition()); } catch (CompoundNotFoundException e) { // TODO is there another solution to handle this exception? logger.error("Could not add 'coded_by' parent DNA location feature, unrecognised compounds found in DNA sequence: {}", e.getMessage()); } } } }