def import_HXcolumns(infile, sequence, name=None, percentD=False, conditions=None, error_estimate=5.0, n_fastamides=2, offset=0): """ Function for converting a set of HX columns intoa Dataset object """ if type(conditions) is not Conditions: print("Standard Conditions used. Please modify these in the script if you are not at 283K and pH=7") conditions = Conditions() f = open(infile,"r") line = f.readline() dataset = Dataset(name=name, sequence=sequence, conditions=conditions, error_estimate=error_estimate, offset=offset, input_file=infile) column_headers = line.rstrip().split(",") # Pre-set to None. See #XXXX for line in f.readlines(): fields = line.split(",") sequence = fields[column_headers.index("peptide_seq")] start_res = int(fields[column_headers.index("start_res")]) + offset time = float(fields[column_headers.index("time")]) deut = float(fields[column_headers.index("D_inc")]) if not percentD: deut = deut / tools.calculate_number_of_observable_amides(sequence, n_fastamides) * 100 score = float(fields[column_headers.index("score")]) new_peptide = dataset.create_peptide(sequence, start_res) if new_peptide is not None: # If the time is 0.0, that's weird. Ignore that. if time==0.0: continue if deut < 105: # XXX Hard coded cap on %D value. Not ideal. new_timepoint=True # If timepoint is already in fragment, grab that timepoint if time in [tp.time for tp in new_peptide.get_timepoints()]: tp = new_peptide.get_timepoint_by_time(time) #If not, add a new timepoint at this time. What to put for sigma?? else: tp = new_peptide.add_timepoint(time) # add the deuteration value as a replicate. # Any other replicate information from the file should be added at this step. tp.add_replicate(deut, score=score) new_peptide.add_timepoint(time) dataset.calculate_observable_rate_bounds() dataset.calculate_observable_protection_factors() return dataset
def import_json(infile, name=""): # Imports a json written by Dataset.write_to_file() import json #print(infile) with open(infile) as json_data: d = json.load(json_data) cond_dict = d["conditions"] conditions = Conditions() for a in cond_dict: conditions.a = cond_dict[a] dataset = Dataset(d["name"], conditions, d["sequence"], input_file = d["raw_data_file"], error_estimate = d["error_estimate"], offset = d["offset"], number_fast_exchanging_amides = d["num_fast_exchanging_amides"], percent_deuterium = d["percent_deuterium"]) pep_dict = d['peptides'] for pep in pep_dict: p = pep_dict[str(pep)] peptide = dataset.create_peptide(p["sequence"], p["start_residue"], peptide_id=pep, charge_state=p["charge_state"], retention_time=p["retention_time"], sigma=p["sigma"]) tp_dict = p["timepoints"] for tp in tp_dict: timepoint = peptide.add_timepoint(tp_dict[str(tp)]["time"], tp_dict[str(tp)]["sigma"]) reps = tp_dict[str(tp)]["replicates"] for rep in reps: timepoint.add_replicate(reps[str(rep)]["deut"], experiment_id=reps[str(rep)]["experiment_id"], score=reps[str(rep)]["reliability"], rt=reps[str(rep)]["rt"]) return dataset