-
- /**
- * Processes the 'Query' and 'Align' properties associated with a GFF
- * similarity feature; these properties define the mapping of the annotated
- * feature to another from which it has transferred annotation
- *
- * @param set
- * @param seq
- * @param sf
- * @return
- */
- public void processGffSimilarity(Map<String, List<String>> set, SequenceI seq,
- SequenceFeature sf, AlignmentI align, List<SequenceI> newseqs, boolean relaxedIdMatching)
- throws InvalidGFF3FieldException
- {
- int strand = sf.getStrand();
- // exonerate cdna/protein map
- // look for fields
- List<SequenceI> querySeq = findNames(align, newseqs, relaxedIdMatching,
- set.get("Query"));
- if (querySeq == null || querySeq.size() != 1)
- {
- throw new InvalidGFF3FieldException("Query", set,
- "Expecting exactly one sequence in Query field (got "
- + set.get("Query") + ")");
- }
- if (set.containsKey("Align"))
- {
- // process the align maps and create cdna/protein maps
- // ideally, the query sequences are in the alignment, but maybe not...
-
- AlignedCodonFrame alco = new AlignedCodonFrame();
- MapList codonmapping = constructCodonMappingFromAlign(set, "Align",
- strand);
-
- // add codon mapping, and hope!
- alco.addMap(seq, querySeq.get(0), codonmapping);
- align.addCodonFrame(alco);
- }
-
- }
-
- /**
- * take a sequence feature and examine its attributes to decide how it should
- * be added to a sequence
- *
- * @param seq
- * - the destination sequence constructed or discovered in the
- * current context
- * @param sf
- * - the base feature with ATTRIBUTES property containing any
- * additional attributes
- * @param gFFFile
- * - true if we are processing a GFF annotation file
- * @return true if sf was actually added to the sequence, false if it was
- * processed in another way
- */
- public boolean processOrAddSeqFeature(AlignmentI align, List<SequenceI> newseqs,
- SequenceI seq, SequenceFeature sf, boolean relaxedIdMatching)
- {
- String attr = (String) sf.getValue(ATTRIBUTES);
- boolean addFeature = true;
- if (attr != null)
- {
- for (String attset : attr.split(TAB))
- {
- Map<String, List<String>> set = StringUtils.parseNameValuePairs(
- attset, ";", new char[] { ' ', '-' });
-
- if ("similarity".equals(sf.getType()))
- {
- try
- {
- processGffSimilarity(set, seq, sf, align, newseqs,
- relaxedIdMatching);
- addFeature = false;
- } catch (InvalidGFF3FieldException ivfe)
- {
- System.err.println(ivfe);
- }
- }
- }
- }
- if (addFeature)
- {
- seq.addSequenceFeature(sf);
- }
- return addFeature;
- }
-
-}
-
-class InvalidGFF3FieldException extends Exception
-{
- String field, value;
-
- public InvalidGFF3FieldException(String field,
- Map<String, List<String>> set, String message)
- {
- super(message + " (Field was " + field + " and value was "
- + set.get(field).toString());
- this.field = field;
- this.value = set.get(field).toString();
- }