use of org.jbei.ice.storage.model.AnnotationLocation 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());
}
use of org.jbei.ice.storage.model.AnnotationLocation in project ice by JBEI.
the class SBOLVisitor method visit.
public void visit(SequenceFeature feature) {
SequenceAnnotation annotation = SBOLFactory.createSequenceAnnotation();
String uri = feature.getUri();
if (uri == null || uri.isEmpty()) {
uri = UUID.randomUUID().toString();
annotation.setURI(URI.create(uriString + "/sa#" + uri));
} else {
if (uris.contains(uri))
return;
uris.add(uri);
annotation.setURI(URI.create(uri));
}
AnnotationLocation location = null;
if (feature.getAnnotationLocations() != null && !feature.getAnnotationLocations().isEmpty()) {
location = (AnnotationLocation) feature.getAnnotationLocations().toArray()[0];
if (location.getGenbankStart() <= location.getEnd()) {
annotation.setBioStart(location.getGenbankStart());
annotation.setBioEnd(location.getEnd());
}
}
annotation.setStrand(feature.getStrand() == 1 ? StrandType.POSITIVE : StrandType.NEGATIVE);
DnaComponent subComponent = SBOLFactory.createDnaComponent();
String dcUri = feature.getFeature().getUri();
if (dcUri == null || dcUri.isEmpty()) {
dcUri = UUID.randomUUID().toString();
subComponent.setURI(URI.create(uriString + "/dc#" + dcUri));
subComponent.setDisplayId(dcUri);
} else {
if (uris.contains(dcUri))
return;
uris.add(dcUri);
subComponent.setURI(URI.create(dcUri));
String displayId = StringUtils.isBlank(feature.getFeature().getIdentification()) ? dcUri.substring(dcUri.lastIndexOf("/") + 1) : feature.getFeature().getIdentification();
subComponent.setDisplayId(displayId);
}
subComponent.setName(feature.getName());
subComponent.addType(IceSequenceOntology.getURI(feature.getGenbankType()));
annotation.setSubComponent(subComponent);
// add a dna sequence for cases where the feature wraps around the origin
if (location != null && location.getGenbankStart() > location.getEnd()) {
DnaSequence subComponentSequence = SBOLFactory.createDnaSequence();
String sequence = location.getSequenceFeature().getSequence().getSequence();
StringBuilder builder = new StringBuilder();
int start = location.getGenbankStart() - 1;
if (start < sequence.length()) {
builder.append(sequence.substring(start, sequence.length()));
} else {
Logger.warn("Encountered feature with start " + location.getGenbankStart() + " and sequence length of " + sequence.length());
return;
}
builder.append(sequence.substring(0, location.getEnd()));
subComponentSequence.setNucleotides(builder.toString());
subComponentSequence.setURI(URI.create(uriString + "/ds#" + UUID.randomUUID().toString()));
subComponent.setDnaSequence(subComponentSequence);
}
dnaComponent.addAnnotation(annotation);
}
Aggregations