Why can't I do a simple CONTAINS constraint with Query?

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

Why can't I do a simple CONTAINS constraint with Query?

Sam Hokin-3
I want to do a query in a post-processor which simply grabs the genes and their proteins, which have primary identifiers which
contain the gene's primary identifier (e.g. gene=cicar.ICC4958.gnm2.ann1.Ca_00006, protein=cicar.ICC4958.gnm2.ann1.Ca_00006.1).

But this query bombs with a vague error message:

// query Genes and Proteins with the corresponding primaryIdentifiers
Query query = new Query();
query.setDistinct(false);

QueryClass qcGene = new QueryClass(Gene.class);
query.addFrom(qcGene);
query.addToSelect(qcGene);

QueryClass qcProtein = new QueryClass(Protein.class);
query.addFrom(qcProtein);
query.addToSelect(qcProtein);

query.setConstraint(new SimpleConstraint(
        new QueryField(qcProtein,"primaryIdentifier"),
        ConstraintOp.CONTAINS,
        new QueryField(qcGene,"primaryIdentifier")));

After testing, it appears that ConstraintOp.CONTAINS is not allowed; I can run the query with ConstraintOp.EQUALS between proteins
and transcripts (which have the same primaryIdentifier).

Any way to do this in a single query? I'm running a protein query inside a loop off the gene query right now, which is slowwwwww
(but acceptable if that's the only way to do it).

_______________________________________________
dev mailing list
[hidden email]
https://lists.intermine.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Why can't I do a simple CONTAINS constraint with Query?

sergio contrino-2
hi sam!
i have not checked why contains is not enabled, and i could be missing
something else, but have you tried a like clause with % before and
after?
thanks
sergio

On 2020-05-04 15:44, Sam Hokin wrote:

> I want to do a query in a post-processor which simply grabs the genes
> and their proteins, which have primary identifiers which contain the
> gene's primary identifier (e.g. gene=cicar.ICC4958.gnm2.ann1.Ca_00006,
> protein=cicar.ICC4958.gnm2.ann1.Ca_00006.1).
>
> But this query bombs with a vague error message:
>
> // query Genes and Proteins with the corresponding primaryIdentifiers
> Query query = new Query();
> query.setDistinct(false);
>
> QueryClass qcGene = new QueryClass(Gene.class);
> query.addFrom(qcGene);
> query.addToSelect(qcGene);
>
> QueryClass qcProtein = new QueryClass(Protein.class);
> query.addFrom(qcProtein);
> query.addToSelect(qcProtein);
>
> query.setConstraint(new SimpleConstraint(
> new QueryField(qcProtein,"primaryIdentifier"),
> ConstraintOp.CONTAINS,
> new QueryField(qcGene,"primaryIdentifier")));
>
> After testing, it appears that ConstraintOp.CONTAINS is not allowed; I
> can run the query with ConstraintOp.EQUALS between proteins and
> transcripts (which have the same primaryIdentifier).
>
> Any way to do this in a single query? I'm running a protein query
> inside a loop off the gene query right now, which is slowwwwww (but
> acceptable if that's the only way to do it).
>
> _______________________________________________
> dev mailing list
> [hidden email]
> https://lists.intermine.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
https://lists.intermine.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Why can't I do a simple CONTAINS constraint with Query?

Daniela Butano-2
In reply to this post by Sam Hokin-3
Hi Sam,
I would suggest you to try the ContainsConstraint instead of the
SimpleConstraint.
This is an example (copied from the TransferSequences)

         Query q = new Query();
         QueryClass qcChr = new QueryClass(Chromosome.class);
         q.addFrom(qcChr);
         q.addToSelect(qcChr);
         QueryObjectReference seqRef = new QueryObjectReference(qcChr,
"sequence");
         ContainsConstraint cc = new ContainsConstraint(seqRef,
ConstraintOp.IS_NOT_NULL);
         q.setConstraint(cc);
Instead of QueryObjectReference, I suspect you have to use the
QueryCollectionReference due the relation between protein->genes

Daniela

> I want to do a query in a post-processor which simply grabs the genes
> and their proteins, which have primary identifiers which contain the
> gene's primary identifier (e.g. gene=cicar.ICC4958.gnm2.ann1.Ca_00006,
> protein=cicar.ICC4958.gnm2.ann1.Ca_00006.1).
>
> But this query bombs with a vague error message:
>
> // query Genes and Proteins with the corresponding primaryIdentifiers
> Query query = new Query();
> query.setDistinct(false);
>
> QueryClass qcGene = new QueryClass(Gene.class);
> query.addFrom(qcGene);
> query.addToSelect(qcGene);
>
> QueryClass qcProtein = new QueryClass(Protein.class);
> query.addFrom(qcProtein);
> query.addToSelect(qcProtein);
>
> query.setConstraint(new SimpleConstraint(
> new QueryField(qcProtein,"primaryIdentifier"),
> ConstraintOp.CONTAINS,
> new QueryField(qcGene,"primaryIdentifier")));
>
> After testing, it appears that ConstraintOp.CONTAINS is not allowed; I
> can run the query with ConstraintOp.EQUALS between proteins and
> transcripts (which have the same primaryIdentifier).
>
> Any way to do this in a single query? I'm running a protein query
> inside a loop off the gene query right now, which is slowwwwww (but
> acceptable if that's the only way to do it).
>
> _______________________________________________
> dev mailing list
> [hidden email]
> https://lists.intermine.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
https://lists.intermine.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Why can't I do a simple CONTAINS constraint with Query?

Sam Hokin-3
In reply to this post by sergio contrino-2
We can use SQL in Query??

On 5/4/20 9:31 AM, [hidden email] wrote:
> hi sam!
> i have not checked why contains is not enabled, and i could be missing something else, but have you tried a like clause with %
> before and after?
> thanks
> sergio
_______________________________________________
dev mailing list
[hidden email]
https://lists.intermine.org/mailman/listinfo/dev