|
Hi Allyson,
As far as the adding duplicates issues, and needing to update
speciesReferences goes, I'm fine with that: libSBML just does exactly
what it says on the tin without attempting anything fancy. Personally
I prefer this approach.
I seem to spend far too large a proportion of my life updating
annotations in SBML documents. A modification of yesterday's code
shows how this works...
import org.sbml.libsbml.*;
/**
*
* @author Neil Swainston
*/
public class SbmlSpeciesIdTest
{
/**
*
*/
static
{
System.loadLibrary( "sbmlj" ); //$NON-NLS-1$
}
/**
*
*/
public void test()
{
final Species species1 = new Species( "Newcastle" );
final SBMLDocument document = new SBMLDocument();
document.createModel();
document.getModel().addSpecies( species1 );
// Print out original:
System.out.println( document.toSBML() );
// Attempt to update notes of species and print out:
species1.setNotes( "Manchester" );
System.out.println( document.toSBML() );
// Try again...
final Species species2 =
document.getModel().getSpecies( "Newcastle" );
species2.setNotes( "Manchester" );
System.out.println( document.toSBML() );
}
/**
*
* @param args
*/
public static void main( String[] args )
{
new SbmlSpeciesIdTest().test();
}
}
Obviously in this case I'm updating notes, not annotations, but the
principle is the same. The output is as follows, showing that the
document.getModel().getSpecies( "Newcastle" ) approach works (i.e.
updating species2, not species1)...
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Newcastle"/>
</listOfSpecies>
</model>
</sbml>
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Newcastle"/>
</listOfSpecies>
</model>
</sbml>
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Newcastle">
<notes>Manchester</notes>
</species>
</listOfSpecies>
</model>
</sbml>
By debugging this, it seems that species1 and species2 are pointing to
different objects in the C++ layer. I'd love to say that I understand
JNI enough to be able to explain this, but frankly I've got better
things to worry about.
This problem has stung me a few times in the past - by getting the
relevant sbase from the model and updating this, all seems to be fine.
Cheers,
Neil.
On 22 Jan 2009, at 09:21, Allyson Lister wrote:
> Hi Neil,
>
> Thanks for the reply. Yes, this is the sort of program I should have
> tried
> first before emailing the group, but thanks for doing it and showing
> the
> output. This is what I had suspected was happening.
>
> The example below shows the behaviour if you try to update a species
> in Java
> (it isn't linked to the model you got it from), or add an "updated"
> species
> with the same id (it gets added as a duplicate rather than updating
> the
> original). So, then, I wonder what the best way is to update a
> species? All
> I want to do is add more annotation. I have gotten as far as making
> a new
> version (locally) of the original species + new annotation, and now
> don't
> know how to get it back in without breaking things.
>
> I'll have a think :)
>
> 2009/1/21 Neil Swainston <neil.swainston@manchester.ac.uk>
>
>> Hi Allyson,
>>
>> Try running the following program:
>>
>> import org.sbml.libsbml.*;
>>
>> /**
>> *
>> * @author Neil Swainston
>> */
>> public class SbmlSpeciesIdTest
>> {
>> /**
>> *
>> */
>> static
>> {
>> System.loadLibrary( "sbmlj" ); //$NON-NLS-1$
>> }
>>
>> /**
>> *
>> */
>> public void test()
>> {
>> final Species species = new Species( "Newcastle" );
>> final SBMLDocument document = new SBMLDocument();
>> document.createModel();
>>
>> document.getModel().addSpecies( species );
>>
>> // Print out original:
>> System.out.println( document.toSBML() );
>>
>> // Attempt to update species and print out:
>> species.setId( "Manchester" );
>> System.out.println( document.toSBML() );
>>
>> // Add a duplicate species and print out:
>> document.getModel().addSpecies( new
>> Species( "Newcastle" )
>> );
>> System.out.println( document.toSBML() );
>> }
>>
>> /**
>> *
>> * @param args
>> */
>> public static void main( String[] args )
>> {
>> new SbmlSpeciesIdTest().test();
>> }
>> }
>>
>> The output that I received was as follows:
>>
>> <sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
>> version="3">
>> <model>
>> <listOfSpecies>
>> <species id="Newcastle"/>
>> </listOfSpecies>
>> </model>
>> </sbml>
>>
>> <sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
>> version="3">
>> <model>
>> <listOfSpecies>
>> <species id="Newcastle"/>
>> </listOfSpecies>
>> </model>
>> </sbml>
>>
>> <sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
>> version="3">
>> <model>
>> <listOfSpecies>
>> <species id="Newcastle"/>
>> <species id="Newcastle"/>
>> </listOfSpecies>
>> </model>
>> </sbml>
>>
>> The take-home messages seem to be that you can indeed add "duplicate"
>> species to the model (two species with the same id).
>>
>> Also, updating the "local". Java species to give it the id of
>> "Manchester" seems not to update the underlying species in the C++
>> layer - presumably down to some JNI subtlety that I won't pretend to
>> understand.
>>
>> Cheers,
>>
>> Neil.
>>
>> On 21 Jan 2009, at 11:49, Allyson Lister wrote:
>>
>>> Hi all,
>>>
>>> I'm using libSbml 3.2.0 in its Java incarnation.
>>>
>>> I would like to get a species from a model (model.getSpecies(myId),
>>> modify
>>> it, and then put it back in, essentially overwriting what was there
>>> before.
>>> However, it is unclear from the docs whether
>>> model.addSpecies( mySpecies)
>>> will overwrite any existing species with that same id, or if it will
>>> not add
>>> the new version of the species. Alternatively, should I remove the
>>> old
>>> version first, and then add the new species (I'm guessing that's
>>> not an
>>> option, as it will mess up all existing links to that species within
>>> the
>>> model). Looking at the C++ code, it seems to run an append()
>>> function over
>>> the species set, but I don't know if that append function will allow
>>> duplicates or not, or how duplicates are determined. I may be
>>> overthinking
>>> this, but the best way to do this would be great!
>>>
>>> thanks,
>>> allyson
>>>
>>> --
>>>
>>> Allyson Lister
>>> http://lurena.vox.com
>>>
>>> CISBAN, http://www.cisban.ac.uk
>>> Newcastle University
>>> ____________________________________________________________
>>> To manage your sbml-interoperability list subscription, visit
>>> https://utils.its.caltech.edu/mailman/listinfo/sbml-interoperability
>>>
>>> For a web interface to the sbml-interoperability mailing list, visit
>>> http://sbml.org/Forums/
>>>
>>> For questions or feedback about the sbml-interoperability list,
>>> contact sbml-team@caltech.edu
>>
>>
>> Neil Swainston
>> Experimental Officer
>>
>> Manchester Centre for Integrative Systems Biology
>> Manchester Interdisciplinary Biocentre
>> University of Manchester
>> Manchester M1 7DN
>> United Kingdom
>>
>>
>>
>>
>>
>> ____________________________________________________________
>> To manage your sbml-interoperability list subscription, visit
>> https://utils.its.caltech.edu/mailman/listinfo/sbml-interoperability
>>
>> For a web interface to the sbml-interoperability mailing list, visit
>> http://sbml.org/Forums/
>>
>> For questions or feedback about the sbml-interoperability list,
>> contact sbml-team@caltech.edu
>>
>
>
>
> --
>
> Allyson Lister
> http://lurena.vox.com
>
> CISBAN, http://www.cisban.ac.uk
> Newcastle University
> ____________________________________________________________
> To manage your sbml-interoperability list subscription, visit
> https://utils.its.caltech.edu/mailman/listinfo/sbml-interoperability
>
> For a web interface to the sbml-interoperability mailing list, visit
> http://sbml.org/Forums/
>
> For questions or feedback about the sbml-interoperability list,
> contact sbml-team@caltech.edu
Neil Swainston
Experimental Officer
Manchester Centre for Integrative Systems Biology
Manchester Interdisciplinary Biocentre
University of Manchester
Manchester M1 7DN
United Kingdom
____________________________________________________________
To manage your sbml-interoperability list subscription, visit
https://utils.its.caltech.edu/mailman/listinfo/sbml-interoperability
For a web interface to the sbml-interoperability mailing list, visit
http://sbml.org/Forums/
For questions or feedback about the sbml-interoperability list,
contact sbml-team@caltech.edu
|