import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.SequenceFeatures;
import jalview.exceptions.JalviewException;
import jalview.io.FastaFile;
import jalview.io.FileParse;
import jalview.io.gff.SequenceOntologyI;
import jalview.util.Comparison;
import jalview.util.DBRefUtils;
+import jalview.util.IntRangeComparator;
import jalview.util.MapList;
-import jalview.util.RangeComparator;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
/**
{
private static final String ALLELES = "alleles";
- protected static final String PARENT = "Parent";
-
- protected static final String ID = "ID";
-
protected static final String NAME = "Name";
protected static final String DESCRIPTION = "description";
try
{
/*
- * get 'dummy' genomic sequence with exon, cds and variation features
+ * get 'dummy' genomic sequence with gene, transcript,
+ * exon, cds and variation features
*/
SequenceI genomicSequence = null;
EnsemblFeatures gffFetcher = new EnsemblFeatures(getDomain());
/*
* transfer features to the query sequence
*/
- SequenceI querySeq = alignment.findName(accId);
+ SequenceI querySeq = alignment.findName(accId, true);
if (transferFeatures(accId, genomicSequence, querySeq))
{
urlstring.append("?type=").append(getSourceEnsemblType().getType());
urlstring.append(("&Accept=text/x-fasta"));
+ String objectType = getObjectType();
+ if (objectType != null)
+ {
+ urlstring.append("&").append(OBJECT_TYPE).append("=")
+ .append(objectType);
+ }
+
URL url = new URL(urlstring.toString());
return url;
}
/**
+ * Override this method to specify object_type request parameter
+ *
+ * @return
+ */
+ protected String getObjectType()
+ {
+ return null;
+ }
+
+ /**
* A sequence/id POST request currently allows up to 50 queries
*
* @see http://rest.ensembl.org/documentation/info/sequence_id_post
protected MapList getGenomicRangesFromFeatures(SequenceI sourceSequence,
String accId, int start)
{
- SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
- if (sfs == null)
+ List<SequenceFeature> sfs = sourceSequence.getFeatures()
+ .getPositionalFeatures();
+ if (sfs.isEmpty())
{
return null;
}
* generously initial size for number of cds regions
* (worst case titin Q8WZ42 has c. 313 exons)
*/
- List<int[]> regions = new ArrayList<int[]>(100);
+ List<int[]> regions = new ArrayList<>(100);
int mappedLength = 0;
int direction = 1; // forward
boolean directionSet = false;
* a final sort is needed since Ensembl returns CDS sorted within source
* (havana / ensembl_havana)
*/
- Collections.sort(regions, new RangeComparator(direction == 1));
+ Collections.sort(regions, direction == 1 ? IntRangeComparator.ASCENDING
+ : IntRangeComparator.DESCENDING);
List<int[]> to = Arrays
.asList(new int[]
if (mappedRange != null)
{
- SequenceFeature copy = new SequenceFeature(sf);
- copy.setBegin(Math.min(mappedRange[0], mappedRange[1]));
- copy.setEnd(Math.max(mappedRange[0], mappedRange[1]));
- if (".".equals(copy.getFeatureGroup()))
+ String group = sf.getFeatureGroup();
+ if (".".equals(group))
{
- copy.setFeatureGroup(getDbSource());
+ group = getDbSource();
}
+ int newBegin = Math.min(mappedRange[0], mappedRange[1]);
+ int newEnd = Math.max(mappedRange[0], mappedRange[1]);
+ SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd,
+ group, sf.getScore());
targetSequence.addSequenceFeature(copy);
/*
return false;
}
- // long start = System.currentTimeMillis();
- SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
+// long start = System.currentTimeMillis();
+ List<SequenceFeature> sfs = sourceSequence.getFeatures()
+ .getPositionalFeatures();
MapList mapping = getGenomicRangesFromFeatures(sourceSequence,
accessionId, targetSequence.getStart());
if (mapping == null)
boolean result = transferFeatures(sfs, targetSequence, mapping,
accessionId);
- // System.out.println("transferFeatures (" + (sfs.length) + " --> "
- // + targetSequence.getSequenceFeatures().length + ") to "
- // + targetSequence.getName()
- // + " took " + (System.currentTimeMillis() - start) + "ms");
+// System.out.println("transferFeatures (" + (sfs.size()) + " --> "
+// + targetSequence.getFeatures().getFeatureCount(true) + ") to "
+// + targetSequence.getName() + " took "
+// + (System.currentTimeMillis() - start) + "ms");
return result;
}
* converted using the mapping. Features which do not overlap are ignored.
* Features whose parent is not the specified identifier are also ignored.
*
- * @param features
+ * @param sfs
* @param targetSequence
* @param mapping
* @param parentId
* @return
*/
- protected boolean transferFeatures(SequenceFeature[] features,
+ protected boolean transferFeatures(List<SequenceFeature> sfs,
SequenceI targetSequence, MapList mapping, String parentId)
{
final boolean forwardStrand = mapping.isFromForwardStrand();
* position descending if reverse strand) so as to add them in
* 'forwards' order to the target sequence
*/
- sortFeatures(features, forwardStrand);
+ SequenceFeatures.sortFeatures(sfs, forwardStrand);
boolean transferred = false;
- for (SequenceFeature sf : features)
+ for (SequenceFeature sf : sfs)
{
if (retainFeature(sf, parentId))
{
}
/**
- * Sort features by start position ascending (if on forward strand), or end
- * position descending (if on reverse strand)
- *
- * @param features
- * @param forwardStrand
- */
- protected static void sortFeatures(SequenceFeature[] features,
- final boolean forwardStrand)
- {
- Arrays.sort(features, new Comparator<SequenceFeature>()
- {
- @Override
- public int compare(SequenceFeature o1, SequenceFeature o2)
- {
- if (forwardStrand)
- {
- return Integer.compare(o1.getBegin(), o2.getBegin());
- }
- else
- {
- return Integer.compare(o2.getEnd(), o1.getEnd());
- }
- }
- });
- }
-
- /**
* Answers true if the feature type is one we want to keep for the sequence.
* Some features are only retrieved in order to identify the sequence range,
* and may then be discarded as redundant information (e.g. "CDS" feature for
{
String parent = (String) sf.getValue(PARENT);
// using contains to allow for prefix "gene:", "transcript:" etc
- if (parent != null && !parent.contains(identifier))
+ if (parent != null
+ && !parent.toUpperCase().contains(identifier.toUpperCase()))
{
// this genomic feature belongs to a different transcript
return false;
/**
* Returns a (possibly empty) list of features on the sequence which have the
- * specified sequence ontology type (or a sub-type of it), and the given
+ * specified sequence ontology term (or a sub-type of it), and the given
* identifier as parent
*
* @param sequence
- * @param type
+ * @param term
* @param parentId
* @return
*/
protected List<SequenceFeature> findFeatures(SequenceI sequence,
- String type, String parentId)
+ String term, String parentId)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
- SequenceFeature[] sfs = sequence.getSequenceFeatures();
- if (sfs != null)
+ List<SequenceFeature> sfs = sequence.getFeatures()
+ .getFeaturesByOntology(term);
+ for (SequenceFeature sf : sfs)
{
- SequenceOntologyI so = SequenceOntologyFactory.getInstance();
- for (SequenceFeature sf : sfs)
+ String parent = (String) sf.getValue(PARENT);
+ if (parent != null && parent.equalsIgnoreCase(parentId))
{
- if (so.isA(sf.getType(), type))
- {
- String parent = (String) sf.getValue(PARENT);
- if (parent.equals(parentId))
- {
- result.add(sf);
- }
- }
+ result.add(sf);
}
}
+
return result;
}