Search in sources :

Example 1 with DNAFeatureLocation

use of org.jbei.ice.lib.dto.DNAFeatureLocation 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 DNAFeatureLocation

use of org.jbei.ice.lib.dto.DNAFeatureLocation 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 DNAFeatureLocation

use of org.jbei.ice.lib.dto.DNAFeatureLocation 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 4 with DNAFeatureLocation

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

the class ICESBOLParserVisitor method visit.

@Override
public void visit(DnaComponent component) {
    if (featuredDNASequence == null) {
        featuredDNASequence = new FeaturedDNASequence();
        if (update != null) {
            String name = component.getName();
            if (name == null || name.trim().isEmpty())
                update.getKeyValue().put(EntryField.NAME, name);
            else {
                update.getKeyValue().put(EntryField.NAME, name);
                update.getKeyValue().put(EntryField.ALIAS, component.getDisplayId());
            }
            update.getKeyValue().put(EntryField.SUMMARY, component.getDescription());
        }
        featuredDNASequence.setName(component.getName());
        featuredDNASequence.setIdentifier(component.getDisplayId());
        featuredDNASequence.setDescription(component.getDescription());
        featuredDNASequence.setDcUri(component.getURI().toString());
        DnaSequence sequence = component.getDnaSequence();
        if (sequence != null) {
            featuredDNASequence.setSequence(sequence.getNucleotides());
            featuredDNASequence.setUri(sequence.getURI().toString());
        }
    }
    List<SequenceAnnotation> annotations = component.getAnnotations();
    Logger.debug("Encountered DC " + component.getDisplayId());
    if (!annotations.isEmpty()) {
        // iterate sorted annotations for top level
        for (SequenceAnnotation sequenceAnnotation : annotations) {
            int strand;
            if (sequenceAnnotation.getStrand() == null) {
                strand = 1;
            } else {
                strand = sequenceAnnotation.getStrand() == StrandType.POSITIVE ? 1 : -1;
            }
            Pair relative = new Pair(sequenceAnnotation.getBioStart(), sequenceAnnotation.getBioEnd(), strand);
            walkTree(sequenceAnnotation, relative);
            DNAFeature feature = createDNAFeature(sequenceAnnotation, relative);
            DNAFeatureLocation location = feature.getLocations().get(0);
            featuredDNASequence.getFeatures().add(feature);
            Logger.debug("Adding feature [" + 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) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) DnaSequence(org.sbolstandard.core.DnaSequence)

Example 5 with DNAFeatureLocation

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

the class Annotations method filter.

public Results<DNAFeature> filter(int offset, int limit, String filter) {
    Account account = accountDAO.getByEmail(userId);
    List<Group> groups = new GroupController().getAllGroups(account);
    List<SequenceFeature> features = sequenceFeatureDAO.getSequenceFeatures(this.userId, groups, filter, offset, limit);
    int count = sequenceFeatureDAO.getSequenceFeaturesCount(this.userId, groups, filter);
    Results<DNAFeature> results = new Results<>();
    results.setResultCount(count);
    for (SequenceFeature feature : features) {
        DNAFeature dnaFeature = feature.toDataTransferObject();
        Entry entry = feature.getSequence().getEntry();
        dnaFeature.setIdentifier(entry.getPartNumber());
        DNAFeatureLocation location = new DNAFeatureLocation();
        location.setGenbankStart(feature.getUniqueGenbankStart());
        location.setEnd(feature.getUniqueEnd());
        dnaFeature.getLocations().add(location);
        dnaFeature.getEntries().add(entry.getId());
        results.getData().add(dnaFeature);
    }
    return results;
}
Also used : Results(org.jbei.ice.lib.dto.common.Results) GroupController(org.jbei.ice.lib.group.GroupController) DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Aggregations

DNAFeature (org.jbei.ice.lib.dto.DNAFeature)5 DNAFeatureLocation (org.jbei.ice.lib.dto.DNAFeatureLocation)5 SequenceAnnotation (org.sbolstandard.core.SequenceAnnotation)2 CSVReader (com.opencsv.CSVReader)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 Results (org.jbei.ice.lib.dto.common.Results)1 GroupController (org.jbei.ice.lib.group.GroupController)1 DnaComponent (org.sbolstandard.core.DnaComponent)1 DnaSequence (org.sbolstandard.core.DnaSequence)1