Forums

F.A.Q. F.A.Q.    Register Register    Login Login    Home Home
Search Search
SBML Discussions » sbml-interoperability » simple question about adding a species
Show: Today's Posts  :: Message Navigator
| Subscribe to topic 
Return to the default flat view Create a new topic Submit Reply
AuthorTopic
Allyson Lister


Posts: 88
Registered:
December 2007
Re: simple question about adding a species 22 Jan '09 02:58 Go to previous messageGo to previous message

Hi all,

Here's an update.

I did a little more digging into this with a unit test, and discovered you
could change the underlying species if you first get it with getSpecies().
Below is a modified unit test based on Neil's, but using thoughts I came up
with after pondering a little more on Frank's email - looks like the Java
behavior is the same as C++ in this instance:

Thanks all! :) allyson p.s. unit test and it's output follows:

unit test (passes):
@Test
public void testDuplicateSpecies() {
final String id = "Newcastle";
final String modifiedId = "Manchester";
final String name = "Sunderland";
final String modifiedName = "Tyne";

Species species = new Species( id );
species.setName( name );
SBMLDocument document = new SBMLDocument();
document.createModel();

document.getModel().addSpecies( species );
species = document.getModel().getSpecies( id ); // re-set species to
the result of getSpecies! if you don't do this, then the changes aren't
propogated back to the model. Comment out this line and see how the behavior
changes.

assertEquals( name, species.getName() );

// Print out original:
System.out.println( document.toSBML() );
System.out.println( "----------" );

// Attempt to update species and print out:
species.setId( modifiedId );

System.out.println( document.toSBML() );
System.out.println( "----------" );

// prove that the Species within the model can be updated via
reference:
assertNull( document.getModel().getSpecies( id ) );
assertNotNull( document.getModel().getSpecies( modifiedId ) );

// set the species back to the original Id, and modify the name
species.setId( id );
species.setName( modifiedName );

assertNotNull( document.getModel().getSpecies( id ) );
assertNull( document.getModel().getSpecies( modifiedId ) );

System.out.println( document.toSBML() );
}


output:

<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Newcastle" name="Sunderland"/>
</listOfSpecies>
</model>
</sbml>
----------
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Manchester" name="Sunderland"/>
</listOfSpecies>
</model>
</sbml>
----------
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2"
version="3">
<model>
<listOfSpecies>
<species id="Newcastle" name="Tyne"/>
</listOfSpecies>
</model>
</sbml>

2009/1/22 Allyson Lister <allyson.lurena@googlemail.com>

> Hi Frank,
>
> This sounds and looks very much like C++ code ;) While I used to use that
> back in a previous job, here I'm using the Java version of libSBML, and as
> Neil pointed out, when we run getSpecies() in Java, I don't think we get
> back a reference/pointer - I think it's a copy. I even tried removing the
> "final" parts of Neil's code above, to make sure that wasn't the problem,
> but I get the same results as he does.
>
> Very good idea, but not sure it will work for us Java-ites.
>
> thanks very much! :)
>
> 2009/1/21 Frank Bergmann <fbergman@u.washington.edu>
>
> Actually it is easier than all that, all you need to do, is to get
>> your species
>>
>> Species *species = model->getSpecies("sbmlId" or unsigned int index);
>>
>> now you check whether the species was there, by testing for NULL, and
>> if all is well you do your modification:
>>
>> if (species != NULL) species->setInitialAmount(newValue);
>>
>> as you only received a reference to the actual species, all changes
>> will be there the next time you write this model out.
>>
>> As to your question when does the validation happen, the next
>> validation happens upon a call to checkConsinstency ... which will
>> fill your error log ...
>>
>> i hope this helps,
>> best
>> Frank
>>
>> On Jan 21, 2009, at 3:49 AM, 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
>>
>> ____________________________________________________________
>> 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
>



--

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

      

SubjectPosterDate
Read Message   simple question about adding a species Allyson Lister21 Jan '09 03:49
Read Message   Re: simple question about adding a species Alejandro21 Jan '09 08:55
Read Message   Re: simple question about adding a species Neil Swainston21 Jan '09 09:06
Read Message   Re: simple question about adding a species ajouraku22 Jan '09 01:57
Read Message   Re: simple question about adding a species Frank Bergmann21 Jan '09 09:18
Read Message   Re: simple question about adding a species Allyson Lister22 Jan '09 01:21
Read Message   Re: simple question about adding a species Neil Swainston22 Jan '09 01:50
Read Message   Re: simple question about adding a species Allyson Lister22 Jan '09 01:24
Read Message   Re: simple question about adding a species ajouraku22 Jan '09 03:56
Read Message   Re: simple question about adding a species Sarah Keating22 Jan '09 08:58
Read Message   Re: simple question about adding a species Mike Hucka02 Feb '09 22:21
Read Message   Re: simple question about adding a species Allyson Lister22 Jan '09 01:31
Read Message   Re: simple question about adding a species  Allyson Lister22 Jan '09 02:58
Read Message   Re: simple question about adding a species Allyson Lister22 Jan '09 09:21
Read Message   Re: simple question about adding a species Mike Hucka23 Jan '09 00:25
Read Message   Re: simple question about adding a species curoli23 Jan '09 06:19
Read Message   Re: simple question about adding a species Allyson Lister23 Jan '09 01:09
Previous Topic:Re: &quot; The basic libsbml library file&quot;
Next Topic:libsbml and tomcat
Go to forum:
-=] Back to Top [=-

Powered by FUDforum. (Copyright Advanced Internet Designs Inc.)

Please use our issue tracking system for any questions or suggestions about this website.