- String seqId = "";
- while (st.hasMoreElements())
- {
-
- if (GFFFile)
- {
- // Still possible this is an old Jalview file,
- // which does not have type colours at the beginning
- seqId = token = st.nextToken();
- seq = findName(align, seqId, relaxedIdmatching, newseqs);
- if (seq != null)
- {
- desc = st.nextToken();
- String group = null;
- if (doGffSource && desc.indexOf(' ') == -1)
- {
- // could also be a source term rather than description line
- group = new String(desc);
- }
- theType = st.nextToken();
- try
- {
- String stt = st.nextToken();
- if (stt.length() == 0 || stt.equals("-"))
- {
- featureStart = 0;
- }
- else
- {
- featureStart = Integer.parseInt(stt);
- }
- } catch (NumberFormatException ex)
- {
- featureStart = 0;
- }
- try
- {
- String stt = st.nextToken();
- if (stt.length() == 0 || stt.equals("-"))
- {
- featureEnd = 0;
- }
- else
- {
- featureEnd = Integer.parseInt(stt);
- }
- } catch (NumberFormatException ex)
- {
- featureEnd = 0;
- }
- // TODO: decide if non positional feature assertion for input data
- // where end==0 is generally valid
- if (featureEnd == 0)
- {
- // treat as non-positional feature, regardless.
- featureStart = 0;
- }
- float score = 0f;
- try
- {
- score = new Float(st.nextToken()).floatValue();
- } catch (NumberFormatException ex)
- {
- // ignore
- }
-
- sf = new SequenceFeature(theType, desc, featureStart, featureEnd, score, group);
-
- try
- {
- sf.setValue("STRAND", st.nextToken());
- sf.setValue("FRAME", st.nextToken());
- } catch (Exception ex)
- {
- }
-
- if (st.hasMoreTokens())
- {
- StringBuilder attributes = new StringBuilder();
- boolean sep = false;
- while (st.hasMoreTokens())
- {
- attributes.append(sep ? "\t" : "").append(
- st.nextElement());
- sep = true;
- }
- // TODO validate and split GFF2 attributes field ? parse out
- // ([A-Za-z][A-Za-z0-9_]*) <value> ; and add as
- // sf.setValue(attrib, val);
- sf.setValue("ATTRIBUTES", attributes.toString());
- }
-
- if (processOrAddSeqFeature(align, newseqs, seq, sf, GFFFile,
- relaxedIdmatching))
- {
- // check whether we should add the sequence feature to any other
- // sequences in the alignment with the same or similar
- while ((seq = align.findName(seq, seqId, true)) != null)
- {
- seq.addSequenceFeature(new SequenceFeature(sf));
- }
- }
- break;
- }
- }
-
- if (GFFFile && seq == null)
- {
- desc = token;
- }
- else
- {
- desc = st.nextToken();
- }
- if (!st.hasMoreTokens())
- {
- System.err
- .println("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
- // in all probability, this isn't a file we understand, so bail
- // quietly.
- return false;
- }
-
- token = st.nextToken();
-
- if (!token.equals("ID_NOT_SPECIFIED"))
- {
- seq = findName(align, seqId = token, relaxedIdmatching, null);
- st.nextToken();
- }
- else
- {
- seqId = null;
- try
- {
- int idx = Integer.parseInt(st.nextToken());
- seq = align.getSequenceAt(idx);
- } catch (NumberFormatException ex)
- {
- seq = null;
- }
- }
-
- if (seq == null)
- {
- System.out.println("Sequence not found: " + line);
- break;
- }
-
- featureStart = Integer.parseInt(st.nextToken());
- featureEnd = Integer.parseInt(st.nextToken());
-
- theType = st.nextToken();
-
- if (!colours.containsKey(theType))
- {
- // Probably the old style groups file
- colours.put(
- theType,
- new FeatureColour(UserColourScheme
- .getColourFromString(theType)));
- }
- sf = new SequenceFeature(theType, desc, "", featureStart, featureEnd, featureGroup);
- if (st.hasMoreTokens())
- {
- float score = 0f;
- try
- {
- score = new Float(st.nextToken()).floatValue();
- // update colourgradient bounds if allowed to
- } catch (NumberFormatException ex)
- {
- // ignore
- }
- sf.setScore(score);
- }
- if (groupLink != null && removeHTML)
- {
- sf.addLink(groupLink);
- sf.description += "%LINK%";
- }
- if (typeLink.containsKey(theType) && removeHTML)
- {
- sf.addLink(typeLink.get(theType));
- sf.description += "%LINK%";
- }
-
- parseDescriptionHTML(sf, removeHTML);
-
- seq.addSequenceFeature(sf);