*/
public abstract class GffHelperBase implements GffHelperI
{
+ private static final String INVALID_GFF_ATTRIBUTE_FORMAT = "Invalid GFF attribute format: ";
+
protected static final String COMMA = ",";
protected static final String EQUALS = "=";
* @return
*/
protected SequenceFeature buildSequenceFeature(String[] gff,
- int typeColumn, String group, Map<String, List<String>> attributes)
+ int typeColumn, String group,
+ Map<String, List<String>> attributes)
{
try
{
{
Map<String, String> map = new HashMap<>();
String[] fields = s.split(EQUALS);
+
+ /*
+ * format validation
+ */
+ boolean valid = true;
+ if (fields.length < 2)
+ {
+ /*
+ * need at least A=B here
+ */
+ valid = false;
+ }
+ else if (fields[0].isEmpty() || fields[0].contains(COMMA))
+ {
+ /*
+ * A,B=C is not a valid start, nor is =C
+ */
+ valid = false;
+ }
+ else
+ {
+ for (int i = 1; i < fields.length - 1; i++)
+ {
+ if (fields[i].isEmpty() || !fields[i].contains(COMMA))
+ {
+ /*
+ * intermediate tokens must include value,name
+ */
+ valid = false;
+ }
+ }
+ }
+
+ if (!valid)
+ {
+ System.err.println(INVALID_GFF_ATTRIBUTE_FORMAT + s);
+ return map;
+ }
+
int i = 0;
while (i < fields.length - 1)
{
? before.substring(before.lastIndexOf(COMMA) + 1)
: before;
+ theKey = theKey.trim();
+ if (theKey.isEmpty())
+ {
+ System.err.println(INVALID_GFF_ATTRIBUTE_FORMAT + s);
+ map.clear();
+ return map;
+ }
+
/*
* if 'value' looks like a,b,c then all but the last token is the value,
* unless this is the last field (no more = to follow), in which case