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;
33 import com.stevesoft.pat.Regex;
36 * Base class for Ensembl sequence fetchers
40 public abstract class EnsemblSeqProxy extends EnsemblRestClient
42 // TODO modify to accept other species e.g. ENSMUSTnnn
43 private static final Regex TRANSCRIPT_REGEX = new Regex(
46 private static final List<String> CROSS_REFERENCES = Arrays
47 .asList(new String[] { "CCDS" });
49 protected static final String CONSEQUENCE_TYPE = "consequence_type";
51 protected static final String PARENT = "Parent";
53 protected static final String ID = "ID";
55 protected static final String NAME = "Name";
58 * enum for 'type' parameter to the /sequence REST service
60 public enum EnsemblSeqType
63 * type=genomic to fetch full dna including introns
68 * type=cdna to fetch dna including UTRs
73 * type=cds to fetch coding dna excluding UTRs
78 * type=protein to fetch peptide product sequence
83 * the value of the 'type' parameter to fetch this version of
88 EnsemblSeqType(String t)
93 public String getType()
101 * A comparator to sort ranges into ascending start position order
103 private class RangeSorter implements Comparator<int[]>
107 RangeSorter(boolean forward)
113 public int compare(int[] o1, int[] o2)
115 return (forwards ? 1 : -1) * Integer.compare(o1[0], o2[0]);
123 public EnsemblSeqProxy()
128 * Makes the sequence queries to Ensembl's REST service and returns an
129 * alignment consisting of the returned sequences.
132 public AlignmentI getSequenceRecords(String query) throws Exception
134 // TODO use a String... query vararg instead?
136 // danger: accession separator used as a regex here, a string elsewhere
137 // in this case it is ok (it is just a space), but (e.g.) '\' would not be
138 List<String> allIds = Arrays.asList(query
139 .split(getAccessionSeparator()));
140 AlignmentI alignment = null;
144 * execute queries, if necessary in batches of the
145 * maximum allowed number of ids
147 int maxQueryCount = getMaximumQueryCount();
148 for (int v = 0, vSize = allIds.size(); v < vSize; v += maxQueryCount)
150 int p = Math.min(vSize, v + maxQueryCount);
151 List<String> ids = allIds.subList(v, p);
154 alignment = fetchSequences(ids, alignment);
155 } catch (Throwable r)
158 String msg = "Aborting ID retrieval after " + v
159 + " chunks. Unexpected problem (" + r.getLocalizedMessage()
161 System.err.println(msg);
167 * fetch and transfer genomic sequence features,
168 * fetch protein product and add as cross-reference
170 for (String accId : allIds)
172 addFeaturesAndProduct(accId, alignment);
175 for (SequenceI seq : alignment.getSequences())
177 getCrossReferences(seq);
184 * Fetches Ensembl features using the /overlap REST endpoint, and adds them to
185 * the sequence in the alignment. Also fetches the protein product, maps it
186 * from the CDS features of the sequence, and saves it as a cross-reference of
192 protected void addFeaturesAndProduct(String accId, AlignmentI alignment)
194 if (alignment == null)
202 * get 'dummy' genomic sequence with exon, cds and variation features
204 SequenceI genomicSequence = null;
205 EnsemblFeatures gffFetcher = new EnsemblFeatures();
206 EnsemblFeatureType[] features = getFeaturesToFetch();
207 AlignmentI geneFeatures = gffFetcher.getSequenceRecords(accId,
209 if (geneFeatures.getHeight() > 0)
211 genomicSequence = geneFeatures.getSequenceAt(0);
213 if (genomicSequence != null)
216 * transfer features to the query sequence
218 SequenceI querySeq = alignment.findName(accId);
219 if (transferFeatures(accId, genomicSequence, querySeq))
223 * fetch and map protein product, and add it as a cross-reference
224 * of the retrieved sequence
226 addProteinProduct(querySeq);
229 } catch (IOException e)
231 System.err.println("Error transferring Ensembl features: "
237 * Returns those sequence feature types to fetch from Ensembl. We may want
238 * features either because they are of interest to the user, or as means to
239 * identify the locations of the sequence on the genomic sequence (CDS
240 * features identify CDS, exon features identify cDNA etc).
244 protected abstract EnsemblFeatureType[] getFeaturesToFetch();
247 * Fetches and maps the protein product, and adds it as a cross-reference of
248 * the retrieved sequence
250 protected void addProteinProduct(SequenceI querySeq)
252 String accId = querySeq.getName();
255 AlignmentI protein = new EnsemblProtein().getSequenceRecords(accId);
256 if (protein == null || protein.getHeight() == 0)
258 System.out.println("Failed to retrieve protein for " + accId);
261 SequenceI proteinSeq = protein.getSequenceAt(0);
264 * need dataset sequences (to be the subject of mappings)
266 proteinSeq.createDatasetSequence();
267 querySeq.createDatasetSequence();
269 MapList mapList = mapCdsToProtein(querySeq, proteinSeq);
272 // clunky: ensure Uniprot xref if we have one is on mapped sequence
273 SequenceI ds = proteinSeq.getDatasetSequence();
274 ds.setSourceDBRef(proteinSeq.getSourceDBRef());
275 Mapping map = new Mapping(ds, mapList);
276 DBRefEntry dbr = new DBRefEntry(getDbSource(), getDbVersion(),
278 querySeq.getDatasetSequence().addDBRef(dbr);
281 * compute peptide variants from dna variants and add as
282 * sequence features on the protein sequence ta-da
284 computeProteinFeatures(querySeq, proteinSeq, mapList);
286 } catch (Exception e)
289 .println(String.format("Error retrieving protein for %s: %s",
290 accId, e.getMessage()));
295 * Get database xrefs from Ensembl, and attach them to the sequence
299 protected void getCrossReferences(SequenceI seq)
301 while (seq.getDatasetSequence() != null)
303 seq = seq.getDatasetSequence();
306 EnsemblXref xrefFetcher = new EnsemblXref();
307 List<DBRefEntry> xrefs = xrefFetcher.getCrossReferences(seq.getName(),
308 getCrossReferenceDatabases());
309 for (DBRefEntry xref : xrefs)
313 * Save any Uniprot xref to be the reference for SIFTS mapping
315 if (DBRefSource.UNIPROT.equals(xref.getSource()))
317 seq.setSourceDBRef(xref);
323 * Returns a list of database names to be used when fetching cross-references.
327 protected List<String> getCrossReferenceDatabases()
329 return CROSS_REFERENCES;
333 * Returns a mapping from dna to protein by inspecting sequence features of
334 * type "CDS" on the dna.
340 protected MapList mapCdsToProtein(SequenceI dnaSeq, SequenceI proteinSeq)
342 List<int[]> ranges = new ArrayList<int[]>(50);
344 int mappedDnaLength = getCdsRanges(dnaSeq, ranges);
346 int proteinLength = proteinSeq.getLength();
347 List<int[]> proteinRange = new ArrayList<int[]>();
348 int proteinStart = 1;
351 * incomplete start codon may mean X at start of peptide
352 * we ignore both for mapping purposes
354 if (proteinSeq.getCharAt(0) == 'X')
359 proteinRange.add(new int[] { proteinStart, proteinLength });
362 * dna length should map to protein (or protein plus stop codon)
364 int codesForResidues = mappedDnaLength / 3;
365 if (codesForResidues == proteinLength
366 || codesForResidues == (proteinLength + 1))
368 return new MapList(ranges, proteinRange, 3, 1);
374 * Adds CDS ranges to the ranges list, and returns the total length mapped
377 * No need to worry about reverse strand dna, here since the retrieved
378 * sequence is as transcribed (reverse complement for reverse strand), i.e in
379 * the same sense as the peptide.
385 protected int getCdsRanges(SequenceI dnaSeq, List<int[]> ranges)
387 SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
392 int mappedDnaLength = 0;
393 for (SequenceFeature sf : sfs)
396 * process a CDS feature (or a sub-type of CDS)
398 if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
399 SequenceOntologyI.CDS))
403 phase = Integer.parseInt(sf.getPhase());
404 } catch (NumberFormatException e)
409 * phase > 0 on first codon means 5' incomplete - skip to the start
410 * of the next codon; example ENST00000496384
412 int begin = sf.getBegin();
413 int end = sf.getEnd();
414 if (ranges.isEmpty() && phase > 0)
419 continue; // shouldn't happen?
422 ranges.add(new int[] { begin, end });
423 mappedDnaLength += Math.abs(end - begin) + 1;
426 return mappedDnaLength;
430 * Fetches sequences for the list of accession ids and adds them to the
431 * alignment. Returns the extended (or created) alignment.
436 * @throws JalviewException
437 * @throws IOException
439 protected AlignmentI fetchSequences(List<String> ids, AlignmentI alignment)
440 throws JalviewException, IOException
442 if (!isEnsemblAvailable())
445 throw new JalviewException("ENSEMBL Rest API not available.");
447 FileParse fp = getSequenceReader(ids);
448 FastaFile fr = new FastaFile(fp);
449 if (fr.hasWarningMessage())
451 System.out.println(String.format(
452 "Warning when retrieving %d ids %s\n%s", ids.size(),
453 ids.toString(), fr.getWarningMessage()));
455 else if (fr.getSeqs().size() != ids.size())
457 System.out.println(String.format(
458 "Only retrieved %d sequences for %d query strings", fr
459 .getSeqs().size(), ids.size()));
462 if (fr.getSeqs().size() == 1 && fr.getSeqs().get(0).getLength() == 0)
465 * POST request has returned an empty FASTA file e.g. for invalid id
467 throw new IOException("No data returned for " + ids);
470 if (fr.getSeqs().size() > 0)
472 AlignmentI seqal = new Alignment(
473 fr.getSeqsAsArray());
474 for (SequenceI sq:seqal.getSequences())
476 if (sq.getDescription() == null)
478 sq.setDescription(getDbName());
480 String name = sq.getName();
481 if (ids.contains(name)
482 || ids.contains(name.replace("ENSP", "ENST")))
484 DBRefUtils.parseToDbRef(sq, DBRefSource.ENSEMBL, "0", name);
487 if (alignment == null)
493 alignment.append(seqal);
500 * Returns the URL for the REST call
503 * @throws MalformedURLException
506 protected URL getUrl(List<String> ids) throws MalformedURLException
509 * a single id is included in the URL path
510 * multiple ids go in the POST body instead
512 StringBuffer urlstring = new StringBuffer(128);
513 urlstring.append(SEQUENCE_ID_URL);
516 urlstring.append("/").append(ids.get(0));
518 // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
519 urlstring.append("?type=").append(getSourceEnsemblType().getType());
520 urlstring.append(("&Accept=text/x-fasta"));
522 URL url = new URL(urlstring.toString());
527 * A sequence/id POST request currently allows up to 50 queries
529 * @see http://rest.ensembl.org/documentation/info/sequence_id_post
532 public int getMaximumQueryCount()
538 protected boolean useGetRequest()
544 protected String getRequestMimeType(boolean multipleIds)
546 return multipleIds ? "application/json" : "text/x-fasta";
550 protected String getResponseMimeType()
552 return "text/x-fasta";
557 * @return the configured sequence return type for this source
559 protected abstract EnsemblSeqType getSourceEnsemblType();
562 * Returns a list of [start, end] genomic ranges corresponding to the sequence
565 * The correspondence between the frames of reference is made by locating
566 * those features on the genomic sequence which identify the retrieved
567 * sequence. Specifically
569 * <li>genomic sequence is identified by "transcript" features with
570 * ID=transcript:transcriptId</li>
571 * <li>cdna sequence is identified by "exon" features with
572 * Parent=transcript:transcriptId</li>
573 * <li>cds sequence is identified by "CDS" features with
574 * Parent=transcript:transcriptId</li>
577 * The returned ranges are sorted to run forwards (for positive strand) or
578 * backwards (for negative strand). Aborts and returns null if both positive
579 * and negative strand are found (this should not normally happen).
581 * @param sourceSequence
584 * the start position of the sequence we are mapping to
587 protected MapList getGenomicRangesFromFeatures(SequenceI sourceSequence,
588 String accId, int start)
590 SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
597 * generously initial size for number of cds regions
598 * (worst case titin Q8WZ42 has c. 313 exons)
600 List<int[]> regions = new ArrayList<int[]>(100);
601 int mappedLength = 0;
602 int direction = 1; // forward
603 boolean directionSet = false;
605 for (SequenceFeature sf : sfs)
608 * accept the target feature type or a specialisation of it
609 * (e.g. coding_exon for exon)
611 if (identifiesSequence(sf, accId))
613 int strand = sf.getStrand();
614 strand = strand == 0 ? 1 : strand; // treat unknown as forward
616 if (directionSet && strand != direction)
618 // abort - mix of forward and backward
619 System.err.println("Error: forward and backward strand for "
627 * add to CDS ranges, semi-sorted forwards/backwards
631 regions.add(0, new int[] { sf.getEnd(), sf.getBegin() });
635 regions.add(new int[] { sf.getBegin(), sf.getEnd() });
637 mappedLength += Math.abs(sf.getEnd() - sf.getBegin() + 1);
642 * 'gene' sequence is contiguous so we can stop as soon as its
643 * identifying feature has been found
650 if (regions.isEmpty())
652 System.out.println("Failed to identify target sequence for " + accId
653 + " from genomic features");
658 * a final sort is needed since Ensembl returns CDS sorted within source
659 * (havana / ensembl_havana)
661 Collections.sort(regions, new RangeSorter(direction == 1));
663 List<int[]> to = Arrays.asList(new int[] { start,
664 start + mappedLength - 1 });
666 return new MapList(regions, to, 1, 1);
670 * Answers true if the sequence being retrieved may occupy discontiguous
671 * regions on the genomic sequence.
673 protected boolean isSpliceable()
679 * Returns true if the sequence feature marks positions of the genomic
680 * sequence feature which are within the sequence being retrieved. For
681 * example, an 'exon' feature whose parent is the target transcript marks the
682 * cdna positions of the transcript.
688 protected abstract boolean identifiesSequence(SequenceFeature sf,
692 * Transfers the sequence feature to the target sequence, locating its start
693 * and end range based on the mapping. Features which do not overlap the
694 * target sequence are ignored.
697 * @param targetSequence
699 * mapping from the sequence feature's coordinates to the target
702 protected void transferFeature(SequenceFeature sf,
703 SequenceI targetSequence, MapList mapping)
705 int start = sf.getBegin();
706 int end = sf.getEnd();
707 int[] mappedRange = mapping.locateInTo(start, end);
709 if (mappedRange != null)
711 SequenceFeature copy = new SequenceFeature(sf);
712 copy.setBegin(Math.min(mappedRange[0], mappedRange[1]));
713 copy.setEnd(Math.max(mappedRange[0], mappedRange[1]));
714 targetSequence.addSequenceFeature(copy);
717 * for sequence_variant, make an additional feature with consequence
719 // if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
720 // SequenceOntologyI.SEQUENCE_VARIANT))
722 // String consequence = (String) sf.getValue(CONSEQUENCE_TYPE);
723 // if (consequence != null)
725 // SequenceFeature sf2 = new SequenceFeature("consequence",
726 // consequence, copy.getBegin(), copy.getEnd(), 0f,
728 // targetSequence.addSequenceFeature(sf2);
735 * Transfers features from sourceSequence to targetSequence
738 * @param sourceSequence
739 * @param targetSequence
740 * @return true if any features were transferred, else false
742 protected boolean transferFeatures(String accessionId,
743 SequenceI sourceSequence, SequenceI targetSequence)
745 if (sourceSequence == null || targetSequence == null)
750 // long start = System.currentTimeMillis();
751 SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
752 MapList mapping = getGenomicRangesFromFeatures(sourceSequence, accessionId,
753 targetSequence.getStart());
759 boolean result = transferFeatures(sfs, targetSequence, mapping,
761 // System.out.println("transferFeatures (" + (sfs.length) + " --> "
762 // + targetSequence.getSequenceFeatures().length + ") to "
763 // + targetSequence.getName()
764 // + " took " + (System.currentTimeMillis() - start) + "ms");
769 * Transfer features to the target sequence. The start/end positions are
770 * converted using the mapping. Features which do not overlap are ignored.
771 * Features whose parent is not the specified identifier are also ignored.
774 * @param targetSequence
779 protected boolean transferFeatures(SequenceFeature[] features,
780 SequenceI targetSequence, MapList mapping, String parentId)
782 final boolean forwardStrand = mapping.isFromForwardStrand();
785 * sort features by start position (descending if reverse strand)
786 * before transferring (in forwards order) to the target sequence
788 Arrays.sort(features, new Comparator<SequenceFeature>()
791 public int compare(SequenceFeature o1, SequenceFeature o2)
793 int c = Integer.compare(o1.getBegin(), o2.getBegin());
794 return forwardStrand ? c : -c;
798 boolean transferred = false;
799 for (SequenceFeature sf : features)
801 if (retainFeature(sf, parentId))
803 transferFeature(sf, targetSequence, mapping);
811 * Answers true if the feature type is one we want to keep for the sequence.
812 * Some features are only retrieved in order to identify the sequence range,
813 * and may then be discarded as redundant information (e.g. "CDS" feature for
816 @SuppressWarnings("unused")
817 protected boolean retainFeature(SequenceFeature sf, String accessionId)
819 return true; // override as required
823 * Answers true if the feature has a Parent which refers to the given
824 * accession id, or if the feature has no parent. Answers false if the
825 * feature's Parent is for a different accession id.
831 protected boolean featureMayBelong(SequenceFeature sf, String identifier)
833 String parent = (String) sf.getValue(PARENT);
834 // using contains to allow for prefix "gene:", "transcript:" etc
835 if (parent != null && !parent.contains(identifier))
837 // this genomic feature belongs to a different transcript
844 public String getDescription()
846 return "Ensembl " + getSourceEnsemblType().getType()
847 + " sequence with variant features";
851 * Returns a (possibly empty) list of features on the sequence which have the
852 * specified sequence ontology type (or a sub-type of it), and the given
853 * identifier as parent
860 protected List<SequenceFeature> findFeatures(SequenceI sequence,
861 String type, String parentId)
863 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
865 SequenceFeature[] sfs = sequence.getSequenceFeatures();
867 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
868 for (SequenceFeature sf :sfs) {
869 if (so.isA(sf.getType(), type))
871 String parent = (String) sf.getValue(PARENT);
872 if (parent.equals(parentId))
883 * Maps exon features from dna to protein, and computes variants in peptide
884 * product generated by variants in dna, and adds them as sequence_variant
885 * features on the protein sequence. Returns the number of variant features
890 * @param dnaToProtein
892 static int computeProteinFeatures(SequenceI dnaSeq,
893 SequenceI peptide, MapList dnaToProtein)
895 while (dnaSeq.getDatasetSequence() != null)
897 dnaSeq = dnaSeq.getDatasetSequence();
899 while (peptide.getDatasetSequence() != null)
901 peptide = peptide.getDatasetSequence();
904 AlignmentUtils.transferFeatures(dnaSeq, peptide, dnaToProtein,
905 SequenceOntologyI.EXON);
907 LinkedHashMap<Integer, String[][]> variants = buildDnaVariantsMap(
908 dnaSeq, dnaToProtein);
911 * scan codon variations, compute peptide variants and add to peptide sequence
914 for (Entry<Integer, String[][]> variant : variants.entrySet())
916 int peptidePos = variant.getKey();
917 String[][] codonVariants = variant.getValue();
918 String residue = String.valueOf(peptide.getCharAt(peptidePos - 1)); // 0-based
919 List<String> peptideVariants = computePeptideVariants(codonVariants,
921 if (!peptideVariants.isEmpty())
923 String desc = StringUtils.listToDelimitedString(peptideVariants,
925 SequenceFeature sf = new SequenceFeature(
926 SequenceOntologyI.SEQUENCE_VARIANT, desc, peptidePos,
927 peptidePos, 0f, null);
928 peptide.addSequenceFeature(sf);
934 * ugly sort to get sequence features in start position order
935 * - would be better to store in Sequence as a TreeSet instead?
937 Arrays.sort(peptide.getSequenceFeatures(),
938 new Comparator<SequenceFeature>()
941 public int compare(SequenceFeature o1, SequenceFeature o2)
943 int c = Integer.compare(o1.getBegin(), o2.getBegin());
944 return c == 0 ? Integer.compare(o1.getEnd(), o2.getEnd())
952 * Builds a map whose key is position in the protein sequence, and value is an
953 * array of all variants for the coding codon positions
956 * @param dnaToProtein
959 static LinkedHashMap<Integer, String[][]> buildDnaVariantsMap(
960 SequenceI dnaSeq, MapList dnaToProtein)
963 * map from peptide position to all variant features of the codon for it
964 * LinkedHashMap ensures we add the peptide features in sequence order
966 LinkedHashMap<Integer, String[][]> variants = new LinkedHashMap<Integer, String[][]>();
967 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
969 SequenceFeature[] dnaFeatures = dnaSeq.getSequenceFeatures();
970 if (dnaFeatures == null)
975 int dnaStart = dnaSeq.getStart();
976 int[] lastCodon = null;
977 int lastPeptidePostion = 0;
980 * build a map of codon variations for peptides
982 for (SequenceFeature sf : dnaFeatures)
984 int dnaCol = sf.getBegin();
985 if (dnaCol != sf.getEnd())
987 // not handling multi-locus variant features
990 if (so.isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT))
992 int[] mapsTo = dnaToProtein.locateInTo(dnaCol, dnaCol);
995 // feature doesn't lie within coding region
998 int peptidePosition = mapsTo[0];
999 String[][] codonVariants = variants.get(peptidePosition);
1000 if (codonVariants == null)
1002 codonVariants = new String[3][];
1003 variants.put(peptidePosition, codonVariants);
1007 * extract dna variants to a string array
1009 String alls = (String) sf.getValue("alleles");
1014 String[] alleles = alls.split(",");
1017 * get this peptides codon positions e.g. [3, 4, 5] or [4, 7, 10]
1019 int[] codon = peptidePosition == lastPeptidePostion ? lastCodon
1020 : MappingUtils.flattenRanges(dnaToProtein.locateInFrom(
1021 peptidePosition, peptidePosition));
1022 lastPeptidePostion = peptidePosition;
1026 * save nucleotide (and this variant) for each codon position
1028 for (int codonPos = 0; codonPos < 3; codonPos++)
1030 String nucleotide = String.valueOf(dnaSeq
1031 .getCharAt(codon[codonPos] - dnaStart));
1032 if (codon[codonPos] == dnaCol)
1035 * record current dna base and its alleles
1037 String[] dnaVariants = new String[alleles.length + 1];
1038 dnaVariants[0] = nucleotide;
1039 System.arraycopy(alleles, 0, dnaVariants, 1, alleles.length);
1040 codonVariants[codonPos] = dnaVariants;
1042 else if (codonVariants[codonPos] == null)
1045 * record current dna base only
1046 * (at least until we find any variation and overwrite it)
1048 codonVariants[codonPos] = new String[] { nucleotide };
1057 * Returns a sorted, non-redundant list of all peptide translations generated
1058 * by the given dna variants, excluding the current residue value
1060 * @param codonVariants
1061 * an array of base values (acgtACGT) for codon positions 1, 2, 3
1063 * the current residue translation
1066 static List<String> computePeptideVariants(
1067 String[][] codonVariants, String residue)
1069 List<String> result = new ArrayList<String>();
1070 for (String base1 : codonVariants[0])
1072 for (String base2 : codonVariants[1])
1074 for (String base3 : codonVariants[2])
1076 String codon = base1 + base2 + base3;
1077 // TODO: report frameshift/insertion/deletion
1078 // and multiple-base variants?!
1079 String peptide = codon.contains("-") ? "-" : ResidueProperties
1080 .codonTranslate(codon);
1081 if (peptide != null && !result.contains(peptide)
1082 && !peptide.equalsIgnoreCase(residue))
1084 result.add(peptide);
1091 * sort alphabetically with STOP at the end
1093 Collections.sort(result, new Comparator<String>()
1097 public int compare(String o1, String o2)
1099 if ("STOP".equals(o1))
1103 else if ("STOP".equals(o2))
1109 return o1.compareTo(o2);
1117 * Answers true if the feature type is either 'NMD_transcript_variant' or
1118 * 'transcript' or one of its sub-types in the Sequence Ontology. This is
1119 * needed because NMD_transcript_variant behaves like 'transcript' in Ensembl
1120 * although strictly speaking it is not (it is a sub-type of
1121 * sequence_variant).
1123 * @param featureType
1126 public static boolean isTranscript(String featureType)
1128 return SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(featureType)
1129 || SequenceOntologyFactory.getInstance().isA(featureType,
1130 SequenceOntologyI.TRANSCRIPT);
1133 public static boolean isTranscriptIdentifier(String query)
1135 return query == null ? false : TRANSCRIPT_REGEX.search(query);