use of org.jbei.ice.lib.dto.DNAFeature 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;
}
use of org.jbei.ice.lib.dto.DNAFeature 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());
}
}
}
use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.
the class Annotations method generate.
/**
* Using existing and potentially curated annotations on this ICE instance,
* this generates matching features for the passed sequence
*
* @param sequence wrapper around dna sequence
* @return wrapper around passed sequence and now with list if annotations for that sequence
*/
public FeaturedDNASequence generate(FeaturedDNASequence sequence) {
BlastQuery query = new BlastQuery();
query.setSequence(sequence.getSequence());
try {
List<DNAFeature> features = BlastPlus.runCheckFeatures(query);
sequence.getFeatures().addAll(features);
return sequence;
} catch (BlastException e) {
Logger.error(e);
return null;
}
}
use of org.jbei.ice.lib.dto.DNAFeature 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;
}
}
use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.
the class AnnotationResource method curate.
/**
* Curate available annotations to include or exclude them from auto-annotation feature
*
* @param list list of annotations each with specified curate
*/
@PUT
@Produces(MediaType.APPLICATION_JSON)
public Response curate(List<DNAFeature> list) {
String userId = requireUserId();
Annotations annotations = new Annotations(userId);
try {
final Type fooType = new TypeToken<ArrayList<DNAFeature>>() {
}.getType();
final Gson gson = new GsonBuilder().create();
final ArrayList<DNAFeature> features = gson.fromJson(gson.toJsonTree(list), fooType);
annotations.curate(features);
return super.respond(true);
} catch (PermissionException e) {
Logger.error(e);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
}
Aggregations