Intermine bag model question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Intermine bag model question

Vallejos, Andrew

Is there a way to determine if a bag is a subclass of a given class?

 

I am working on ClStatLdr.java, which is an ontology enrichment widget for GEO data.  I modeled the data so there is a super class of GEORecord, with three sub classes of GEODataSet, GEOSample, and GEOSeries.

 

Here is snippet of my code: 

if (bagType.equals("GEODataSet")) {

qfPrimaryIdentifier = new QueryField(qcGEORecord, "geoAccession");

                qfId = qfGEORecordId;

}

 

I could have three conditionals…checking for each class individually, but I would rather check to see if the bag class is a subclass of GEORecord, since the code is generally the same.  The main reason I have these checks is because I also have to check for other classes of objects, like Genes, which use primaryIdentifier not geoAccession.

 

Thanks!

 

Andrew

 

======================

Andrew Vallejos

Web Developer II

Biotechnology and Bioengineering Center

Medical College of Wisconsin

414-955-4104

[hidden email]


_______________________________________________
dev mailing list
[hidden email]
http://mail.intermine.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Intermine bag model question

Julie Sullivan
No, not easily.

That value is a string so there's not a quick way to explore the model.  You
could create a GEODataSet/GEOSample/GEOSeries object then look at it's parent
classes or use isInstanceOf().

But I think it'd be easier to just make a big IF statement.

On 07/01/2011 03:15 PM, Vallejos, Andrew wrote:

> Is there a way to determine if a bag is a subclass of a given class?
>
>
>
> I am working on ClStatLdr.java, which is an ontology enrichment widget
> for GEO data.  I modeled the data so there is a super class of
> GEORecord, with three sub classes of GEODataSet, GEOSample, and
> GEOSeries.
>
>
>
> Here is snippet of my code:
>
> if (bagType.equals("GEODataSet")) {
>
> qfPrimaryIdentifier = new QueryField(qcGEORecord, "geoAccession");
>
>                  qfId = qfGEORecordId;
>
> }
>
>
>
> I could have three conditionals...checking for each class individually,
> but I would rather check to see if the bag class is a subclass of
> GEORecord, since the code is generally the same.  The main reason I have
> these checks is because I also have to check for other classes of
> objects, like Genes, which use primaryIdentifier not geoAccession.
>
>
>
> Thanks!
>
>
>
> Andrew
>
>
>
> ======================
>
> Andrew Vallejos
>
> Web Developer II
>
> Biotechnology and Bioengineering Center
>
> Medical College of Wisconsin
>
> 414-955-4104
>
> [hidden email]
>
>
>
>
>
> _______________________________________________
> dev mailing list
> [hidden email]
> http://mail.intermine.org/cgi-bin/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
http://mail.intermine.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Intermine bag model question

Alex Kalderimis-2
In reply to this post by Vallejos, Andrew
One way is to get a class descriptor for your suspected sub-class and
then call cd.getAllSuperClassNames(). This returns a Set of Strings,
and if your superclass' name is in the set, then it is a superclass,
or the class itself.

SO:

  import org.intermine.metadata.Model;
  import org.intermine.metadata.ClassDescriptor;

  String super = "Employee";
  String sub = "Manager";
  Model model = ??;

  ClassDescriptor cd = model.getClassDescriptorByName(sub);
  if (cd.getAllSuperClassNames().contains(super)) {
    System.out.println("YAY! super is super");
  } else {
    System.out.println("Boo! super is not really super");
  }

Alex
On Fri, Jul 01, 2011 at 09:15:52AM -0500, Vallejos, Andrew wrote:

> Is there a way to determine if a bag is a subclass of a given class?
>
>  
>
> I am working on ClStatLdr.java, which is an ontology enrichment widget
> for GEO data.  I modeled the data so there is a super class of
> GEORecord, with three sub classes of GEODataSet, GEOSample, and
> GEOSeries.
>
>  
>
> Here is snippet of my code:  
>
> if (bagType.equals("GEODataSet")) {
>
> qfPrimaryIdentifier = new QueryField(qcGEORecord, "geoAccession");
>
>                 qfId = qfGEORecordId;
>
> }
>
>  
>
> I could have three conditionals...checking for each class individually,
> but I would rather check to see if the bag class is a subclass of
> GEORecord, since the code is generally the same.  The main reason I have
> these checks is because I also have to check for other classes of
> objects, like Genes, which use primaryIdentifier not geoAccession.
>
>  
>
> Thanks!
>
>  
>
> Andrew
>
>  
>
> ======================
>
> Andrew Vallejos
>
> Web Developer II
>
> Biotechnology and Bioengineering Center
>
> Medical College of Wisconsin
>
> 414-955-4104
>
> [hidden email]
>

> _______________________________________________
> dev mailing list
> [hidden email]
> http://mail.intermine.org/cgi-bin/mailman/listinfo/dev


_______________________________________________
dev mailing list
[hidden email]
http://mail.intermine.org/cgi-bin/mailman/listinfo/dev