Best Python code snippet using autotest_python
clinvar_xml_parser.py
Source:clinvar_xml_parser.py  
...120        if (variation_type == 'copy number loss') or (variation_type == 'copy number gain'):121            for AttributeSet in measure_obj.AttributeSet:122                if 'HGVS, genomic, top level' in AttributeSet.Attribute.Type:123                    if AttributeSet.Attribute.integerValue == 37:124                        hgvs_genome = AttributeSet.Attribute.get_valueOf_()125                if 'genomic' in AttributeSet.Attribute.Type:126                    HGVS['genomic'].append(AttributeSet.Attribute.get_valueOf_())127                elif 'non-coding' in AttributeSet.Attribute.Type:128                    HGVS['non-coding'].append(AttributeSet.Attribute.get_valueOf_())129                elif 'coding' in AttributeSet.Attribute.Type:130                    HGVS['coding'].append(AttributeSet.Attribute.get_valueOf_())131                elif 'protein' in AttributeSet.Attribute.Type:132                    HGVS['protein'].append(AttributeSet.Attribute.get_valueOf_())133        else:134            for AttributeSet in measure_obj.AttributeSet:135                if 'genomic' in AttributeSet.Attribute.Type:136                    HGVS['genomic'].append(AttributeSet.Attribute.get_valueOf_())137                elif 'non-coding' in AttributeSet.Attribute.Type:138                    HGVS['non-coding'].append(AttributeSet.Attribute.get_valueOf_())139                elif 'coding' in AttributeSet.Attribute.Type:140                    HGVS['coding'].append(AttributeSet.Attribute.get_valueOf_())141                elif 'protein' in AttributeSet.Attribute.Type:142                    HGVS['protein'].append(AttributeSet.Attribute.get_valueOf_())143                if not hgvs_coding and AttributeSet.Attribute.Type == 'HGVS, coding, RefSeq':144                    hgvs_coding = AttributeSet.Attribute.get_valueOf_()145                if not hgvs_genome and AttributeSet.Attribute.Type == 'HGVS, genomic, top level, previous':146                    hgvs_genome = AttributeSet.Attribute.get_valueOf_()147        if chrom and chromStart and chromEnd:148            # if its SNP, make sure chrom, chromStart, chromEnd, ref, alt are all provided149            if variation_type == 'single nucleotide variant':150                if ref and alt:151                    hgvs_id = "chr%s:g.%s%s>%s" % (chrom, chromStart, ref, alt)152                else:153                    print('hgvs not found chr {}, chromStart {}, chromEnd {}, ref {}, alt {}, allele id {}'.154                          format(chrom, chromStart, chromEnd, ref, alt, allele_id))155            # items whose type belong to 'Indel, Insertion, \156            # Duplication' might not hava explicit alt information, \157            # so we will parse from hgvs_genome158            elif variation_type == 'Indel':159                # RCV000156073, NC_000010.10:g.112581638_112581639delinsG160                if hgvs_genome:161                    indel_position = hgvs_genome.find('del')162                    indel_alt = hgvs_genome[indel_position+3:]163                    hgvs_id = "chr%s:g.%s_%sdel%s" % (chrom, chromStart, chromEnd, indel_alt)164            elif variation_type == 'Deletion':165                if chromStart == chromEnd:166                    # RCV000048406, chr17:g.41243547del167                    hgvs_id = "chr%s:g.%sdel" % (chrom, chromStart)168                else:169                    hgvs_id = "chr%s:g.%s_%sdel" % (chrom, chromStart, chromEnd)170            elif variation_type == 'Insertion':171                if hgvs_genome:172                    ins_position = hgvs_genome.find('ins')173                    if 'ins' in hgvs_genome:174                        ins_ref = hgvs_genome[ins_position+3:]175                        if chromStart == chromEnd:176                            hgvs_id = "chr%s:g.%sins%s" % (chrom, chromStart, ins_ref)177                        else:178                            hgvs_id = "chr%s:g.%s_%sins%s" % (chrom, chromStart, chromEnd, ins_ref)179            elif variation_type == 'Duplication':180                if hgvs_genome:181                    dup_position = hgvs_genome.find('dup')182                    if 'dup' in hgvs_genome:183                        dup_ref = hgvs_genome[dup_position+3:]184                        if chromStart == chromEnd:185                            hgvs_id = "chr%s:g.%sdup%s" % (chrom, chromStart, dup_ref)186                        else:187                            hgvs_id = "chr%s:g.%s_%sdup%s" % (chrom, chromStart, chromEnd, dup_ref)188        elif variation_type == 'copy number loss' or variation_type == 'copy number gain':189            if hgvs_genome and chrom:190                hgvs_id = "chr" + chrom + ":" + hgvs_genome.split('.')[2]191        elif hgvs_coding:192            hgvs_id = hgvs_coding193            coding_hgvs_only = True194        else:195            return196    else:197        return198    for key in HGVS:199        HGVS[key].sort()200    rsid = None201    cosmic = None202    dbvar = None203    uniprot = None204    omim = None205    # loop through XRef to find rsid as well as other ids206    if measure_obj.XRef:207        for XRef in measure_obj.XRef:208            if XRef.Type == 'rs':209                rsid = 'rs' + str(XRef.ID)210            elif XRef.DB == 'COSMIC':211                cosmic = XRef.ID212            elif XRef.DB == 'OMIM':213                omim = XRef.ID214            elif XRef.DB == 'UniProtKB/Swiss-Prot':215                uniprot = XRef.ID216            elif XRef.DB == 'dbVar':217                dbvar = XRef.ID218    # make sure the hgvs_id is not none219    if hgvs_id:220        one_snp_json = {221            "_id": hgvs_id,222            "clinvar": {223                "allele_id": allele_id,224                "chrom": chrom,225                "omim": omim,226                "cosmic": cosmic,227                "uniprot": uniprot,228                "dbvar": dbvar,229                "hg19": {230                    "start": chromStart_19,231                    "end": chromEnd_19232                },233                "hg38": {234                    "start": chromStart_38,235                    "end": chromEnd_38236                },237                "type": variation_type,238                "gene": {239                    "id": gene_id,240                    "symbol": symbol241                },242                "rcv": {243                    "preferred_name": name,244                },245                "rsid": rsid,246                "cytogenic": cytogenic,247                "hgvs": HGVS,248                "coding_hgvs_only": coding_hgvs_only,249                "ref": ref,250                "alt": alt251            }252        }253        return one_snp_json254def _map_public_set_to_json(public_set_obj, hg19: bool):255    """256    Convert a `clinvarlib.PublicSetType` object into a json document.257    Each `clinvarlib.PublicSetType` object is mapped to a `<ClinVarSet>` block in the XML.258    E.g., `public_set_obj.ReferenceClinVarAssertion.MeasureSet` is the parsed value from a block structure below:259        <ClinVarSet ...>260          <ReferenceClinVarAssertion ...>261            <MeasureSet ...>262              ...263            </MeasureSet>264          </ReferenceClinVarAssertion>265        </ClinVarSet>266    """267    try:268        clinical_significance = public_set_obj.ReferenceClinVarAssertion.ClinicalSignificance.Description269    except:270        clinical_significance = None271    rcv_accession = public_set_obj.ReferenceClinVarAssertion.ClinVarAccession.Acc272    try:273        review_status = public_set_obj.ReferenceClinVarAssertion.ClinicalSignificance.ReviewStatus274    except:275        review_status = None276    try:277        last_evaluated = public_set_obj.ReferenceClinVarAssertion.ClinicalSignificance.DateLastEvaluated278    except:279        last_evaluated = None280    281    number_submitters = len(public_set_obj.ClinVarAssertion)282    # some items in clinvar_xml doesn't have origin information283    try:284        origin = public_set_obj.ReferenceClinVarAssertion.ObservedIn[0].Sample.Origin285    except:286        origin = None287    conditions = []288    for _trait in public_set_obj.ReferenceClinVarAssertion.TraitSet.Trait:289        synonyms = []290        conditions_name = ''291        for name in _trait.Name:292            if name.ElementValue.Type == 'Alternate':293                synonyms.append(name.ElementValue.get_valueOf_())294            if name.ElementValue.Type == 'Preferred':295                conditions_name += name.ElementValue.get_valueOf_()296        identifiers = {}297        for item in _trait.XRef:298            if item.DB == 'Human Phenotype Ontology':299                key = 'Human_Phenotype_Ontology'300            else:301                key = item.DB302            identifiers[key.lower()] = item.ID303        for symbol in _trait.Symbol:304            if symbol.ElementValue.Type == 'Preferred':305                conditions_name += ' (' + symbol.ElementValue.get_valueOf_() + ')'306        age_of_onset = ''307        for _set in _trait.AttributeSet:308            if _set.Attribute.Type == 'age of onset':309                age_of_onset = _set.Attribute.get_valueOf_()310        conditions.append({"name": conditions_name, "synonyms": synonyms, "identifiers": identifiers,311                           "age_of_onset": age_of_onset})312    try:313        genotypeset = public_set_obj.ReferenceClinVarAssertion.GenotypeSet314    except:315        genotypeset = None316    if genotypeset:317        obj_list = []318        id_list = []319        for _set in public_set_obj.ReferenceClinVarAssertion.GenotypeSet.MeasureSet:320            variant_id = _set.ID321            for _measure in _set.Measure:322                json_obj = _map_measure_to_json(_measure, hg19=hg19)323                if json_obj:...wxCSV.py
Source:wxCSV.py  
...23def processForecast(inXML, N):24  rootObj = ForeSupermod.parseString(inXML, True)25  print "----------------------------------------------"26  print "Forecast Length (hrs): " + str(len(rootObj.data[0].parameters[0].temperature[0].value))27  print "Date: " + rootObj.head.product.creation_date.get_valueOf_()28  pyObsTime = datetime.datetime.strptime(rootObj.head.product.creation_date.get_valueOf_()[:-6], 29    "%Y-%m-%dT%H:%M:%S")30  print "Location: " + rootObj.data[0].location[0].city.get_valueOf_()31  print "Multiple Prediction Test"32  for ii in range(0,len(rootObj.data[0].parameters[0].temperature[0].value)):33    forecast = Forecast()34    forecast.forecasttime = pyObsTime35    forecast.location = rootObj.data[0].location[0].city.get_valueOf_()36    print "Time: " + rootObj.data[0].time_layout[0].start_valid_time[ii].get_valueOf_(),37    starttime = datetime.datetime.strptime(rootObj.data[0].time_layout[0].start_valid_time[ii].get_valueOf_()[:-6], 38      "%Y-%m-%dT%H:%M:%S")39    forecast.starttime = starttime40    print "to " + str(rootObj.data[0].time_layout[0].end_valid_time[ii])41    endtime = datetime.datetime.strptime(str(rootObj.data[0].time_layout[0].end_valid_time[ii])[:-6], 42      "%Y-%m-%d %H:%M:%S")43    forecast.stoptime = endtime44    for t in rootObj.data[0].parameters[0].temperature:45      print "Temp type " + t.get_type(),46      if(t.value[ii].get_valueOf_() == ''):47        v = None48      else:49        v = t.value[ii].get_valueOf_()50      if(t.get_type() == 'dew point'):51        forecast.dewpoint = v52      if(t.get_type() == 'wind chill'):53        forecast.windchill = v54      if(t.get_type() == 'hourly'):55        forecast.temperature = v56      print v57    print "precipitation probability: " + rootObj.data[0].parameters[0].probability_of_precipitation[0].value[ii].get_valueOf_()58    if(rootObj.data[0].parameters[0].probability_of_precipitation[0].value[ii].get_valueOf_() == ''):59      forecast.precipprob = None60    else:61      forecast.precipprob = rootObj.data[0].parameters[0].probability_of_precipitation[0].value[ii].get_valueOf_()62    for w in rootObj.data[0].parameters[0].wind_speed:63      print "wind " + w.get_type() + ': ' + w.value[ii].get_valueOf_()64      if(w.get_type() == 'sustained'):65        forecast.windspeed = w.value[ii].get_valueOf_()66        if(w.value[ii].get_valueOf_() == ''):67          forecast.windspeed = None68          print "no wind speed value"69        else:70          forecast.windspeed = w.value[ii].get_valueOf_()71      if(w.get_type() == 'gust'):72        if(w.value[ii].get_valueOf_() == ''):73          forecast.windgust = None74          print "no wind gust value"75        else:76          forecast.windgust = w.value[ii].get_valueOf_()77    for d in rootObj.data[0].parameters[0].direction:78      print "direction of " + d.get_type() + ": " + d.value[ii].get_valueOf_()79      if(d.get_type() == 'wind'):80        if(d.value[ii].get_valueOf_() == ''):81          forecast.winddir = None82          print "no wind dir value"83        else:84          forecast.winddir = d.value[ii].get_valueOf_()85    forecast.save()86def processCurrent(inXML):87  rootObj = CurSupermod.parseString(inXML, True)88  curObs = Currentobs() # current observation sql object89  print "Current Observation"90  print "Station ID: " + rootObj.station_id91  curObs.station = rootObj.station_id92  print "Observation Time: " + rootObj.observation_time_rfc82293  #pyObsTime = datetime.datetime.strptime(rootObj.observation_time_rfc822, "Last Updated on %b %d %Y, %I:%M %p %Z")94  pyObsTime = datetime.datetime.strptime(rootObj.observation_time_rfc822[:-6], "%a, %d %b %Y %H:%M:%S")95  curObs.obstime = pyObsTime96  print "Current Temp: " + str(rootObj.temp_f) + " F"97  curObs.temperature = rootObj.temp_f98  print "Rel Humidity: " + str(rootObj.relative_humidity) + "%"...script.py
Source:script.py  
...18	for event in instance.AuditTrailEntry:19		e = xes.Event()20		activity = event.get_WorkflowModelElement()21		e.add_attribute(xes.Attribute(type="string", key="concept:name", value=activity))22		event_type = event.get_EventType().get_valueOf_()23		e.add_attribute(xes.Attribute(type="string", key="lifecycle:transition", value=event_type))24		timestamp = event.Timestamp.get_valueOf_()25		e.add_attribute(xes.Attribute(type="date", key="time:timestamp", value=timestamp))26		attributes = {}27		for attribute in event.Data.Attribute:28			attributes[attribute.get_name()]=attribute.get_valueOf_()29		for key,value in attributes.items():30			e.add_attribute(xes.Attribute(type="string", key=key, value=value))31		trace.add_event(e)32	output.add_trace(trace)33base_filename = ".".join(os.path.basename(filename).split('.')[0:-1])34#output_filename = filename.replace(".mxml",".xes")35output_filename = base_filename+".xes"36with open(output_filename, "w") as f:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
