Esempio n. 1
0
def table_platform(request):
   '''
   Display the div table of the
   first 10 line of the given platform
   '''
   if request.is_ajax():
      if request.method == 'POST':
         try:
            list_annot = request.POST['list_annot']
         except MultiValueDictKeyError:
            list_annot = ''
         platform_id = request.POST['platform_id']
         if list_annot == '':
            table = geo_annot_tab(platform_id,10)
            return HttpResponse(table,mimetype="text/html")
         else:
            args =  simplejson.dumps(platform_id)+','+list_annot
            send_to_queue('ocelot.Platforms.utils','get_geo_annot_split',args)
            return HttpResponse('The request was sent to the queue.',mimetype="text/html")
            #return HttpResponseRedirect('/admin/chip/')
      else:
         return HttpResponse("Not Found",mimetype="text/plain")
   else:
      return HttpResponse("Not Found",mimetype="text/plain")
Esempio n. 2
0
def DSparse(request,dataset_id):
   '''
   Parse the XML and display the various information
   of the dataset...might be dismiss in order to do it
   client side with JavaSrcipt
   '''
   dictionary = list(Dictionary.objects.filter(dataset_id = dataset_id))
   metainfo   = list(MetaInfo.objects.filter(dataset_id = dataset_id))
   if not dictionary:
      return HttpResponseRedirect('/admin/geo/')
   else:
      dictionary = dictionary[0]
      if not metainfo:   
         metainfo = MetaInfo(dataset_id = dataset_id)
      else:
         metainfo = metainfo[0]
   datasets = list(Datasets.objects.all())
   platforms = GPL2title(dataset_id)
   platform_list = []
   for platform in platforms:
      platform_list.append(platform['id'])
   metainfo.platform = ",".join(platform_list)
   # Collect the metainfo to pass to the
   # Autocomplete
   treatments = []
   subtypes   = []
   diseases   = []
   for dataset in datasets:
      treats = dataset.treatment.split(',')
      for treatment in treats:
         if treatment not in treatments:
            treatments.append(treatment.strip())
      dis = dataset.disease.split(',')
      for disease in dis:
         if disease not in diseases:
            diseases.append(disease.strip())
      subtps = dataset.subtype.split(',')
      for subtype in subtps:
         if subtype not in subtypes:
            subtypes.append(subtype.strip())
   treatments = simplejson.dumps(treatments)
   subtypes   = simplejson.dumps(subtypes)
   diseases   = simplejson.dumps(diseases)
   req = getGEOurl(dataset_id,'meta')
   with contextlib.closing(urlopen(req)) as geo:
      DS = GEOdsParse(geo)
   acc = DS['accessions'].split(' ')
   for a in acc:
      if not a.startswith('GSM'):
         acc.remove(a)
   released = DS['released'].split('-')
   metainfo.released = datetime.date(int(released[0].strip()),int(released[1].strip()),int(released[2].strip()))
   metainfo.saved = datetime.date.today()
   del DS['released']
   del DS['accessions']
   acclen = len(acc)
   doGSMtable.needs_autoescape = True
   GSMtable = doGSMtable(dataset_id)
   # Form part:
   if request.method == 'GET':
      dictform = geoforms.GEOForm(instance=dictionary)
      metaform = geoforms.GEOMetaForm(instance=metainfo)
   if request.method == 'POST':
      dictform = geoforms.GEOForm(data=request.POST,instance=dictionary)
      metaform = geoforms.GEOMetaForm(data=request.POST,instance=metainfo)
      if dictform.is_valid() and metaform.is_valid():
         dictform.save()
         metaform.save()
         dictionary = Dictionary.objects.get(dataset_id__exact = dataset_id)
         metainfo   = MetaInfo.objects.get(dataset_id__exact = dataset_id)
         metainfo.treatment = metainfo.treatment.replace(', ',',').strip(',')
         metainfo.subtype   = metainfo.subtype.replace(', ',',').strip(',')
         metainfo.disease   = metainfo.disease.replace(', ',',').strip(',')
         metainfo.samples_count = acclen
         metainfo.save()
         for platform in platforms:
            plt = list(Platform.objects.filter(platform_id = platform['id']))
            if not plt:
               plt = Platform(platform_id = platform['id'], name = platform['title'] )
               plt.save()
         already_indexed = list(Datasets.objects.filter(dataset_id__exact = dataset_id))
         if already_indexed:
            RegisterGSE(dictionary,metainfo)
         send_to_queue('ocelot.pyGEO.utils','get_express',simplejson.dumps(dataset_id))
         return HttpResponseRedirect('/admin/geo/')
   payload = dict(platforms=platforms, dictform=dictform, metaform=metaform, DS=DS, GSMtable=GSMtable, dataset_id=dataset_id, acclen=acclen, treatments=treatments, diseases=diseases, subtypes=subtypes)
   return render_to_response('geo_parse.html',payload,RequestContext(request))