Search in sources :

Example 1 with SequenceFeature

use of org.jbei.ice.storage.model.SequenceFeature in project ice by JBEI.

the class GenbankFormatter method format.

@Override
public void format(Sequence sequence, OutputStream outputStream) throws FormatterException, IOException {
    if (sequence == null || outputStream == null || sequence.getSequence().isEmpty()) {
        return;
    }
    SimpleRichSequence simpleRichSequence = null;
    try {
        simpleRichSequence = new SimpleRichSequence(getNamespace(), normalizeLocusName(name), accessionNumber, version, DNATools.createDNA(sequence.getSequence()), seqVersion);
        simpleRichSequence.setCircular(getCircular());
        if (getDescription() != null && !getDescription().isEmpty()) {
            simpleRichSequence.setDescription(getDescription());
        }
        if (getDivision() != null && !getDivision().isEmpty()) {
            simpleRichSequence.setDivision(getDivision());
        }
        if (getIdentifier() != null && !getIdentifier().isEmpty()) {
            simpleRichSequence.setIdentifier(getIdentifier());
        }
        if (sequence.getSequenceFeatures() != null && sequence.getSequenceFeatures().size() > 0) {
            Set<Feature> featureSet = new LinkedHashSet<>();
            for (SequenceFeature sequenceFeature : sequence.getSequenceFeatures()) {
                if (sequenceFeature.getFeature() == null) {
                    Logger.warn("In sequence with id: " + sequence.getId() + "; SequenceFeature object has no feature assigned to it.");
                    continue;
                }
                RichFeature.Template featureTemplate = new RichFeature.Template();
                featureTemplate.annotation = getAnnotations(sequenceFeature);
                Set<AnnotationLocation> locations = sequenceFeature.getAnnotationLocations();
                if (locations == null || locations.size() == 0)
                    continue;
                if (locations.size() == 1) {
                    featureTemplate.location = new SimpleRichLocation(new SimplePosition(sequenceFeature.getUniqueGenbankStart()), new SimplePosition(sequenceFeature.getUniqueEnd()), 1, getStrand(sequenceFeature));
                } else {
                    ArrayList<Location> members = new ArrayList<>();
                    for (AnnotationLocation location : locations) {
                        members.add(new SimpleRichLocation(new SimplePosition(location.getGenbankStart()), new SimplePosition(location.getEnd()), 1, getStrand(sequenceFeature)));
                    }
                    featureTemplate.location = new CompoundRichLocation(members);
                }
                featureTemplate.source = getDefaultFeatureSource();
                featureTemplate.type = getFeatureType(sequenceFeature);
                featureTemplate.rankedCrossRefs = new TreeSet<>();
                SimpleRichFeature simpleRichFeature = new SimpleRichFeature(simpleRichSequence, featureTemplate);
                featureSet.add(simpleRichFeature);
            }
            simpleRichSequence.setFeatureSet(featureSet);
        }
    } catch (Exception e) {
        throw new FormatterException("Failed to create generate genbank file", e);
    }
    RichSequence.IOTools.writeGenbank(outputStream, simpleRichSequence, getNamespace());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) Feature(org.biojava.bio.seq.Feature) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) IOException(java.io.IOException) AnnotationLocation(org.jbei.ice.storage.model.AnnotationLocation) AnnotationLocation(org.jbei.ice.storage.model.AnnotationLocation) Location(org.biojava.bio.symbol.Location)

Example 2 with SequenceFeature

use of org.jbei.ice.storage.model.SequenceFeature in project ice by JBEI.

the class SBOLVisitor method visit.

public void visit(Sequence sequence) {
    // ice data model conflates the sequence and component
    Entry entry = sequence.getEntry();
    // Set required properties
    String partId = entry.getPartNumber();
    String dcUri = sequence.getComponentUri();
    if (dcUri == null) {
        dnaComponent.setURI(URI.create(uriString + "/dc#" + partId));
        dnaComponent.setDisplayId(partId);
    } else {
        dnaComponent.setURI(URI.create(dcUri));
        String displayId = StringUtils.isBlank(sequence.getIdentifier()) ? dcUri.substring(dcUri.lastIndexOf("/") + 1) : sequence.getIdentifier();
        dnaComponent.setDisplayId(displayId);
    }
    dnaComponent.setName(entry.getName());
    dnaComponent.setDescription(entry.getShortDescription());
    DnaSequence dnaSequence = SBOLFactory.createDnaSequence();
    dnaSequence.setNucleotides(sequence.getSequence());
    String dsUri = sequence.getUri();
    if (dsUri == null || dsUri.isEmpty()) {
        dsUri = sequence.getFwdHash();
        dnaSequence.setURI(URI.create(uriString + "/ds#" + dsUri));
    } else {
        dnaSequence.setURI(URI.create(dsUri));
    }
    dnaSequence.setNucleotides(sequence.getSequence());
    dnaComponent.setDnaSequence(dnaSequence);
    List<SequenceFeature> features = new ArrayList<>(sequence.getSequenceFeatures());
    Collections.sort(features, new SequenceFeatureComparator());
    for (SequenceFeature feature : features) visit(feature);
}
Also used : Entry(org.jbei.ice.storage.model.Entry) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature)

Example 3 with SequenceFeature

use of org.jbei.ice.storage.model.SequenceFeature in project ice by JBEI.

the class BlastPlus method writeBigFastaFileForFeatures.

/**
     * Writes the fasta file (part of the blast database) that contains all the features that exists on this system.
     * This routine is expected to be called as part of the blast sequence feature database rebuild
     *
     * @param writer writer for fasta file
     * @throws BlastException
     */
private static void writeBigFastaFileForFeatures(BufferedWriter writer) throws BlastException {
    FeatureDAO featureDAO = DAOFactory.getFeatureDAO();
    SequenceFeatureDAO sequenceFeatureDAO = DAOFactory.getSequenceFeatureDAO();
    long count = featureDAO.getFeatureCount(null);
    if (count <= 0)
        return;
    int offset = 0;
    while (offset < count) {
        List<Feature> features = featureDAO.getFeatures(offset++, 1, null);
        Feature feature = features.get(0);
        String featureName = feature.getName();
        if (featureName == null || featureName.trim().isEmpty())
            continue;
        if (feature.getCuration() != null && feature.getCuration().isExclude())
            continue;
        boolean hasNegativeStrand = false;
        boolean hasPositiveStrand = false;
        List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getByFeature(feature);
        if (sequenceFeatures == null || sequenceFeatures.isEmpty()) {
            hasPositiveStrand = true;
        } else {
            for (SequenceFeature sequenceFeature : sequenceFeatures) {
                if (sequenceFeature.getStrand() == 1) {
                    hasPositiveStrand = true;
                } else if (sequenceFeature.getStrand() == -1) {
                    hasNegativeStrand = true;
                }
            }
        }
        try {
            String sequenceString = feature.getSequence().trim();
            if (StringUtils.isEmpty(sequenceString))
                continue;
            if (hasNegativeStrand) {
                try {
                    SymbolList symbolList = DNATools.createDNA(sequenceString);
                    symbolList = DNATools.reverseComplement(symbolList);
                    writeSequenceString(feature, writer, symbolList.seqString(), -1);
                } catch (IllegalSymbolException | IllegalAlphabetException e) {
                    Logger.warn(e.getMessage());
                    continue;
                }
            }
            if (hasPositiveStrand) {
                writeSequenceString(feature, writer, sequenceString, 1);
            }
        } catch (IOException e) {
            throw new BlastException(e);
        }
    }
}
Also used : IllegalAlphabetException(org.biojava.bio.symbol.IllegalAlphabetException) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) FeatureDAO(org.jbei.ice.storage.hibernate.dao.FeatureDAO) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) IllegalSymbolException(org.biojava.bio.symbol.IllegalSymbolException) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Feature(org.jbei.ice.storage.model.Feature) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) SymbolList(org.biojava.bio.symbol.SymbolList)

Aggregations

SequenceFeature (org.jbei.ice.storage.model.SequenceFeature)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Feature (org.biojava.bio.seq.Feature)1 IllegalAlphabetException (org.biojava.bio.symbol.IllegalAlphabetException)1 IllegalSymbolException (org.biojava.bio.symbol.IllegalSymbolException)1 Location (org.biojava.bio.symbol.Location)1 SymbolList (org.biojava.bio.symbol.SymbolList)1 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)1 FeatureDAO (org.jbei.ice.storage.hibernate.dao.FeatureDAO)1 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)1 AnnotationLocation (org.jbei.ice.storage.model.AnnotationLocation)1 Entry (org.jbei.ice.storage.model.Entry)1 Feature (org.jbei.ice.storage.model.Feature)1