From 9e0407286fe32d01dfe4fea4d0bb6141f999f145 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 21 Nov 2014 08:56:52 +0000 Subject: [PATCH] JAL-1140 sensible name for seuqences in RNAML files that have no ID --- src/jalview/io/RnamlFile.java | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/jalview/io/RnamlFile.java b/src/jalview/io/RnamlFile.java index d366edc..9f0c8d5 100644 --- a/src/jalview/io/RnamlFile.java +++ b/src/jalview/io/RnamlFile.java @@ -20,12 +20,6 @@ */ package jalview.io; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; - import jalview.analysis.SecStrConsensus.SimpleBP; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -33,6 +27,14 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +import com.stevesoft.pat.Regex; + import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed; import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied; @@ -139,6 +141,14 @@ public class RnamlFile extends AlignFile int end = seq.length(); id = current.getName(); + if (id == null || id.trim().length() == 0) + { + id = safeName(getDataName()); + if (result.size() > 1) + { + id += "." + i; + } + } seqs[i] = new Sequence(id, seq, begin, end); seqs[i].setEnd(seqs[i].findPosition(seqs[i].getLength())); @@ -204,13 +214,18 @@ public class RnamlFile extends AlignFile private String safeName(String dataName) { int b = 0; - while ((b = dataName.indexOf("/")) > -1 && b < dataName.length()) + if ((b = dataName.lastIndexOf(".")) > 0) { - dataName = dataName.substring(b + 1).trim(); - + dataName = dataName.substring(0, b - 1); + } + b = 0; + Regex m = new Regex("[\\/]?([-A-Za-z0-9]+)\\.?"); + String mm = dataName; + while (m.searchFrom(dataName, b)) + { + mm = m.stringMatched(); + b = m.matchedTo(); } - int e = (dataName.length() - dataName.indexOf(".")) + 1; - dataName = dataName.substring(1, e).trim(); - return dataName; + return mm; } } -- 1.7.10.2