Пример #1
0
def map_signature(request, pk):
    signature = Signature.objects.get(pk=pk)
    taxid = signature.species.taxid
    transcripts = signature.transcripts.all()
    taxid = signature.species.taxid
    mapped = 0
    transcript_count = transcripts.count()
    counter = Counter(transcript_count)

    #geneExpressions = GeneExpressions()

    for transcript in transcripts:
        counter.count()
        gene_id = mapid(transcript.seq_id, taxid=taxid)
        #print transcript, gene_id
        if gene_id and isinstance(gene_id, int):
            transcript.entrez_gene_id = gene_id
            transcript.save()
            #t = Transcript.objects.get(pk = transcript.pk)
            #print("T: %s %s %s" % (t.pk, t.seq_id, t.entrez_gene_id))
            #print transcript, transcript.entrez_gene_id
#        if gene_id:
#            gene, created = Gene.objects.get_or_create(id=gene_id, species_id=taxid)
#            if gene_id not in geneExpressions:
#                geneExpressions[gene_id] = GeneExpression(id, transcript, signature)
#            else:
#                geneExpressions[gene_id].add(transcript, signature)
#            signature.genes.add(gene)
            mapped += 1

    msg = 'Mapped %s' % (100.*mapped/transcript_count)
    messages.add_message(request, messages.INFO, _(msg))
    #genes = signatures.genes.all()

    return redirect('/expressions/signatures/')
Пример #2
0
    def save(self, *args,
             **kwargs):  #TODO: must be splitted into several methods
        if not self.pk:
            self.mean = percentage(self.exp.mean, self.ctr.mean) or self.mean
            self.median = percentage(self.exp.median,
                                     self.ctr.median) or self.median
            self.max = percentage(self.exp.max, self.ctr.max) or self.max

            if self.exp.genotype:
                interventions = Intervention.objects.filter(
                    name__icontains=self.exp.genotype)
            elif self.exp.diet:
                interventions = Intervention.objects.filter(
                    name__icontains=self.exp.diet)
            else:
                interventions = []
                #Q(name__icontains=self.exp.genotype) | Q(name__icontains=self.ctr.genotype))
            #print("%s %s %s" % (self.exp.genotype, self.ctr.genotype, interventions))
            for intervention in interventions:
                self.intervention = intervention
                #print("mapping")
            if self.exp.genotype:
                if "/" in self.exp.genotype.name:
                    genotype = self.exp.genotype.name.split('/')[0]
                else:
                    genotype = self.exp.genotype.name
                if "(" in genotype:
                    genotype = genotype.split('(')[0].rstrip()
                    #print("map id")
                #print(genotype)
                id = mapid(genotype, self.exp.experiment.species.taxid)
                #print("mapped")
            else:
                id = None
            if id:
                try:
                    factor = Factor.objects.get(entrez_gene_id=id)
                    interventions = factor.intervention.all()
                    if interventions:
                        self.intervention = interventions[0]
                except ObjectDoesNotExist:
                    pass  # Make message
                    #print("ObjectDoesNotExist %s" % id)
                except MultipleObjectsReturned:
                    pass  # Make message
                    #print("MultipleObjectsReturned %s" % id)

                    #print self.intervention
                    #else: factor = ''
                    #print("Mapped factor: %s = %s (%s) %s" % (genotype, id, factor, interventions))

        super(Comparison, self).save(*args, **kwargs)
Пример #3
0
    def save(self, *args, **kwargs):
        if not self.pk:
            self.mean = percentage(self.exp.mean, self.ctr.mean) or self.mean
            self.median = percentage(self.exp.median, self.ctr.median) or self.median
            self.max = percentage(self.exp.max, self.ctr.max) or self.max

            if self.exp.genotype:
                interventions = Intervention.objects.filter(name__icontains=self.exp.genotype)
            elif self.exp.diet:
                interventions = Intervention.objects.filter(name__icontains=self.exp.diet)
            else:
                interventions = []
                #Q(name__icontains=self.exp.genotype) | Q(name__icontains=self.ctr.genotype))
            #print("%s %s %s" % (self.exp.genotype, self.ctr.genotype, interventions))
            for intervention in interventions:
                self.intervention = intervention
            #print("mapping")
            if self.exp.genotype:
                if "/" in self.exp.genotype.name:
                    genotype = self.exp.genotype.name.split('/')[0]
                else:
                    genotype = self.exp.genotype.name
                if "(" in genotype:
                    genotype = genotype.split('(')[0].rstrip()
                #print("map id")
                #print(genotype)
                id = mapid(genotype, self.exp.experiment.species.taxid)
                #print("mapped")
            else:
                id = None
            if id:
                try:
                    factor = Factor.objects.get(entrez_gene_id=id)
                    interventions = factor.intervention.all()
                    if interventions:
                        self.intervention = interventions[0]
                except ObjectDoesNotExist:
                    pass # Make message
                    #print("ObjectDoesNotExist %s" % id)
                except MultipleObjectsReturned:
                    pass # Make message
                    #print("MultipleObjectsReturned %s" % id)

                    #print self.intervention
            #else: factor = ''
            #print("Mapped factor: %s = %s (%s) %s" % (genotype, id, factor, interventions))

        super(Comparison, self).save(*args, **kwargs)
Пример #4
0
def map_signature(request, pk):
    signature = Signature.objects.get(pk=pk)
    taxid = signature.species.taxid
    transcripts = signature.transcripts.all()
    taxid = signature.species.taxid
    mapped = 0
    transcript_count = transcripts.count()
    counter = Counter(transcript_count)

    #geneExpressions = GeneExpressions()

    for transcript in transcripts:
        counter.count()
        gene_id = mapid(transcript.seq_id, taxid=taxid)
        #print transcript, gene_id
        if gene_id and isinstance(gene_id, int):
            transcript.entrez_gene_id = gene_id
            transcript.save()
            #t = Transcript.objects.get(pk = transcript.pk)
            #print("T: %s %s %s" % (t.pk, t.seq_id, t.entrez_gene_id))
            #print transcript, transcript.entrez_gene_id
            #        if gene_id:
            #            gene, created = Gene.objects.get_or_create(id=gene_id, species_id=taxid)
            #            if gene_id not in geneExpressions:
            #                geneExpressions[gene_id] = GeneExpression(id, transcript, signature)
            #            else:
            #                geneExpressions[gene_id].add(transcript, signature)
            #            signature.genes.add(gene)
            mapped += 1

    msg = 'Mapped %s' % (100. * mapped / transcript_count)
    messages.add_message(request, messages.INFO, _(msg))
    #genes = signatures.genes.all()

    return redirect('/expressions/signatures/')


#234567891123456789212345678931234567894123456789512345678961234567897123456789
Пример #5
0
def map_signatures(request):
    print ("Initializing mapping.")
    signatures = Signature.objects.all()
    mapped = 0
    total = 0
    for signature in signatures:
        print ("Signature: %s" % signature)
        taxid = signature.species.taxid
        transcripts = signature.transcripts.all()
        transcript_count = transcripts.count()
        total += transcript_count
        counter = Counter(transcript_count)
        for transcript in transcripts:
            counter.count()
            gene_id = mapid(str(transcript.seq_id), taxid=taxid)
            if gene_id and isinstance(gene_id, int):
                transcript.entrez_gene_id = gene_id
                transcript.save()
                mapped += 1
            # print transcript, transcript.entrez_gene_id
    msg = "Mapped %s" % (100.0 * mapped / total)
    messages.add_message(request, messages.INFO, _(msg))
    return redirect("/expressions/signatures/")
Пример #6
0
def map_signatures(request):
    print("Initializing mapping.")
    signatures = Signature.objects.all()
    mapped = 0
    total = 0
    for signature in signatures:
        if not "Timeless" in signature.name: continue
        print("Signature: %s" % signature)
        taxid = signature.species.taxid
        transcripts = signature.transcripts.all()
        transcript_count = transcripts.count()
        total += transcript_count
        counter = Counter(transcript_count)
        for transcript in transcripts:
            counter.count()
            gene_id = mapid(str(transcript.seq_id), taxid=taxid)
            if gene_id and isinstance(gene_id, int):
                transcript.entrez_gene_id = gene_id
                transcript.save()
                mapped += 1
            #print transcript, transcript.entrez_gene_id
    msg = "Mapped %s" % (100. * mapped / total)
    messages.add_message(request, messages.INFO, _(msg))
    return redirect('/expressions/signatures/')