Esempio n. 1
0
void insertAnnotationAfter(SequenceAnnotation* upstream, SequenceAnnotation* new_annotation) {

	//	Update start and end of annotation
	int insert_size = strlen(getDNASequenceNucleotides(getDNAComponentSequence(getSequenceAnnotationSubComponent(new_annotation))));
	int insertion_site = getPositionProperty(upstream->genbankEnd) + 1;
	setSequenceAnnotationStart(new_annotation, insertion_site);
	setSequenceAnnotationEnd(new_annotation, insertion_site + insert_size - 1);


	//  Update precedes relationship of annotations 
	SequenceAnnotation* downstream = NULL;
	if (getNumPointersInArray(upstream->precedes) > 0) {
		downstream = getNthPrecedes(upstream, 0);
		removePrecedesRelationship(upstream, downstream);
		addPrecedesRelationship(upstream, new_annotation);
		addPrecedesRelationship(new_annotation, downstream);
		upstream = new_annotation;

		// Update all start and end indices for annotations downstream from insertion
		int old_start, old_end = 0;
		int new_start = 0;
		int new_end = 0;
		while (getNumPointersInArray(upstream->precedes) > 0) {
			downstream = getNthPrecedes(upstream, 0);
			old_start = getPositionProperty(downstream->genbankStart);
			old_end = getPositionProperty(downstream->genbankEnd);
			new_start = old_start + insert_size;
			new_end = old_end + insert_size;
			setPositionProperty(downstream->genbankStart, new_start);
			setPositionProperty(downstream->genbankEnd, new_end);
			upstream = downstream;
		}
	}
}
Esempio n. 2
0
static void applyFunctionToNodesMatchingXPath(void (*fn)(xmlNode *), xmlNode *node, xmlChar *path) {
	if (!path)
		return;
	PointerArray *results = getNodesMatchingXPath(node, path);
	if (results) {
        if (getNumPointersInArray(results) > 0) {
            int n;
            for (n=0; n<getNumPointersInArray(results); n++)
                fn(getNthPointerInArray(results, n));
        }
	deletePointerArray(results);
    }
}
Esempio n. 3
0
static void readCollectionReferences(xmlNode *node) {
    Collection *col;
	xmlChar *path;
    xmlChar *col_uri;
    xmlChar *ref_uri;
    PointerArray *ref_nodes;
    xmlNode *ref_node;
    int n;

    // get Collection
    col_uri = getNodeURI(node);
    col = getCollection(DESTINATION, (char *)col_uri);
    xmlFree(col_uri);

    // add components
    path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_COMPONENT
    				 "/" NSPREFIX_SBOL ":" NODENAME_DNACOMPONENT;
    if ((ref_nodes = getNodesMatchingXPath(node, path))) {
        for (n=0; n<getNumPointersInArray(ref_nodes); n++) {
            ref_node = (xmlNode *) getNthPointerInArray(ref_nodes, n);
            ref_uri = getNodeURI(ref_node);
            addDNAComponentToCollection(col, getDNAComponent(DESTINATION, (char *)ref_uri));
            xmlFree(ref_uri);
        }
        deletePointerArray(ref_nodes);
    }
}
Esempio n. 4
0
static void readSequenceAnnotationReferences(xmlNode *node) {
	SequenceAnnotation *ann;
	xmlChar *path;
	xmlChar *ann_uri;
	xmlChar *ref_uri;
	xmlNode *ref_node;
	PointerArray *results;
	int n;

 	// get SequenceAnnotation
	ann_uri = getNodeURI(node);
	ann = getSequenceAnnotation(DESTINATION, (char *)ann_uri);
	xmlFree(ann_uri);

	// add subComponent
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_SUBCOMPONENT
					 "/" NSPREFIX_SBOL ":" NODENAME_DNACOMPONENT;
	if ((ref_uri = getURIOfNodeMatchingXPath(node, path))) {
		setSequenceAnnotationSubComponent(ann, getDNAComponent(DESTINATION, (char *)ref_uri));
		xmlFree(ref_uri);
	}

	// add precedes
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_PRECEDES;
	if ((results = getNodesMatchingXPath(node, path))) {
		for (n=0; n<getNumPointersInArray(results); n++) {
			ref_node = (xmlNode *) getNthPointerInArray(results, n);
			ref_uri  = getNodeURI(ref_node);
			addPrecedesRelationship(ann, getSequenceAnnotation(DESTINATION, (char *)ref_uri));
			xmlFree(ref_uri);
		}
		deletePointerArray(results);
	}
}
Esempio n. 5
0
static xmlNode *getSingleNodeMatchingXPath(xmlNode *node, xmlChar *path) {
	PointerArray *results_array = getNodesMatchingXPath(node, path);
	if (!results_array)
		return NULL;
	else if (getNumPointersInArray(results_array) == 0) {
		deletePointerArray(results_array);
		return NULL;
	} else {
		if (getNumPointersInArray(results_array) > 1) {
			#ifdef SBOL_DEBUG_STATEMENTS
			printf("Got too many nodes matching xpath %s\n", (char *)path);
			#endif
		}
		xmlNode *result = getNthPointerInArray(results_array, 0);
		deletePointerArray(results_array);
		return result;
	}
}
Esempio n. 6
0
void removePrecedesRelationship(SequenceAnnotation* upstream, SequenceAnnotation* downstream) {
	if (upstream && downstream) {
		char *target_uri = getSequenceAnnotationURI(downstream);

		char *query_uri;
		int FOUND = 0; // found URI in list of URIs
		int EOL = 0; // end of list
		int i_uri = 0;  // index of URI in list
		while (!FOUND && !EOL) {
			query_uri = (char *)getNthPointerInArray(upstream->precedes, i_uri);

			if (strcmp(query_uri, target_uri) == 0) {
				FOUND++;
				removePointerFromArray(upstream->precedes, i_uri);
			}
			i_uri++;
			if (i_uri == getNumPointersInArray(upstream->precedes)) {
				EOL++;
			}
		}
	}
	return;
}
Esempio n. 7
0
SequenceAnnotation* copySequenceAnnotation(SequenceAnnotation* ann, char* id_modifier) {
	int i;
	char* copy_uri = augmentURI(getSequenceAnnotationURI(ann), id_modifier);
	SequenceAnnotation* copy = createSequenceAnnotation(ann->doc, copy_uri);
	setSequenceAnnotationStart(copy, getSequenceAnnotationStart(ann));
	setSequenceAnnotationEnd(copy, getSequenceAnnotationEnd(ann));
	setSequenceAnnotationStrand(copy, getSequenceAnnotationStrand(ann));

	// Copy precedes property
	copy->precedes = createPointerArray();
	char *target_uri;
	for (i = 0; i < getNumPointersInArray(ann->precedes); i++) {
		target_uri = (char *)getNthPointerInArray(ann->precedes, i);
		insertPointerIntoArray(copy->precedes, augmentURI(target_uri, id_modifier));
	}

	// Copy SubComponent tree recursively
	if (ann->subComponent) {
		char* sub_com_uri = augmentURI(getDNAComponentURI(ann->subComponent), id_modifier);
		DNAComponent* sub_com_copy = createDNAComponent(ann->doc, sub_com_uri);
		setSequenceAnnotationSubComponent(copy, sub_com_copy);
	}
	return (SequenceAnnotation *)copy;
}
Esempio n. 8
0
static void readDNAComponentReferences(xmlNode *node) {
    DNAComponent *com;
	xmlChar *path;
    xmlChar *com_uri;
    xmlChar *ref_uri;
    PointerArray *ref_nodes;
    xmlNode *ref_node;
    int n;

    // get DNAComponent
    com_uri = getNodeURI(node);
    com = getDNAComponent(DESTINATION, (char *)com_uri);
    xmlFree(com_uri);

    // add sequence
    path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_DNASEQUENCE_REF
    				 "/" NSPREFIX_SBOL ":" NODENAME_DNASEQUENCE;
    if ((ref_uri = getURIOfNodeMatchingXPath(node, path))) {
        setDNAComponentSequence(com, getDNASequence(DESTINATION, (char *)ref_uri));
        xmlFree(ref_uri);
    }
    
    // add annotations
    path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_ANNOTATION
      "/" NSPREFIX_SBOL ":" NODENAME_SEQUENCEANNOTATION;

    if ((ref_nodes = getNodesMatchingXPath(node, path))) {
        for (n=0; n<getNumPointersInArray(ref_nodes); n++) {
            ref_node = (xmlNode *) getNthPointerInArray(ref_nodes, n);
            ref_uri = getNodeURI(ref_node);
            addSequenceAnnotation(com, getSequenceAnnotation(DESTINATION, (char *)ref_uri));
            xmlFree(ref_uri);
        }
        deletePointerArray(ref_nodes);
    }
}
Esempio n. 9
0
int getNumPrecedes(const SequenceAnnotation* ann) {
	if (ann && ann->precedes)
		return getNumPointersInArray(ann->precedes);
	else
		return 0;
}
Esempio n. 10
0
int getNumDNAComponentsIn(const Collection* col) {
	if (col)
		return getNumPointersInArray(col->components);
	else
		return -1;
}
Esempio n. 11
0
int getNumStructuredAnnotations(SBOLObject* obj) {
	return getNumPointersInArray(obj->xml_annotations);
}