1 package jalview.io.vcf;
3 import htsjdk.samtools.util.CloseableIterator;
4 import htsjdk.variant.variantcontext.Allele;
5 import htsjdk.variant.variantcontext.VariantContext;
6 import htsjdk.variant.vcf.VCFHeader;
7 import htsjdk.variant.vcf.VCFHeaderLine;
8 import htsjdk.variant.vcf.VCFHeaderLineCount;
9 import htsjdk.variant.vcf.VCFHeaderLineType;
10 import htsjdk.variant.vcf.VCFInfoHeaderLine;
12 import jalview.analysis.AlignmentUtils;
13 import jalview.analysis.Dna;
14 import jalview.api.AlignViewControllerGuiI;
15 import jalview.datamodel.AlignmentI;
16 import jalview.datamodel.DBRefEntry;
17 import jalview.datamodel.GeneLociI;
18 import jalview.datamodel.Mapping;
19 import jalview.datamodel.SequenceFeature;
20 import jalview.datamodel.SequenceI;
21 import jalview.datamodel.features.FeatureAttributeType;
22 import jalview.datamodel.features.FeatureSource;
23 import jalview.datamodel.features.FeatureSources;
24 import jalview.ext.ensembl.EnsemblMap;
25 import jalview.ext.htsjdk.VCFReader;
26 import jalview.io.gff.Gff3Helper;
27 import jalview.io.gff.SequenceOntologyI;
28 import jalview.util.MapList;
29 import jalview.util.MappingUtils;
30 import jalview.util.MessageManager;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
37 import java.util.Map.Entry;
40 * A class to read VCF data (using the htsjdk) and add variants as sequence
41 * features on dna and any related protein product sequences
45 public class VCFLoader
48 * keys to fields of VEP CSQ consequence data
49 * see https://www.ensembl.org/info/docs/tools/vep/vep_formats.html
51 private static final String ALLELE_KEY = "Allele";
53 private static final String ALLELE_NUM_KEY = "ALLELE_NUM"; // 0 (ref), 1...
54 private static final String FEATURE_KEY = "Feature"; // Ensembl stable id
57 * what comes before column headings in CSQ Description field
59 private static final String FORMAT = "Format: ";
62 * default VCF INFO key for VEP consequence data
63 * NB this can be overridden running VEP with --vcf_info_field
64 * - we don't handle this case (require identifier to be CSQ)
66 private static final String CSQ_FIELD = "CSQ";
69 * separator for fields in consequence data is '|'
71 private static final String PIPE_REGEX = "\\|";
74 * key for Allele Frequency output by VEP
75 * see http://www.ensembl.org/info/docs/tools/vep/vep_formats.html
77 private static final String ALLELE_FREQUENCY_KEY = "AF";
80 * delimiter that separates multiple consequence data blocks
82 private static final String COMMA = ",";
85 * the feature group assigned to a VCF variant in Jalview
87 private static final String FEATURE_GROUP_VCF = "VCF";
90 * internal delimiter used to build keys for assemblyMappings
93 private static final String EXCL = "!";
96 * the alignment we are associating VCF data with
98 private AlignmentI al;
101 * mappings between VCF and sequence reference assembly regions, as
102 * key = "species!chromosome!fromAssembly!toAssembly
103 * value = Map{fromRange, toRange}
105 private Map<String, Map<int[], int[]>> assemblyMappings;
108 * holds details of the VCF header lines (metadata)
110 private VCFHeader header;
113 * the position (0...) of field in each block of
114 * CSQ (consequence) data (if declared in the VCF INFO header for CSQ)
115 * see http://www.ensembl.org/info/docs/tools/vep/vep_formats.html
117 private int csqAlleleFieldIndex = -1;
118 private int csqAlleleNumberFieldIndex = -1;
119 private int csqFeatureFieldIndex = -1;
122 * a unique identifier under which to save metadata about feature
123 * attributes (selected INFO field data)
125 private String sourceId;
127 List<String> vcfFieldsOfInterest;
129 List<String> vepFieldsOfInterest;
132 * Constructor given an alignment context
136 public VCFLoader(AlignmentI alignment)
140 // map of species!chromosome!fromAssembly!toAssembly to {fromRange, toRange}
141 assemblyMappings = new HashMap<String, Map<int[], int[]>>();
145 * Starts a new thread to query and load VCF variant data on to the alignment
147 * This method is not thread safe - concurrent threads should use separate
148 * instances of this class.
153 public void loadVCF(final String filePath,
154 final AlignViewControllerGuiI gui)
158 gui.setStatus(MessageManager.getString("label.searching_vcf"));
167 VCFLoader.this.doLoad(filePath, gui);
174 * Loads VCF on to an alignment - provided it can be related to one or more
175 * sequence's chromosomal coordinates
179 * optional callback handler for messages
181 protected void doLoad(String filePath, AlignViewControllerGuiI gui)
183 VCFReader reader = null;
186 // long start = System.currentTimeMillis();
187 reader = new VCFReader(filePath);
189 header = reader.getFileHeader();
193 saveMetadata(sourceId);
196 * get offset of CSQ ALLELE_NUM and Feature if declared
200 VCFHeaderLine ref = header
201 .getOtherHeaderLine(VCFHeader.REFERENCE_KEY);
202 String vcfAssembly = ref.getValue();
208 * query for VCF overlapping each sequence in turn
210 for (SequenceI seq : al.getSequences())
212 int added = loadSequenceVCF(seq, reader, vcfAssembly);
217 transferAddedFeatures(seq);
222 // long elapsed = System.currentTimeMillis() - start;
223 String msg = MessageManager.formatMessage("label.added_vcf",
226 if (gui.getFeatureSettingsUI() != null)
228 gui.getFeatureSettingsUI().discoverAllFeatureData();
231 } catch (Throwable e)
233 System.err.println("Error processing VCF: " + e.getMessage());
237 gui.setStatus("Error occurred - see console for details");
246 } catch (IOException e)
255 * Reads metadata (such as INFO field descriptions and datatypes) and saves
256 * them for future reference
260 void saveMetadata(String theSourceId)
262 vcfFieldsOfInterest = new ArrayList<>();
264 FeatureSource metadata = new FeatureSource(theSourceId);
266 for (VCFInfoHeaderLine info : header.getInfoHeaderLines())
268 String attributeId = info.getID();
269 String desc = info.getDescription();
270 VCFHeaderLineType type = info.getType();
271 FeatureAttributeType attType = null;
275 attType = FeatureAttributeType.Character;
278 attType = FeatureAttributeType.Flag;
281 attType = FeatureAttributeType.Float;
284 attType = FeatureAttributeType.Integer;
287 attType = FeatureAttributeType.String;
290 metadata.setAttributeName(attributeId, desc);
291 metadata.setAttributeType(attributeId, attType);
293 if (isVcfFieldWanted(attributeId))
295 vcfFieldsOfInterest.add(attributeId);
299 FeatureSources.getInstance().addSource(theSourceId, metadata);
303 * Answers true if the VCF id is one we wish to capture in Jalview, else false
308 private boolean isVcfFieldWanted(String id)
310 // TODO option to match patterns in a Preferences entry?
315 * Answers true if the VEP (CSQ) id is one we wish to capture in Jalview, else
321 private boolean isVepFieldWanted(String id)
323 // TODO option to match patterns in a Preferences entry?
328 * Records the position of selected fields defined in the CSQ INFO header (if
329 * there is one). CSQ fields are declared in the CSQ INFO Description e.g.
331 * Description="Consequence ...from ... VEP. Format: Allele|Consequence|...
333 protected void locateCsqFields()
335 vepFieldsOfInterest = new ArrayList<>();
337 VCFInfoHeaderLine csqInfo = header.getInfoHeaderLine(CSQ_FIELD);
343 String desc = csqInfo.getDescription();
344 int formatPos = desc.indexOf(FORMAT);
347 System.err.println("Parse error, failed to find " + FORMAT
351 desc = desc.substring(formatPos + FORMAT.length());
355 String[] format = desc.split(PIPE_REGEX);
357 for (String field : format)
359 if (ALLELE_NUM_KEY.equals(field))
361 csqAlleleNumberFieldIndex = index;
363 if (ALLELE_KEY.equals(field))
365 csqAlleleFieldIndex = index;
367 if (FEATURE_KEY.equals(field))
369 csqFeatureFieldIndex = index;
372 if (isVepFieldWanted(field))
374 vepFieldsOfInterest.add(field);
383 * Transfers VCF features to sequences to which this sequence has a mapping.
384 * If the mapping is 3:1, computes peptide variants from nucleotide variants.
388 protected void transferAddedFeatures(SequenceI seq)
390 DBRefEntry[] dbrefs = seq.getDBRefs();
395 for (DBRefEntry dbref : dbrefs)
397 Mapping mapping = dbref.getMap();
398 if (mapping == null || mapping.getTo() == null)
403 SequenceI mapTo = mapping.getTo();
404 MapList map = mapping.getMap();
405 if (map.getFromRatio() == 3)
408 * dna-to-peptide product mapping
410 AlignmentUtils.computeProteinFeatures(seq, mapTo, map);
415 * nucleotide-to-nucleotide mapping e.g. transcript to CDS
417 List<SequenceFeature> features = seq.getFeatures()
418 .getPositionalFeatures(SequenceOntologyI.SEQUENCE_VARIANT);
419 for (SequenceFeature sf : features)
421 if (FEATURE_GROUP_VCF.equals(sf.getFeatureGroup()))
423 transferFeature(sf, mapTo, map);
431 * Tries to add overlapping variants read from a VCF file to the given
432 * sequence, and returns the number of variant features added. Note that this
433 * requires the sequence to hold information as to its species, chromosomal
434 * positions and reference assembly, in order to be able to map the VCF
435 * variants to the sequence (or not)
442 protected int loadSequenceVCF(SequenceI seq, VCFReader reader,
446 GeneLociI seqCoords = seq.getGeneLoci();
447 if (seqCoords == null)
449 System.out.println(String.format(
450 "Can't query VCF for %s as chromosome coordinates not known",
455 if (!vcfSpeciesMatchesSequence(vcfAssembly, seqCoords.getSpeciesId()))
460 List<int[]> seqChromosomalContigs = seqCoords.getMap().getToRanges();
461 for (int[] range : seqChromosomalContigs)
463 count += addVcfVariants(seq, reader, range, vcfAssembly);
470 * Answers true if the species inferred from the VCF reference identifier
471 * matches that for the sequence
477 boolean vcfSpeciesMatchesSequence(String vcfAssembly, String speciesId)
480 // there are many aliases for species - how to equate one with another?
482 // VCF ##reference header is an unstructured URI - how to extract species?
483 // perhaps check if ref includes any (Ensembl) alias of speciesId??
484 // TODO ask the user to confirm this??
486 if (vcfAssembly.contains("Homo_sapiens") // gnomAD exome data example
487 && "HOMO_SAPIENS".equals(speciesId)) // Ensembl species id
492 if (vcfAssembly.contains("c_elegans") // VEP VCF response example
493 && "CAENORHABDITIS_ELEGANS".equals(speciesId)) // Ensembl
498 // this is not a sustainable solution...
504 * Queries the VCF reader for any variants that overlap the given chromosome
505 * region of the sequence, and adds as variant features. Returns the number of
506 * overlapping variants found.
511 * start-end range of a sequence region in its chromosomal
514 * the '##reference' identifier for the VCF reference assembly
517 protected int addVcfVariants(SequenceI seq, VCFReader reader,
518 int[] range, String vcfAssembly)
520 GeneLociI seqCoords = seq.getGeneLoci();
522 String chromosome = seqCoords.getChromosomeId();
523 String seqRef = seqCoords.getAssemblyId();
524 String species = seqCoords.getSpeciesId();
527 * map chromosomal coordinates from sequence to VCF if the VCF
528 * data has a different reference assembly to the sequence
530 // TODO generalise for non-human species
531 // - or get the user to choose in a dialog
534 if ("GRCh38".equalsIgnoreCase(seqRef) // Ensembl
535 && vcfAssembly.contains("Homo_sapiens_assembly19")) // gnomAD
537 String toRef = "GRCh37";
538 int[] newRange = mapReferenceRange(range, chromosome, "human",
540 if (newRange == null)
542 System.err.println(String.format(
543 "Failed to map %s:%s:%s:%d:%d to %s", species, chromosome,
544 seqRef, range[0], range[1], toRef));
547 offset = newRange[0] - range[0];
551 boolean forwardStrand = range[0] <= range[1];
554 * query the VCF for overlaps
555 * (convert a reverse strand range to forwards)
558 MapList mapping = seqCoords.getMap();
560 int fromLocus = Math.min(range[0], range[1]);
561 int toLocus = Math.max(range[0], range[1]);
562 CloseableIterator<VariantContext> variants = reader.query(chromosome,
564 while (variants.hasNext())
567 * get variant location in sequence chromosomal coordinates
569 VariantContext variant = variants.next();
571 int start = variant.getStart() - offset;
572 int end = variant.getEnd() - offset;
575 * convert chromosomal location to sequence coordinates
576 * - may be reverse strand (convert to forward for sequence feature)
577 * - null if a partially overlapping feature
579 int[] seqLocation = mapping.locateInFrom(start, end);
580 if (seqLocation != null)
582 int featureStart = Math.min(seqLocation[0], seqLocation[1]);
583 int featureEnd = Math.max(seqLocation[0], seqLocation[1]);
584 count += addAlleleFeatures(seq, variant, featureStart, featureEnd,
595 * A convenience method to get the AF value for the given alternate allele
602 protected float getAlleleFrequency(VariantContext variant, int alleleIndex)
605 String attributeValue = getAttributeValue(variant,
606 ALLELE_FREQUENCY_KEY, alleleIndex);
607 if (attributeValue != null)
611 score = Float.parseFloat(attributeValue);
612 } catch (NumberFormatException e)
622 * A convenience method to get an attribute value for an alternate allele
625 * @param attributeName
629 protected String getAttributeValue(VariantContext variant,
630 String attributeName, int alleleIndex)
632 Object att = variant.getAttribute(attributeName);
634 if (att instanceof String)
638 else if (att instanceof ArrayList)
640 return ((List<String>) att).get(alleleIndex);
647 * Adds one variant feature for each allele in the VCF variant record, and
648 * returns the number of features added.
652 * @param featureStart
654 * @param forwardStrand
657 protected int addAlleleFeatures(SequenceI seq, VariantContext variant,
658 int featureStart, int featureEnd, boolean forwardStrand)
663 * Javadoc says getAlternateAlleles() imposes no order on the list returned
664 * so we proceed defensively to get them in strict order
666 int altAlleleCount = variant.getAlternateAlleles().size();
667 for (int i = 0; i < altAlleleCount; i++)
669 added += addAlleleFeature(seq, variant, i, featureStart, featureEnd,
676 * Inspects one allele and attempts to add a variant feature for it to the
677 * sequence. We extract as much as possible of the additional data associated
678 * with this allele to store in the feature's key-value map. Answers the
679 * number of features added (0 or 1).
683 * @param altAlleleIndex
685 * @param featureStart
687 * @param forwardStrand
690 protected int addAlleleFeature(SequenceI seq, VariantContext variant,
691 int altAlleleIndex, int featureStart, int featureEnd,
692 boolean forwardStrand)
694 String reference = variant.getReference().getBaseString();
695 Allele alt = variant.getAlternateAllele(altAlleleIndex);
696 String allele = alt.getBaseString();
699 * build the ref,alt allele description e.g. "G,A", using the base
700 * complement if the sequence is on the reverse strand
702 // TODO check how structural variants are shown on reverse strand
703 StringBuilder sb = new StringBuilder();
704 sb.append(forwardStrand ? reference : Dna.reverseComplement(reference));
706 sb.append(forwardStrand ? allele : Dna.reverseComplement(allele));
707 String alleles = sb.toString(); // e.g. G,A
709 String type = SequenceOntologyI.SEQUENCE_VARIANT;
710 float score = getAlleleFrequency(variant, altAlleleIndex);
712 SequenceFeature sf = new SequenceFeature(type, alleles, featureStart,
713 featureEnd, score, FEATURE_GROUP_VCF);
714 sf.setSource(sourceId);
716 sf.setValue(Gff3Helper.ALLELES, alleles);
718 addAlleleProperties(variant, seq, sf, altAlleleIndex);
720 seq.addSequenceFeature(sf);
726 * Add any allele-specific VCF key-value data to the sequence feature
731 * @param altAlelleIndex
734 protected void addAlleleProperties(VariantContext variant, SequenceI seq,
735 SequenceFeature sf, final int altAlelleIndex)
737 Map<String, Object> atts = variant.getAttributes();
739 for (Entry<String, Object> att : atts.entrySet())
741 String key = att.getKey();
744 * extract Consequence data (if present) that we are able to
745 * associated with the allele for this variant feature
747 if (CSQ_FIELD.equals(key))
749 addConsequences(variant, seq, sf, altAlelleIndex);
754 * filter out fields we don't want to capture
756 if (!vcfFieldsOfInterest.contains(key))
762 * we extract values for other data which are allele-specific;
763 * these may be per alternate allele (INFO[key].Number = 'A')
764 * or per allele including reference (INFO[key].Number = 'R')
766 VCFInfoHeaderLine infoHeader = header.getInfoHeaderLine(key);
767 if (infoHeader == null)
770 * can't be sure what data belongs to this allele, so
771 * play safe and don't take any
776 VCFHeaderLineCount number = infoHeader.getCountType();
777 int index = altAlelleIndex;
778 if (number == VCFHeaderLineCount.R)
781 * one value per allele including reference, so bump index
782 * e.g. the 3rd value is for the 2nd alternate allele
786 else if (number != VCFHeaderLineCount.A)
789 * don't save other values as not allele-related
795 * take the index'th value
797 String value = getAttributeValue(variant, key, index);
800 sf.setValue(key, value);
806 * Inspects CSQ data blocks (consequences) and adds attributes on the sequence
807 * feature for the current allele (and transcript if applicable)
809 * Allele matching: if field ALLELE_NUM is present, it must match
810 * altAlleleIndex. If not present, then field Allele value must match the VCF
813 * Transcript matching: if sequence name can be identified to at least one of
814 * the consequences' Feature values, then select only consequences that match
815 * the value (i.e. consequences for the current transcript sequence). If not,
816 * take all consequences (this is the case when adding features to the gene
822 * @param altAlelleIndex
825 protected void addConsequences(VariantContext variant, SequenceI seq,
826 SequenceFeature sf, int altAlelleIndex)
828 Object value = variant.getAttribute(CSQ_FIELD);
830 if (value == null || !(value instanceof ArrayList<?>))
835 List<String> consequences = (List<String>) value;
838 * if CSQ data includes 'Feature', and any value matches the sequence name,
839 * then restrict consequence data to only the matching value (transcript)
840 * i.e. just pick out consequences for the transcript the variant feature is on
842 String seqName = seq.getName()== null ? "" : seq.getName().toLowerCase();
843 String matchFeature = null;
844 if (csqFeatureFieldIndex > -1)
846 for (String consequence : consequences)
848 String[] csqFields = consequence.split(PIPE_REGEX);
849 if (csqFields.length > csqFeatureFieldIndex)
851 String featureIdentifier = csqFields[csqFeatureFieldIndex];
852 if (featureIdentifier.length() > 4
853 && seqName.indexOf(featureIdentifier.toLowerCase()) > -1)
855 matchFeature = featureIdentifier;
861 StringBuilder sb = new StringBuilder(128);
862 boolean found = false;
864 // todo check against vepFieldsOfInterest as well somewhere
866 for (String consequence : consequences)
868 String[] csqFields = consequence.split(PIPE_REGEX);
870 if (includeConsequence(csqFields, matchFeature, variant,
878 sb.append(consequence);
884 sf.setValue(CSQ_FIELD, sb.toString());
889 * Answers true if we want to associate this block of consequence data with
890 * the specified alternate allele of the VCF variant.
892 * If consequence data includes the ALLELE_NUM field, then this has to match
893 * altAlleleIndex. Otherwise the Allele field of the consequence data has to
894 * match the allele value.
896 * Optionally (if matchFeature is not null), restrict to only include
897 * consequences whose Feature value matches. This allows us to attach
898 * consequences to their respective transcripts.
901 * @param matchFeature
903 * @param altAlelleIndex
907 protected boolean includeConsequence(String[] csqFields,
908 String matchFeature, VariantContext variant, int altAlelleIndex)
911 * check consequence is for the current transcript
913 if (matchFeature != null)
915 if (csqFields.length <= csqFeatureFieldIndex)
919 String featureIdentifier = csqFields[csqFeatureFieldIndex];
920 if (!featureIdentifier.equals(matchFeature))
922 return false; // consequence is for a different transcript
927 * if ALLELE_NUM is present, it must match altAlleleIndex
928 * NB first alternate allele is 1 for ALLELE_NUM, 0 for altAlleleIndex
930 if (csqAlleleNumberFieldIndex > -1)
932 if (csqFields.length <= csqAlleleNumberFieldIndex)
936 String alleleNum = csqFields[csqAlleleNumberFieldIndex];
937 return String.valueOf(altAlelleIndex + 1).equals(alleleNum);
941 * else consequence allele must match variant allele
943 if (csqAlleleFieldIndex > -1 && csqFields.length > csqAlleleFieldIndex)
945 String csqAllele = csqFields[csqAlleleFieldIndex];
946 String vcfAllele = variant.getAlternateAllele(altAlelleIndex)
948 return csqAllele.equals(vcfAllele);
955 * A convenience method to complement a dna base and return the string value
961 protected String complement(byte[] reference)
963 return String.valueOf(Dna.getComplement((char) reference[0]));
967 * Determines the location of the query range (chromosome positions) in a
968 * different reference assembly.
970 * If the range is just a subregion of one for which we already have a mapping
971 * (for example, an exon sub-region of a gene), then the mapping is just
972 * computed arithmetically.
974 * Otherwise, calls the Ensembl REST service that maps from one assembly
975 * reference's coordinates to another's
978 * start-end chromosomal range in 'fromRef' coordinates
982 * assembly reference for the query coordinates
984 * assembly reference we wish to translate to
985 * @return the start-end range in 'toRef' coordinates
987 protected int[] mapReferenceRange(int[] queryRange, String chromosome,
988 String species, String fromRef, String toRef)
991 * first try shorcut of computing the mapping as a subregion of one
992 * we already have (e.g. for an exon, if we have the gene mapping)
994 int[] mappedRange = findSubsumedRangeMapping(queryRange, chromosome,
995 species, fromRef, toRef);
996 if (mappedRange != null)
1002 * call (e.g.) http://rest.ensembl.org/map/human/GRCh38/17:45051610..45109016:1/GRCh37
1004 EnsemblMap mapper = new EnsemblMap();
1005 int[] mapping = mapper.getAssemblyMapping(species, chromosome, fromRef,
1008 if (mapping == null)
1010 // mapping service failure
1015 * save mapping for possible future re-use
1017 String key = makeRangesKey(chromosome, species, fromRef, toRef);
1018 if (!assemblyMappings.containsKey(key))
1020 assemblyMappings.put(key, new HashMap<int[], int[]>());
1023 assemblyMappings.get(key).put(queryRange, mapping);
1029 * If we already have a 1:1 contiguous mapping which subsumes the given query
1030 * range, this method just calculates and returns the subset of that mapping,
1031 * else it returns null. In practical terms, if a gene has a contiguous
1032 * mapping between (for example) GRCh37 and GRCh38, then we assume that its
1033 * subsidiary exons occupy unchanged relative positions, and just compute
1034 * these as offsets, rather than do another lookup of the mapping.
1036 * If in future these assumptions prove invalid (e.g. for bacterial dna?!),
1037 * simply remove this method or let it always return null.
1039 * Warning: many rapid calls to the /map service map result in a 429 overload
1049 protected int[] findSubsumedRangeMapping(int[] queryRange, String chromosome,
1050 String species, String fromRef, String toRef)
1052 String key = makeRangesKey(chromosome, species, fromRef, toRef);
1053 if (assemblyMappings.containsKey(key))
1055 Map<int[], int[]> mappedRanges = assemblyMappings.get(key);
1056 for (Entry<int[], int[]> mappedRange : mappedRanges.entrySet())
1058 int[] fromRange = mappedRange.getKey();
1059 int[] toRange = mappedRange.getValue();
1060 if (fromRange[1] - fromRange[0] == toRange[1] - toRange[0])
1063 * mapping is 1:1 in length, so we trust it to have no discontinuities
1065 if (MappingUtils.rangeContains(fromRange, queryRange))
1068 * fromRange subsumes our query range
1070 int offset = queryRange[0] - fromRange[0];
1071 int mappedRangeFrom = toRange[0] + offset;
1072 int mappedRangeTo = mappedRangeFrom + (queryRange[1] - queryRange[0]);
1073 return new int[] { mappedRangeFrom, mappedRangeTo };
1082 * Transfers the sequence feature to the target sequence, locating its start
1083 * and end range based on the mapping. Features which do not overlap the
1084 * target sequence are ignored.
1087 * @param targetSequence
1089 * mapping from the feature's coordinates to the target sequence
1091 protected void transferFeature(SequenceFeature sf,
1092 SequenceI targetSequence, MapList mapping)
1094 int[] mappedRange = mapping.locateInTo(sf.getBegin(), sf.getEnd());
1096 if (mappedRange != null)
1098 String group = sf.getFeatureGroup();
1099 int newBegin = Math.min(mappedRange[0], mappedRange[1]);
1100 int newEnd = Math.max(mappedRange[0], mappedRange[1]);
1101 SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd,
1102 group, sf.getScore());
1103 targetSequence.addSequenceFeature(copy);
1108 * Formats a ranges map lookup key
1116 protected static String makeRangesKey(String chromosome, String species,
1117 String fromRef, String toRef)
1119 return species + EXCL + chromosome + EXCL + fromRef + EXCL