X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fgff%2FGff3Helper.java;h=031900d3c199d75b4f70e29b43abb07049ff7965;hb=55ea0e81c495953933370df9bb747120649e5274;hp=4c67caa7fb4db009038dd878c8f553d96e54a9cf;hpb=8f920d337154e092f5f9056ffde3cdf2735eca43;p=jalview.git diff --git a/src/jalview/io/gff/Gff3Helper.java b/src/jalview/io/gff/Gff3Helper.java index 4c67caa..031900d 100644 --- a/src/jalview/io/gff/Gff3Helper.java +++ b/src/jalview/io/gff/Gff3Helper.java @@ -61,19 +61,6 @@ public class Gff3Helper extends GffHelperBase AlignmentI align, List newseqs, boolean relaxedIdMatching) throws IOException { - /* - * (For now) we don't process mappings from reverse complement ; to do - * this would require (a) creating a virtual sequence placeholder for - * the reverse complement (b) resolving the sequence by its id from some - * source (GFF ##FASTA or other) (c) creating the reverse complement - * sequence (d) updating the mapping to be to the reverse complement - */ - if ("-".equals(gff[STRAND_COL])) - { - System.err - .println("Skipping mapping from reverse complement as not yet supported"); - return null; - } SequenceFeature sf = null; if (gff.length == 9) @@ -82,12 +69,13 @@ public class Gff3Helper extends GffHelperBase String atts = gff[ATTRIBUTES_COL]; Map> attributes = parseNameValuePairs(atts); - if (SequenceOntology.getInstance().isProteinMatch(soTerm)) + SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + if (so.isA(soTerm, SequenceOntologyI.PROTEIN_MATCH)) { - sf = processProteinMatch(attributes, seq, gff, align, - newseqs, relaxedIdMatching); + sf = processProteinMatch(attributes, seq, gff, align, newseqs, + relaxedIdMatching); } - else if (SequenceOntology.getInstance().isNucleotideMatch(soTerm)) + else if (so.isA(soTerm, SequenceOntologyI.NUCLEOTIDE_MATCH)) { sf = processNucleotideMatch(attributes, seq, gff, align, newseqs, relaxedIdMatching); @@ -135,10 +123,18 @@ public class Gff3Helper extends GffHelperBase throws IOException { String strand = gffColumns[STRAND_COL]; - if ("-1".equals(strand)) + + /* + * (For now) we don't process mappings from reverse complement ; to do + * this would require (a) creating a virtual sequence placeholder for + * the reverse complement (b) resolving the sequence by its id from some + * source (GFF ##FASTA or other) (c) creating the reverse complement + * sequence (d) updating the mapping to be to the reverse complement + */ + if ("-".equals(strand)) { System.err - .println("Currently ignoring mappings from reverse complement"); + .println("Skipping mapping from reverse complement as not yet supported"); return null; } @@ -351,11 +347,61 @@ public class Gff3Helper extends GffHelperBase Map> attributes) { SequenceFeature sf = super.buildSequenceFeature(gff, attributes); + String desc = getDescription(sf, attributes); + if (desc != null) + { + sf.setDescription(desc); + } + return sf; + } + + /** + * Apply heuristic rules to try to get the most useful feature description + * + * @param sf + * @param attributes + * @return + */ + protected String getDescription(SequenceFeature sf, + Map> attributes) + { + String desc = null; String target = (String) sf.getValue(TARGET); if (target != null) { - sf.setDescription(target.split(" ")[0]); + desc = target.split(" ")[0]; } - return sf; + + SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + String type = sf.getType(); + if (so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT)) + { + /* + * Ensembl returns dna variants as 'alleles' + */ + desc = StringUtils.listToDelimitedString( + attributes.get("alleles"), ","); + } + + /* + * extract 'Name' for a transcript (to show gene name) + * or an exon (so 'colour by label' shows exon boundaries) + */ + if (SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(type) + || so.isA(type, SequenceOntologyI.TRANSCRIPT) + || so.isA(type, SequenceOntologyI.EXON)) + { + desc = StringUtils.listToDelimitedString(attributes.get("Name"), ","); + } + + /* + * if the above fails, try ID + */ + if (desc == null) + { + desc = (String) sf.getValue(ID); + } + + return desc; } }