Search in sources :

Example 1 with Location

use of org.biojava.bio.symbol.Location 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)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Feature (org.biojava.bio.seq.Feature)1 Location (org.biojava.bio.symbol.Location)1 AnnotationLocation (org.jbei.ice.storage.model.AnnotationLocation)1 SequenceFeature (org.jbei.ice.storage.model.SequenceFeature)1