1 package jalview.ext.ensembl;
3 import jalview.analysis.AlignmentUtils;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.DBRefEntry;
7 import jalview.datamodel.DBRefSource;
8 import jalview.datamodel.Mapping;
9 import jalview.datamodel.SequenceFeature;
10 import jalview.datamodel.SequenceI;
11 import jalview.exceptions.JalviewException;
12 import jalview.io.FastaFile;
13 import jalview.io.FileParse;
14 import jalview.io.gff.SequenceOntologyFactory;
15 import jalview.io.gff.SequenceOntologyI;
16 import jalview.schemes.ResidueProperties;
17 import jalview.util.DBRefUtils;
18 import jalview.util.MapList;
19 import jalview.util.MappingUtils;
20 import jalview.util.StringUtils;
22 import java.io.IOException;
23 import java.net.MalformedURLException;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.LinkedHashMap;
30 import java.util.List;
31 import java.util.Map.Entry;
34 * Base class for Ensembl sequence fetchers
36 * @see http://rest.ensembl.org/documentation/info/sequence_id
39 public abstract class EnsemblSeqProxy extends EnsemblRestClient
41 private static final List<String> CROSS_REFERENCES = Arrays
42 .asList(new String[] { "CCDS", "Uniprot/SWISSPROT" });
44 protected static final String CONSEQUENCE_TYPE = "consequence_type";
46 protected static final String PARENT = "Parent";
48 protected static final String ID = "ID";
50 protected static final String NAME = "Name";
53 * enum for 'type' parameter to the /sequence REST service
55 public enum EnsemblSeqType
58 * type=genomic to fetch full dna including introns
63 * type=cdna to fetch dna including UTRs
68 * type=cds to fetch coding dna excluding UTRs
73 * type=protein to fetch peptide product sequence
78 * the value of the 'type' parameter to fetch this version of
83 EnsemblSeqType(String t)
88 public String getType()
96 * A comparator to sort ranges into ascending start position order
98 private class RangeSorter implements Comparator<int[]>
102 RangeSorter(boolean forward)
108 public int compare(int[] o1, int[] o2)
110 return (forwards ? 1 : -1) * Integer.compare(o1[0], o2[0]);
116 * Default constructor (to use rest.ensembl.org)
118 public EnsemblSeqProxy()
124 * Constructor given the target domain to fetch data from
126 public EnsemblSeqProxy(String d)
132 * Makes the sequence queries to Ensembl's REST service and returns an
133 * alignment consisting of the returned sequences.
136 public AlignmentI getSequenceRecords(String query) throws Exception
138 // TODO use a String... query vararg instead?
140 // danger: accession separator used as a regex here, a string elsewhere
141 // in this case it is ok (it is just a space), but (e.g.) '\' would not be
142 List<String> allIds = Arrays.asList(query
143 .split(getAccessionSeparator()));
144 AlignmentI alignment = null;
148 * execute queries, if necessary in batches of the
149 * maximum allowed number of ids
151 int maxQueryCount = getMaximumQueryCount();
152 for (int v = 0, vSize = allIds.size(); v < vSize; v += maxQueryCount)
154 int p = Math.min(vSize, v + maxQueryCount);
155 List<String> ids = allIds.subList(v, p);
158 alignment = fetchSequences(ids, alignment);
159 } catch (Throwable r)
162 String msg = "Aborting ID retrieval after " + v
163 + " chunks. Unexpected problem (" + r.getLocalizedMessage()
165 System.err.println(msg);
170 if (alignment == null)
176 * fetch and transfer genomic sequence features,
177 * fetch protein product and add as cross-reference
179 for (String accId : allIds)
181 addFeaturesAndProduct(accId, alignment);
184 for (SequenceI seq : alignment.getSequences())
186 getCrossReferences(seq);
193 * Fetches Ensembl features using the /overlap REST endpoint, and adds them to
194 * the sequence in the alignment. Also fetches the protein product, maps it
195 * from the CDS features of the sequence, and saves it as a cross-reference of
201 protected void addFeaturesAndProduct(String accId, AlignmentI alignment)
203 if (alignment == null)
211 * get 'dummy' genomic sequence with exon, cds and variation features
213 SequenceI genomicSequence = null;
214 EnsemblFeatures gffFetcher = new EnsemblFeatures(getDomain());
215 EnsemblFeatureType[] features = getFeaturesToFetch();
216 AlignmentI geneFeatures = gffFetcher.getSequenceRecords(accId,
218 if (geneFeatures.getHeight() > 0)
220 genomicSequence = geneFeatures.getSequenceAt(0);
222 if (genomicSequence != null)
225 * transfer features to the query sequence
227 SequenceI querySeq = alignment.findName(accId);
228 if (transferFeatures(accId, genomicSequence, querySeq))
232 * fetch and map protein product, and add it as a cross-reference
233 * of the retrieved sequence
235 addProteinProduct(querySeq);
238 } catch (IOException e)
240 System.err.println("Error transferring Ensembl features: "
246 * Returns those sequence feature types to fetch from Ensembl. We may want
247 * features either because they are of interest to the user, or as means to
248 * identify the locations of the sequence on the genomic sequence (CDS
249 * features identify CDS, exon features identify cDNA etc).
253 protected abstract EnsemblFeatureType[] getFeaturesToFetch();
256 * Fetches and maps the protein product, and adds it as a cross-reference of
257 * the retrieved sequence
259 protected void addProteinProduct(SequenceI querySeq)
261 String accId = querySeq.getName();
264 AlignmentI protein = new EnsemblProtein(getDomain())
265 .getSequenceRecords(accId);
266 if (protein == null || protein.getHeight() == 0)
268 System.out.println("Failed to retrieve protein for " + accId);
271 SequenceI proteinSeq = protein.getSequenceAt(0);
274 * need dataset sequences (to be the subject of mappings)
276 proteinSeq.createDatasetSequence();
277 querySeq.createDatasetSequence();
279 MapList mapList = mapCdsToProtein(querySeq, proteinSeq);
282 // clunky: ensure Uniprot xref if we have one is on mapped sequence
283 SequenceI ds = proteinSeq.getDatasetSequence();
284 ds.setSourceDBRef(proteinSeq.getSourceDBRef());
285 Mapping map = new Mapping(ds, mapList);
286 DBRefEntry dbr = new DBRefEntry(getDbSource(), getDbVersion(),
288 querySeq.getDatasetSequence().addDBRef(dbr);
291 * compute peptide variants from dna variants and add as
292 * sequence features on the protein sequence ta-da
294 computeProteinFeatures(querySeq, proteinSeq, mapList);
296 } catch (Exception e)
299 .println(String.format("Error retrieving protein for %s: %s",
300 accId, e.getMessage()));
305 * Get database xrefs from Ensembl, and attach them to the sequence
309 protected void getCrossReferences(SequenceI seq)
311 while (seq.getDatasetSequence() != null)
313 seq = seq.getDatasetSequence();
316 EnsemblXref xrefFetcher = new EnsemblXref(getDomain());
317 List<DBRefEntry> xrefs = xrefFetcher.getCrossReferences(seq.getName(),
318 getCrossReferenceDatabases());
319 for (DBRefEntry xref : xrefs)
323 * Save any Uniprot xref to be the reference for SIFTS mapping
325 if (DBRefSource.UNIPROT.equals(xref.getSource()))
327 seq.setSourceDBRef(xref);
333 * Returns a list of database names to be used when fetching cross-references.
337 protected List<String> getCrossReferenceDatabases()
339 return CROSS_REFERENCES;
343 * Returns a mapping from dna to protein by inspecting sequence features of
344 * type "CDS" on the dna.
350 protected MapList mapCdsToProtein(SequenceI dnaSeq, SequenceI proteinSeq)
352 List<int[]> ranges = getCdsRanges(dnaSeq);
353 int mappedDnaLength = MappingUtils.getLength(ranges);
355 int proteinLength = proteinSeq.getLength();
356 int proteinEnd = proteinLength;
357 int proteinStart = 1;
360 * incomplete start codon may mean X at start of peptide
361 * we ignore both for mapping purposes
363 if (proteinSeq.getCharAt(0) == 'X')
368 List<int[]> proteinRange = new ArrayList<int[]>();
371 * dna length should map to protein (or protein plus stop codon)
373 int codesForResidues = mappedDnaLength / 3;
374 if (codesForResidues == (proteinLength + 1))
376 // assuming extra codon is for STOP and not in peptide
379 if (codesForResidues == proteinLength)
381 proteinRange.add(new int[] { proteinStart, proteinEnd });
382 return new MapList(ranges, proteinRange, 3, 1);
388 * Returns a list of CDS ranges found.
390 * No need to worry about reverse strand dna, here since the retrieved
391 * sequence is as transcribed (reverse complement for reverse strand), i.e in
392 * the same sense as the peptide.
397 protected List<int[]> getCdsRanges(SequenceI dnaSeq)
399 List<int[]> result = new ArrayList<int[]>();
400 SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
405 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
406 for (SequenceFeature sf : sfs)
409 * process a CDS feature (or a sub-type of CDS)
411 if (so.isA(sf.getType(), SequenceOntologyI.CDS))
415 phase = Integer.parseInt(sf.getPhase());
416 } catch (NumberFormatException e)
421 * phase > 0 on first codon means 5' incomplete - skip to the start
422 * of the next codon; example ENST00000496384
424 int begin = sf.getBegin();
425 int end = sf.getEnd();
426 if (result.isEmpty())
431 continue; // shouldn't happen?
434 result.add(new int[] { begin, end });
441 * Fetches sequences for the list of accession ids and adds them to the
442 * alignment. Returns the extended (or created) alignment.
447 * @throws JalviewException
448 * @throws IOException
450 protected AlignmentI fetchSequences(List<String> ids, AlignmentI alignment)
451 throws JalviewException, IOException
453 if (!isEnsemblAvailable())
456 throw new JalviewException("ENSEMBL Rest API not available.");
458 FileParse fp = getSequenceReader(ids);
459 FastaFile fr = new FastaFile(fp);
460 if (fr.hasWarningMessage())
462 System.out.println(String.format(
463 "Warning when retrieving %d ids %s\n%s", ids.size(),
464 ids.toString(), fr.getWarningMessage()));
466 else if (fr.getSeqs().size() != ids.size())
468 System.out.println(String.format(
469 "Only retrieved %d sequences for %d query strings", fr
470 .getSeqs().size(), ids.size()));
473 if (fr.getSeqs().size() == 1 && fr.getSeqs().get(0).getLength() == 0)
476 * POST request has returned an empty FASTA file e.g. for invalid id
478 throw new IOException("No data returned for " + ids);
481 if (fr.getSeqs().size() > 0)
483 AlignmentI seqal = new Alignment(
484 fr.getSeqsAsArray());
485 for (SequenceI sq:seqal.getSequences())
487 if (sq.getDescription() == null)
489 sq.setDescription(getDbName());
491 String name = sq.getName();
492 if (ids.contains(name)
493 || ids.contains(name.replace("ENSP", "ENST")))
495 DBRefUtils.parseToDbRef(sq, DBRefSource.ENSEMBL, "0", name);
498 if (alignment == null)
504 alignment.append(seqal);
511 * Returns the URL for the REST call
514 * @throws MalformedURLException
517 protected URL getUrl(List<String> ids) throws MalformedURLException
520 * a single id is included in the URL path
521 * multiple ids go in the POST body instead
523 StringBuffer urlstring = new StringBuffer(128);
524 urlstring.append(getDomain() + "/sequence/id");
527 urlstring.append("/").append(ids.get(0));
529 // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
530 urlstring.append("?type=").append(getSourceEnsemblType().getType());
531 urlstring.append(("&Accept=text/x-fasta"));
533 URL url = new URL(urlstring.toString());
538 * A sequence/id POST request currently allows up to 50 queries
540 * @see http://rest.ensembl.org/documentation/info/sequence_id_post
543 public int getMaximumQueryCount()
549 protected boolean useGetRequest()
555 protected String getRequestMimeType(boolean multipleIds)
557 return multipleIds ? "application/json" : "text/x-fasta";
561 protected String getResponseMimeType()
563 return "text/x-fasta";
568 * @return the configured sequence return type for this source
570 protected abstract EnsemblSeqType getSourceEnsemblType();
573 * Returns a list of [start, end] genomic ranges corresponding to the sequence
576 * The correspondence between the frames of reference is made by locating
577 * those features on the genomic sequence which identify the retrieved
578 * sequence. Specifically
580 * <li>genomic sequence is identified by "transcript" features with
581 * ID=transcript:transcriptId</li>
582 * <li>cdna sequence is identified by "exon" features with
583 * Parent=transcript:transcriptId</li>
584 * <li>cds sequence is identified by "CDS" features with
585 * Parent=transcript:transcriptId</li>
588 * The returned ranges are sorted to run forwards (for positive strand) or
589 * backwards (for negative strand). Aborts and returns null if both positive
590 * and negative strand are found (this should not normally happen).
592 * @param sourceSequence
595 * the start position of the sequence we are mapping to
598 protected MapList getGenomicRangesFromFeatures(SequenceI sourceSequence,
599 String accId, int start)
601 SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
608 * generously initial size for number of cds regions
609 * (worst case titin Q8WZ42 has c. 313 exons)
611 List<int[]> regions = new ArrayList<int[]>(100);
612 int mappedLength = 0;
613 int direction = 1; // forward
614 boolean directionSet = false;
616 for (SequenceFeature sf : sfs)
619 * accept the target feature type or a specialisation of it
620 * (e.g. coding_exon for exon)
622 if (identifiesSequence(sf, accId))
624 int strand = sf.getStrand();
625 strand = strand == 0 ? 1 : strand; // treat unknown as forward
627 if (directionSet && strand != direction)
629 // abort - mix of forward and backward
630 System.err.println("Error: forward and backward strand for "
638 * add to CDS ranges, semi-sorted forwards/backwards
642 regions.add(0, new int[] { sf.getEnd(), sf.getBegin() });
646 regions.add(new int[] { sf.getBegin(), sf.getEnd() });
648 mappedLength += Math.abs(sf.getEnd() - sf.getBegin() + 1);
653 * 'gene' sequence is contiguous so we can stop as soon as its
654 * identifying feature has been found
661 if (regions.isEmpty())
663 System.out.println("Failed to identify target sequence for " + accId
664 + " from genomic features");
669 * a final sort is needed since Ensembl returns CDS sorted within source
670 * (havana / ensembl_havana)
672 Collections.sort(regions, new RangeSorter(direction == 1));
674 List<int[]> to = Arrays.asList(new int[] { start,
675 start + mappedLength - 1 });
677 return new MapList(regions, to, 1, 1);
681 * Answers true if the sequence being retrieved may occupy discontiguous
682 * regions on the genomic sequence.
684 protected boolean isSpliceable()
690 * Returns true if the sequence feature marks positions of the genomic
691 * sequence feature which are within the sequence being retrieved. For
692 * example, an 'exon' feature whose parent is the target transcript marks the
693 * cdna positions of the transcript.
699 protected abstract boolean identifiesSequence(SequenceFeature sf,
703 * Transfers the sequence feature to the target sequence, locating its start
704 * and end range based on the mapping. Features which do not overlap the
705 * target sequence are ignored.
708 * @param targetSequence
710 * mapping from the sequence feature's coordinates to the target
713 protected void transferFeature(SequenceFeature sf,
714 SequenceI targetSequence, MapList mapping)
716 int start = sf.getBegin();
717 int end = sf.getEnd();
718 int[] mappedRange = mapping.locateInTo(start, end);
720 if (mappedRange != null)
722 SequenceFeature copy = new SequenceFeature(sf);
723 copy.setBegin(Math.min(mappedRange[0], mappedRange[1]));
724 copy.setEnd(Math.max(mappedRange[0], mappedRange[1]));
725 targetSequence.addSequenceFeature(copy);
728 * for sequence_variant, make an additional feature with consequence
730 // if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
731 // SequenceOntologyI.SEQUENCE_VARIANT))
733 // String consequence = (String) sf.getValue(CONSEQUENCE_TYPE);
734 // if (consequence != null)
736 // SequenceFeature sf2 = new SequenceFeature("consequence",
737 // consequence, copy.getBegin(), copy.getEnd(), 0f,
739 // targetSequence.addSequenceFeature(sf2);
746 * Transfers features from sourceSequence to targetSequence
749 * @param sourceSequence
750 * @param targetSequence
751 * @return true if any features were transferred, else false
753 protected boolean transferFeatures(String accessionId,
754 SequenceI sourceSequence, SequenceI targetSequence)
756 if (sourceSequence == null || targetSequence == null)
761 // long start = System.currentTimeMillis();
762 SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
763 MapList mapping = getGenomicRangesFromFeatures(sourceSequence, accessionId,
764 targetSequence.getStart());
770 boolean result = transferFeatures(sfs, targetSequence, mapping,
772 // System.out.println("transferFeatures (" + (sfs.length) + " --> "
773 // + targetSequence.getSequenceFeatures().length + ") to "
774 // + targetSequence.getName()
775 // + " took " + (System.currentTimeMillis() - start) + "ms");
780 * Transfer features to the target sequence. The start/end positions are
781 * converted using the mapping. Features which do not overlap are ignored.
782 * Features whose parent is not the specified identifier are also ignored.
785 * @param targetSequence
790 protected boolean transferFeatures(SequenceFeature[] features,
791 SequenceI targetSequence, MapList mapping, String parentId)
793 final boolean forwardStrand = mapping.isFromForwardStrand();
796 * sort features by start position (descending if reverse strand)
797 * before transferring (in forwards order) to the target sequence
799 Arrays.sort(features, new Comparator<SequenceFeature>()
802 public int compare(SequenceFeature o1, SequenceFeature o2)
804 int c = Integer.compare(o1.getBegin(), o2.getBegin());
805 return forwardStrand ? c : -c;
809 boolean transferred = false;
810 for (SequenceFeature sf : features)
812 if (retainFeature(sf, parentId))
814 transferFeature(sf, targetSequence, mapping);
822 * Answers true if the feature type is one we want to keep for the sequence.
823 * Some features are only retrieved in order to identify the sequence range,
824 * and may then be discarded as redundant information (e.g. "CDS" feature for
827 @SuppressWarnings("unused")
828 protected boolean retainFeature(SequenceFeature sf, String accessionId)
830 return true; // override as required
834 * Answers true if the feature has a Parent which refers to the given
835 * accession id, or if the feature has no parent. Answers false if the
836 * feature's Parent is for a different accession id.
842 protected boolean featureMayBelong(SequenceFeature sf, String identifier)
844 String parent = (String) sf.getValue(PARENT);
845 // using contains to allow for prefix "gene:", "transcript:" etc
846 if (parent != null && !parent.contains(identifier))
848 // this genomic feature belongs to a different transcript
855 public String getDescription()
857 return "Ensembl " + getSourceEnsemblType().getType()
858 + " sequence with variant features";
862 * Returns a (possibly empty) list of features on the sequence which have the
863 * specified sequence ontology type (or a sub-type of it), and the given
864 * identifier as parent
871 protected List<SequenceFeature> findFeatures(SequenceI sequence,
872 String type, String parentId)
874 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
876 SequenceFeature[] sfs = sequence.getSequenceFeatures();
878 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
879 for (SequenceFeature sf :sfs) {
880 if (so.isA(sf.getType(), type))
882 String parent = (String) sf.getValue(PARENT);
883 if (parent.equals(parentId))
894 * Maps exon features from dna to protein, and computes variants in peptide
895 * product generated by variants in dna, and adds them as sequence_variant
896 * features on the protein sequence. Returns the number of variant features
901 * @param dnaToProtein
903 static int computeProteinFeatures(SequenceI dnaSeq,
904 SequenceI peptide, MapList dnaToProtein)
906 while (dnaSeq.getDatasetSequence() != null)
908 dnaSeq = dnaSeq.getDatasetSequence();
910 while (peptide.getDatasetSequence() != null)
912 peptide = peptide.getDatasetSequence();
915 AlignmentUtils.transferFeatures(dnaSeq, peptide, dnaToProtein,
916 SequenceOntologyI.EXON);
918 LinkedHashMap<Integer, String[][]> variants = buildDnaVariantsMap(
919 dnaSeq, dnaToProtein);
922 * scan codon variations, compute peptide variants and add to peptide sequence
925 for (Entry<Integer, String[][]> variant : variants.entrySet())
927 int peptidePos = variant.getKey();
928 String[][] codonVariants = variant.getValue();
929 String residue = String.valueOf(peptide.getCharAt(peptidePos - 1)); // 0-based
930 List<String> peptideVariants = computePeptideVariants(codonVariants,
932 if (!peptideVariants.isEmpty())
934 String desc = StringUtils.listToDelimitedString(peptideVariants,
936 SequenceFeature sf = new SequenceFeature(
937 SequenceOntologyI.SEQUENCE_VARIANT, desc, peptidePos,
938 peptidePos, 0f, null);
939 peptide.addSequenceFeature(sf);
945 * ugly sort to get sequence features in start position order
946 * - would be better to store in Sequence as a TreeSet instead?
948 Arrays.sort(peptide.getSequenceFeatures(),
949 new Comparator<SequenceFeature>()
952 public int compare(SequenceFeature o1, SequenceFeature o2)
954 int c = Integer.compare(o1.getBegin(), o2.getBegin());
955 return c == 0 ? Integer.compare(o1.getEnd(), o2.getEnd())
963 * Builds a map whose key is position in the protein sequence, and value is an
964 * array of all variants for the coding codon positions
967 * @param dnaToProtein
970 static LinkedHashMap<Integer, String[][]> buildDnaVariantsMap(
971 SequenceI dnaSeq, MapList dnaToProtein)
974 * map from peptide position to all variant features of the codon for it
975 * LinkedHashMap ensures we add the peptide features in sequence order
977 LinkedHashMap<Integer, String[][]> variants = new LinkedHashMap<Integer, String[][]>();
978 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
980 SequenceFeature[] dnaFeatures = dnaSeq.getSequenceFeatures();
981 if (dnaFeatures == null)
986 int dnaStart = dnaSeq.getStart();
987 int[] lastCodon = null;
988 int lastPeptidePostion = 0;
991 * build a map of codon variations for peptides
993 for (SequenceFeature sf : dnaFeatures)
995 int dnaCol = sf.getBegin();
996 if (dnaCol != sf.getEnd())
998 // not handling multi-locus variant features
1001 if (so.isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT))
1003 int[] mapsTo = dnaToProtein.locateInTo(dnaCol, dnaCol);
1006 // feature doesn't lie within coding region
1009 int peptidePosition = mapsTo[0];
1010 String[][] codonVariants = variants.get(peptidePosition);
1011 if (codonVariants == null)
1013 codonVariants = new String[3][];
1014 variants.put(peptidePosition, codonVariants);
1018 * extract dna variants to a string array
1020 String alls = (String) sf.getValue("alleles");
1025 String[] alleles = alls.split(",");
1028 * get this peptides codon positions e.g. [3, 4, 5] or [4, 7, 10]
1030 int[] codon = peptidePosition == lastPeptidePostion ? lastCodon
1031 : MappingUtils.flattenRanges(dnaToProtein.locateInFrom(
1032 peptidePosition, peptidePosition));
1033 lastPeptidePostion = peptidePosition;
1037 * save nucleotide (and this variant) for each codon position
1039 for (int codonPos = 0; codonPos < 3; codonPos++)
1041 String nucleotide = String.valueOf(dnaSeq
1042 .getCharAt(codon[codonPos] - dnaStart));
1043 if (codon[codonPos] == dnaCol)
1046 * record current dna base and its alleles
1048 String[] dnaVariants = new String[alleles.length + 1];
1049 dnaVariants[0] = nucleotide;
1050 System.arraycopy(alleles, 0, dnaVariants, 1, alleles.length);
1051 codonVariants[codonPos] = dnaVariants;
1053 else if (codonVariants[codonPos] == null)
1056 * record current dna base only
1057 * (at least until we find any variation and overwrite it)
1059 codonVariants[codonPos] = new String[] { nucleotide };
1068 * Returns a sorted, non-redundant list of all peptide translations generated
1069 * by the given dna variants, excluding the current residue value
1071 * @param codonVariants
1072 * an array of base values (acgtACGT) for codon positions 1, 2, 3
1074 * the current residue translation
1077 static List<String> computePeptideVariants(
1078 String[][] codonVariants, String residue)
1080 List<String> result = new ArrayList<String>();
1081 for (String base1 : codonVariants[0])
1083 for (String base2 : codonVariants[1])
1085 for (String base3 : codonVariants[2])
1087 String codon = base1 + base2 + base3;
1088 // TODO: report frameshift/insertion/deletion
1089 // and multiple-base variants?!
1090 String peptide = codon.contains("-") ? "-" : ResidueProperties
1091 .codonTranslate(codon);
1092 if (peptide != null && !result.contains(peptide)
1093 && !peptide.equalsIgnoreCase(residue))
1095 result.add(peptide);
1102 * sort alphabetically with STOP at the end
1104 Collections.sort(result, new Comparator<String>()
1108 public int compare(String o1, String o2)
1110 if ("STOP".equals(o1))
1114 else if ("STOP".equals(o2))
1120 return o1.compareTo(o2);
1128 * Answers true if the feature type is either 'NMD_transcript_variant' or
1129 * 'transcript' or one of its sub-types in the Sequence Ontology. This is
1130 * needed because NMD_transcript_variant behaves like 'transcript' in Ensembl
1131 * although strictly speaking it is not (it is a sub-type of
1132 * sequence_variant).
1134 * @param featureType
1137 public static boolean isTranscript(String featureType)
1139 return SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(featureType)
1140 || SequenceOntologyFactory.getInstance().isA(featureType,
1141 SequenceOntologyI.TRANSCRIPT);