Search in sources :

Example 1 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class ICESBOLParserVisitor method createDNAFeature.

static DNAFeature createDNAFeature(SequenceAnnotation annotation, Pair pair) {
    DNAFeature feature = new DNAFeature();
    // set feature location
    DNAFeatureLocation location = new DNAFeatureLocation();
    location.setGenbankStart(pair.getFirst());
    location.setEnd(pair.getSecond());
    // get sequence strand type and uri
    feature.setStrand(pair.getStrand());
    feature.setUri(annotation.getURI().toString());
    // get sequence annotation type and start and end sequence
    DnaComponent subComponent = annotation.getSubComponent();
    if (subComponent != null) {
        location.setUri(subComponent.getURI().toString());
        String name = subComponent.getName();
        if (name == null || name.trim().isEmpty())
            name = subComponent.getDisplayId();
        feature.setName(name);
        feature.setIdentifier(subComponent.getDisplayId());
        String featureType = getFeatureType(subComponent.getTypes());
        feature.setType(featureType);
    }
    feature.getLocations().add(location);
    return feature;
}
Also used : DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) DnaComponent(org.sbolstandard.core.DnaComponent)

Example 2 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class ICESBOLParserVisitor method walkTree.

private void walkTree(SequenceAnnotation parent, Pair relativePair) {
    List<SequenceAnnotation> annotations = parent.getSubComponent().getAnnotations();
    if (!annotations.isEmpty()) {
        for (SequenceAnnotation sequenceAnnotation : annotations) {
            int strand;
            if (sequenceAnnotation.getStrand() == null) {
                strand = relativePair.getStrand();
            } else {
                strand = sequenceAnnotation.getStrand() == StrandType.POSITIVE ? relativePair.getStrand() : relativePair.getStrand() * -1;
            }
            Pair newRelativePair;
            if (strand > 0)
                newRelativePair = calculatePairForPositiveStrand(sequenceAnnotation, relativePair);
            else
                newRelativePair = calculatePairForNegativeStrand(sequenceAnnotation, relativePair);
            walkTree(sequenceAnnotation, newRelativePair);
            DNAFeature feature = createDNAFeature(sequenceAnnotation, newRelativePair);
            DNAFeatureLocation location = feature.getLocations().get(0);
            featuredDNASequence.getFeatures().add(feature);
            Logger.debug("Adding feature " + strand + "[" + location.getGenbankStart() + ", " + location.getEnd() + "] for " + feature.getIdentifier());
        }
    }
}
Also used : DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) SequenceAnnotation(org.sbolstandard.core.SequenceAnnotation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 3 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class Annotations method generate.

/**
     * Using existing and potentially curated annotations on this ICE instance,
     * this generates matching features for the passed sequence
     *
     * @param sequence wrapper around dna sequence
     * @return wrapper around passed sequence and now with list if annotations for that sequence
     */
public FeaturedDNASequence generate(FeaturedDNASequence sequence) {
    BlastQuery query = new BlastQuery();
    query.setSequence(sequence.getSequence());
    try {
        List<DNAFeature> features = BlastPlus.runCheckFeatures(query);
        sequence.getFeatures().addAll(features);
        return sequence;
    } catch (BlastException e) {
        Logger.error(e);
        return null;
    }
}
Also used : BlastQuery(org.jbei.ice.lib.dto.search.BlastQuery) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) BlastException(org.jbei.ice.lib.search.blast.BlastException)

Example 4 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class BlastPlus method processFeaturesBlastOutput.

/**
     * Process the output of the blast run for features
     * into a list of feature objects
     * <br>
     * Expected format for the output (per line) is
     * <code>feature_id, label, type, qstart, qend, sstart, send, sstrand</code>
     * Therefore line[0] is feature_id, line[1] is label etc
     * <br>Since we are only interested in features that have a full match (covers entire feature) some matches are
     * manually eliminated. The results returned by blast can cover only a subset of the sequence. e.g.
     * given query = 'ATGC' and feature1 = 'ATG' and feature2 = 'TATGT', the query will return
     * 1,3,1,3 and 1,3,2,4.
     *
     * @param blastOutput blast program output
     * @return list of feature objects resulting from processing the blast output
     */
public static List<DNAFeature> processFeaturesBlastOutput(String blastOutput) {
    List<DNAFeature> hashMap = new ArrayList<>();
    HashSet<String> duplicates = new HashSet<>();
    try (CSVReader reader = new CSVReader(new StringReader(blastOutput))) {
        List<String[]> lines = reader.readAll();
        for (String[] line : lines) {
            if (line.length != 9) {
                continue;
            }
            long id = Long.decode(line[0]);
            String label = line[1];
            String type = line[2];
            int strand = Integer.decode(line[3]);
            int queryStart = Integer.decode(line[4]);
            int queryEnd = Integer.decode(line[5]);
            int subjectStart = Integer.decode(line[6]);
            int subjectEnd = Integer.decode(line[7]);
            if (!duplicates.add(label + ":" + queryStart + ":" + queryEnd + ":" + strand)) {
                continue;
            }
            if (subjectStart != 1 && (queryEnd - queryStart) + 1 != subjectEnd)
                continue;
            // check for full feature coverage
            DNAFeature dnaFeature = new DNAFeature();
            dnaFeature.setId(id);
            dnaFeature.setName(label);
            dnaFeature.setType(type);
            DNAFeatureLocation location = new DNAFeatureLocation();
            location.setGenbankStart(queryStart);
            location.setEnd(queryEnd);
            dnaFeature.getLocations().add(location);
            dnaFeature.setStrand(strand);
            hashMap.add(dnaFeature);
        }
        return hashMap;
    } catch (IOException e) {
        Logger.error(e);
        return null;
    }
}
Also used : CSVReader(com.opencsv.CSVReader) DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 5 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class AnnotationResource method curate.

/**
     * Curate available annotations to include or exclude them from auto-annotation feature
     *
     * @param list list of annotations each with specified curate
     */
@PUT
@Produces(MediaType.APPLICATION_JSON)
public Response curate(List<DNAFeature> list) {
    String userId = requireUserId();
    Annotations annotations = new Annotations(userId);
    try {
        final Type fooType = new TypeToken<ArrayList<DNAFeature>>() {
        }.getType();
        final Gson gson = new GsonBuilder().create();
        final ArrayList<DNAFeature> features = gson.fromJson(gson.toJsonTree(list), fooType);
        annotations.curate(features);
        return super.respond(true);
    } catch (PermissionException e) {
        Logger.error(e);
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) Annotations(org.jbei.ice.lib.entry.sequence.annotation.Annotations) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Aggregations

DNAFeature (org.jbei.ice.lib.dto.DNAFeature)13 DNAFeatureLocation (org.jbei.ice.lib.dto.DNAFeatureLocation)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 ArrayList (java.util.ArrayList)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 Results (org.jbei.ice.lib.dto.common.Results)2 BlastQuery (org.jbei.ice.lib.dto.search.BlastQuery)2 BlastException (org.jbei.ice.lib.search.blast.BlastException)2 SequenceAnnotation (org.sbolstandard.core.SequenceAnnotation)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 CSVReader (com.opencsv.CSVReader)1 Type (java.lang.reflect.Type)1 List (java.util.List)1 MediaType (javax.ws.rs.core.MediaType)1 Curation (org.jbei.ice.lib.dto.Curation)1 DNAFeatures (org.jbei.ice.lib.dto.DNAFeatures)1 DNASequence (org.jbei.ice.lib.dto.DNASequence)1 Annotations (org.jbei.ice.lib.entry.sequence.annotation.Annotations)1 GroupController (org.jbei.ice.lib.group.GroupController)1