private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds) throws IOException, DataSourceException, ServletException, DazzleException { DazzleReferenceSource drs = (DazzleReferenceSource) dds; List segments = DazzleTools.getSegments(dds, req, resp); if (segments.size() == 0) { throw new DazzleException( DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command"); } // Fetch and validate the requests. Map segmentResults = new HashMap(); for (Iterator i = segments.iterator(); i.hasNext(); ) { Segment seg = (Segment) i.next(); try { Sequence seq = drs.getSequence(seg.getReference()); if (seq.getAlphabet() != DNATools.getDNA()) { throw new DazzleException( DASStatus.STATUS_SERVER_ERROR, "Sequence " + seg.toString() + " is not in the DNA alphabet"); } if (seg.isBounded()) { if (seg.getMin() < 1 || seg.getMax() > seq.length()) { throw new DazzleException( DASStatus.STATUS_BAD_COORDS, "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length()); } } segmentResults.put(seg, seq); } catch (NoSuchElementException ex) { throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex); } catch (DataSourceException ex) { throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex); } } // // Looks okay -- generate the response document // XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd"); try { xw.openTag("DASDNA"); for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) { Map.Entry me = (Map.Entry) i.next(); Segment seg = (Segment) me.getKey(); Sequence seq = (Sequence) me.getValue(); xw.openTag("SEQUENCE"); xw.attribute("id", seg.getReference()); xw.attribute("version", drs.getLandmarkVersion(seg.getReference())); if (seg.isBounded()) { xw.attribute("start", "" + seg.getStart()); xw.attribute("stop", "" + seg.getStop()); } else { xw.attribute("start", "" + 1); xw.attribute("stop", "" + seq.length()); } SymbolList syms = seq; if (seg.isBounded()) { syms = syms.subList(seg.getMin(), seg.getMax()); } if (seg.isInverted()) { syms = DNATools.reverseComplement(syms); } xw.openTag("DNA"); xw.attribute("length", "" + syms.length()); for (int pos = 1; pos <= syms.length(); pos += 60) { int maxPos = Math.min(syms.length(), pos + 59); xw.println(syms.subStr(pos, maxPos)); } xw.closeTag("DNA"); xw.closeTag("SEQUENCE"); } xw.closeTag("DASDNA"); xw.close(); } catch (Exception ex) { throw new DazzleException(ex, "Error writing DNA document"); } }
/** * Returns the input subsequence matched by the previous match. * * <p>For a matcher m with input sequence s, the expressions m.group() and s.substring(m.start(), * m.end()) are equivalent. Note that some patterns, for example a*, match the empty SymbolList. * This method will return the empty string when the pattern successfully matches the empty string * in the input. * * @return The (possibly empty) subsequence matched by the previous match, in SymbolList form. */ public SymbolList group() { return sl.subList(start(), end() - 1); }
/** * Calculate the predicted properties of this polypeptide. * * @return a <code>PeptideProperties</code> object containing the predicted properties of this * polypeptide. */ public PeptideProperties calculateStats() { if (this.getResidues() == null) { logger.warn("No residues for '" + this.getUniqueName() + "'"); return null; } String residuesString = new String(this.getResidues()); SymbolList residuesSymbolList = null; PeptideProperties pp = new PeptideProperties(); try { SymbolTokenization proteinTokenization = ProteinTools.getTAlphabet().getTokenization("token"); residuesSymbolList = new SimpleSymbolList(proteinTokenization, residuesString); if (residuesSymbolList.length() == 0) { logger.error( String.format( "Polypeptide feature '%s' has zero-length residues", this.getUniqueName())); return pp; } try { // if the sequence ends with a termination symbol (*), we need to remove it if (residuesSymbolList.symbolAt(residuesSymbolList.length()) == ProteinTools.ter()) { if (residuesSymbolList.length() == 1) { logger.error( String.format( "Polypeptide feature '%s' only has termination symbol", this.getUniqueName())); return pp; } residuesSymbolList = residuesSymbolList.subList(1, residuesSymbolList.length() - 1); } } catch (IndexOutOfBoundsException exception) { throw new RuntimeException(exception); } } catch (BioException e) { logger.error("Can't translate into a protein sequence", e); return pp; } pp.setAminoAcids(residuesSymbolList.length()); try { double isoElectricPoint = new IsoelectricPointCalc().getPI(residuesSymbolList, false, false); pp.setIsoelectricPoint(isoElectricPoint); } catch (Exception e) { logger.error( String.format("Error computing protein isoelectric point for '%s'", residuesSymbolList), e); } double mass2 = calculateMass(residuesSymbolList); if (mass2 != -1) { // mass = mass2; pp.setMass(mass2); } double charge = calculateCharge(residuesString); pp.setCharge(charge); return pp; }
/** * Returns the input subsequence captured by the given group during the previous match operation. * * <p>For a matcher m, input sequence s, and group index g, the expressions m.group(g) and * s.substring(m.start(g), m.end(g)) are equivalent. Capturing groups are indexed from left to * right, starting at one. Group zero denotes the entire pattern, so the expression m.group(0) is * equivalent to m.group(). If the match was successful but the group specified failed to match * any part of the input sequence, then null is returned. Note that some groups, for example (a*), * match the empty string. This method will return the empty string when such a group successfully * matches the emtpy string in the input. * * @return The (possibly empty) subsequence captured by the group during the previous match, or * null if the group failed to match part of the input. */ public SymbolList group(int group) throws IndexOutOfBoundsException { int start = matcher.start(group); int end = matcher.end(group); if ((start == -1) && (end == -1)) return null; else return sl.subList(start(group), end(group) - 1); }