use of org.biojava.bio.seq.Feature 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());
}
Aggregations