X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fgff%2FGffHelperBase.java;h=2206a03a9bbcc0292f812cc0fb3fc04cbbfe302a;hb=refs%2Fheads%2Ffeature%2FJAL-3251biotypedMappings;hp=6d9327b1c2efceed07d93f9cac1dacce2ecf5899;hpb=ac599db2d506591153433ffbf1e6ea2ef4be4943;p=jalview.git diff --git a/src/jalview/io/gff/GffHelperBase.java b/src/jalview/io/gff/GffHelperBase.java index 6d9327b..2206a03 100644 --- a/src/jalview/io/gff/GffHelperBase.java +++ b/src/jalview/io/gff/GffHelperBase.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io.gff; import jalview.analysis.SequenceIdMatcher; @@ -68,15 +88,15 @@ public abstract class GffHelperBase implements GffHelperI int[] to = new int[] { toStart, toEnd }; /* - * Jalview always models from dna to protein, so switch values if the - * GFF mapping is from protein to dna + * Jalview always models from dna to protein, so invert + * mapping if the GFF mapping is from protein to dna */ - if (mappingType == MappingType.PeptideToNucleotide) + if (MappingType.isPeptideToDna(mappingType)) { int[] temp = from; from = to; to = temp; - mappingType = mappingType.getInverse(); + mappingType = MappingType.CdsToPeptide; } int fromRatio = mappingType.getFromRatio(); @@ -130,8 +150,8 @@ public abstract class GffHelperBase implements GffHelperI * restrict from range to make them match up * it's kind of arbitrary which end we truncate - here it is the end */ - System.err.print("Truncating mapping from " + Arrays.toString(from) - + " to "); + System.err.print( + "Truncating mapping from " + Arrays.toString(from) + " to "); if (from[1] > from[0]) { from[1] -= fromOverlap / toRatio; @@ -149,8 +169,8 @@ public abstract class GffHelperBase implements GffHelperI /* * restrict to range to make them match up */ - System.err.print("Truncating mapping to " + Arrays.toString(to) - + " to "); + System.err.print( + "Truncating mapping to " + Arrays.toString(to) + " to "); if (to[1] > to[0]) { to[1] -= fromOverlap / fromRatio; @@ -241,7 +261,8 @@ public abstract class GffHelperBase implements GffHelperI /** * Parses the input line to a map of name / value(s) pairs. For example the * line
- * Notes=Fe-S;Method=manual curation, prediction; source = Pfam; Notes = Metal
+ * Notes=Fe-S;Method=manual curation, prediction; source = Pfam; Notes = Metal + *
* if parsed with delimiter=";" and separators {' ', '='}
* would return a map with { Notes={Fe=S, Metal}, Method={manual curation, * prediction}, source={Pfam}}
@@ -265,7 +286,7 @@ public abstract class GffHelperBase implements GffHelperI String namesDelimiter, char nameValueSeparator, String valuesDelimiter) { - Map> map = new HashMap>(); + Map> map = new HashMap<>(); if (text == null || text.trim().length() == 0) { return map; @@ -293,7 +314,7 @@ public abstract class GffHelperBase implements GffHelperI List vals = map.get(key); if (vals == null) { - vals = new ArrayList(); + vals = new ArrayList<>(); map.put(key, vals); } for (String val : values.split(valuesDelimiter)) @@ -317,24 +338,44 @@ public abstract class GffHelperBase implements GffHelperI protected SequenceFeature buildSequenceFeature(String[] gff, Map> attributes) { + return buildSequenceFeature(gff, TYPE_COL, gff[SOURCE_COL], attributes); + } + + /** + * @param gff + * @param typeColumn + * @param group + * @param attributes + * @return + */ + protected SequenceFeature buildSequenceFeature(String[] gff, + int typeColumn, String group, Map> attributes) + { try { int start = Integer.parseInt(gff[START_COL]); int end = Integer.parseInt(gff[END_COL]); - float score = Float.NaN; + + /* + * default 'score' is 0 rather than Float.NaN as the latter currently + * disables the 'graduated colour => colour by label' option + */ + float score = 0f; try { score = Float.parseFloat(gff[SCORE_COL]); } catch (NumberFormatException nfe) { - // e.g. '.' - leave as NaN to indicate no score + // e.g. '.' - leave as zero } - SequenceFeature sf = new SequenceFeature(gff[TYPE_COL], - gff[SOURCE_COL], start, end, score, gff[SOURCE_COL]); + SequenceFeature sf = new SequenceFeature(gff[typeColumn], + gff[SOURCE_COL], start, end, score, group); sf.setStrand(gff[STRAND_COL]); + sf.setPhase(gff[PHASE_COL]); + if (attributes != null) { /* @@ -348,8 +389,8 @@ public abstract class GffHelperBase implements GffHelperI */ for (Entry> attr : attributes.entrySet()) { - String values = StringUtils.listToDelimitedString( - attr.getValue(), "; "); + String values = StringUtils.listToDelimitedString(attr.getValue(), + ","); sf.setValue(attr.getKey(), values); if (NOTE.equals(attr.getKey())) { @@ -385,7 +426,8 @@ public abstract class GffHelperBase implements GffHelperI * @param toSeq * @return */ - protected AlignedCodonFrame getMapping(AlignmentI align, SequenceI fromSeq, SequenceI toSeq) + protected AlignedCodonFrame getMapping(AlignmentI align, + SequenceI fromSeq, SequenceI toSeq) { AlignedCodonFrame acf = align.getMapping(fromSeq, toSeq); if (acf == null)