def parse_peak_line(self, line, dim):

        fields = string.split(line, None, dim + 1)
        if len(fields) < dim + 1:
            return None

        assignment = sputil.parse_assignment(fields[0])
        if assignment == None or len(assignment) != dim:
            self.unreadable.listbox.insert('end', line)
            return None

        frequency = []
        for a in range(dim):
            f = pyutil.string_to_float(fields[a + 1])
            if f == None:
                self.unreadable.listbox.insert('end', line)
                return None
            frequency.append(f)

        if len(fields) > dim + 1:
            note = fields[dim + 1]
        else:
            note = ''

        return (assignment, frequency, note)
Beispiel #2
0
  def parse_peak_line(self, line, dim):

    fields = string.split(line, None, dim + 1)
    if len(fields) < dim + 1:
      return None

    assignment = sputil.parse_assignment(fields[0])
    if assignment == None or len(assignment) != dim:
      self.unreadable.listbox.insert('end', line)
      return None

    frequency = []
    for a in range(dim):
      f = pyutil.string_to_float(fields[a+1])
      if f == None:
        self.unreadable.listbox.insert('end', line)
        return None
      frequency.append(f)

    if len(fields) > dim + 1:
      note = fields[dim + 1]
    else:
      note = ''

    return (assignment, frequency, note)
Beispiel #3
0
	def write_npc_cb(self):
		fileName = os.path.abspath(self.npc_write_path.get())
		diaSpec = self.dia_menu.spectrum()
		paraSpec = self.para_menu.spectrum()

		if not all([diaSpec, paraSpec, fileName]):
			raise IOError("You need to select two spectra and a valid file name")

		dia = self.unpack_peaks(diaSpec.peak_list())
		para = self.unpack_peaks(paraSpec.peak_list())
		common = set(dia) & set(para)

		pcs = {}
		for assig in common:
			new_freq = []
			for d, p in zip(dia[assig], para[assig]):
				new_freq.append(p-d)
			pcs[assig] = tuple(new_freq)

		out = {}
		for assig in pcs:
			for (tmp, atom), value in zip(sputil.parse_assignment(assig), pcs[assig]):
				seq = int(re.findall(r"\d+", tmp)[0])
				out[(seq, atom)] = value

		with open(fileName, 'w') as f:
			for key in sorted(out):
				seq, atom = key
				line = "{0:<3d} {1:<3s} {2:6.3f} 0.000\n".format(
					seq, atom, out[key])
				f.write(line)

		self.message['text'] = "PCS values written to file: \n{}".format(fileName)
Beispiel #4
0
    def write_npc_cb(self):
        fileName = os.path.abspath(self.npc_write_path.get())
        diaSpec = self.dia_menu.spectrum()
        paraSpec = self.para_menu.spectrum()

        if not all([diaSpec, paraSpec, fileName]):
            raise IOError(
                "You need to select two spectra and a valid file name")

        dia = self.unpack_peaks(diaSpec.peak_list())
        para = self.unpack_peaks(paraSpec.peak_list())
        common = set(dia) & set(para)

        pcs = {}
        for assig in common:
            pd = dia[assig]
            pp = para[assig]
            freq = [p - d for d, p in zip(pd.frequency, pp.frequency)]
            edia = []
            for i in range(diaSpec.dimension):
                taq = float(self.dia_acqu.variables[i].get())
                tmp = ((2. / 3.) * diaSpec.noise) / (pd.data_height * taq *
                                                     diaSpec.hz_per_ppm[i])
                edia.append(tmp)

            epara = []
            for i in range(paraSpec.dimension):
                taq = float(self.para_acqu.variables[i].get())
                tmp = ((2. / 3.) * paraSpec.noise) / (pp.data_height * taq *
                                                      paraSpec.hz_per_ppm[i])
                epara.append(tmp)

            error = [(d**2 + p**2)**0.5 for d, p in zip(edia, epara)]
            pcs[assig] = tuple(freq), tuple(error)

        out = {}
        for assig in pcs:
            for (tmp,
                 atom), value, error in zip(sputil.parse_assignment(assig),
                                            *pcs[assig]):
                grp, seq = sputil.parse_group_name(tmp)
                out[(seq, atom)] = value, error

        with open(fileName, 'w') as f:
            for key in sorted(out):
                seq, atom = key
                line = "{0:<3d} {1:<3s} {2:6.3f} {3:8.6f}\n".format(
                    seq, atom, out[key][0], out[key][1])
                f.write(line)

        self.message['text'] = "PCS values written to file: \n{}".format(
            fileName)
    def LabelBox(self):

        self.label_list.clear()

        # append labels which are located on the selected peak
        iIndex = -1
        if self.spectrum == None:  # if there is no selected spectrum, exit this function.
            return
        if self.peak == None:
            return
        szPos = '('
        for pos in self.peak.position:
            szPos = szPos + ('%7.3f,' % pos).strip()
        szPos = szPos.rstrip(',')
        szPos = szPos + ')'
        #----------------------------------------------------------------------------------------------
        f = open(self.spectrum.save_path + '_pl', 'r')
        try:
            for label in f.readlines():
                label = label.strip()
                if label.find(szPos) <> -1:
                    #tkMessageBox.showinfo('szPos',szPos)
                    # find label object
                    iFound = 0
                    for pLabel in self.spectrum.label_list():
                        if pLabel.text == label:
                            iFound = 1
                            break
                    if iFound == 1:
                        self.label_list.append(label, pLabel)
                    else:
                        self.label_list.append(label, None)
                    if self.peak.is_assigned == 1:
                        asns = sputil.parse_assignment(self.peak.assignment)
                        filled_assignment = ''
                        for asn in asns:
                            filled_assignment = filled_assignment + asn[
                                0] + asn[1] + '-'
                        filled_assignment = filled_assignment.rstrip('-')
                        #                        tkMessageBox.showinfo('filled',filled_assignment)
                        if label.find(filled_assignment) <> -1:
                            iIndex = self.label_list.listbox.size() - 1
#                    if self.peak.is_assigned == 1 and label.find(self.peak.assignment) <> -1:
#                        iIndex = self.label_list.listbox.size()-1

        finally:
            f.close()

        if iIndex <> -1:
            self.label_list.listbox.selection_set(iIndex, )
            self.label_list.listbox.see(iIndex)
Beispiel #6
0
  def Assign(self):
    if self.selected_spectrum == None or self.selected_group == None or self.selected_atom == None:
        return
    if len(self.label_list.selected_line_numbers()) == 0:
        return

    for label in self.label_list.selected_line_data():
        if label.find('assigned') <> -1:
            continue
        [label_assign, label_prob, label_pos] = self.SplitPineLabel(label)
        
        # parse frequencies from label text
        splited = label.split('(')
        if splited < 2:                             #
            continue
        splitedsplited = splited[1].split(')')
        pszFreq = splitedsplited[0].split(',')
        freq = []
        for szFreq in pszFreq:
            freq.append(eval(szFreq))
        # set ranges depending on atom types
        ranges = []
        for atom_type in self.selected_spectrum.nuclei:
            if atom_type == '13C':
                ranges.append(0.4)
            elif atom_type == '1H':
                ranges.append(0.03)
            elif atom_type == '15N':
                ranges.append(0.4)
         
        peak = sputil.closest_peak(freq, self.selected_spectrum.peak_list(), ranges)
        if peak <> None:
            if peak.is_assigned:
                # unassign peak
                for i in range(self.selected_spectrum.dimension):
                    peak.assign(i, '', '')
            # Assign
            splited2 = label.split('[')
            assgn = sputil.parse_assignment(splited2[0])
            for i in range(self.selected_spectrum.dimension):
                peak.assign(i, assgn[i][0], assgn[i][1])
            # select floating labels
            # if already assigned, clear labels
            peak.selected = 0
            for pLabel in self.selected_spectrum.label_list():
                [pAssign, pProb, pPos] = self.SplitPineLabel(pLabel.text)
                if label_pos == pPos:
                    pLabel.selected = 1
                else:
                    pLabel.selected = 0
    self.UpdateDialog()
Beispiel #7
0
  def LabelBox(self):
    
    self.label_list.clear()

    # append labels which are located on the selected peak
    iIndex = -1
    if self.spectrum == None:                   # if there is no selected spectrum, exit this function.
        return
    if self.peak == None:
        return
    szPos = '('
    for pos in self.peak.position:
        szPos = szPos + ('%7.3f,' % pos).strip() 
    szPos = szPos.rstrip(',')
    szPos = szPos + ')'
    #----------------------------------------------------------------------------------------------
    f = open(self.spectrum.save_path + '_pl', 'r')
    try:
        for label in f.readlines():
            label = label.strip()
            if label.find(szPos) <> -1:
                #tkMessageBox.showinfo('szPos',szPos)
                # find label object
                iFound = 0
                for pLabel in self.spectrum.label_list():
                    if pLabel.text == label:
                        iFound = 1
                        break
                if iFound == 1:
                    self.label_list.append(label, pLabel)
                else:
                    self.label_list.append(label, None) 
                if self.peak.is_assigned == 1:
                    asns = sputil.parse_assignment(self.peak.assignment)
                    filled_assignment = ''
                    for asn in asns:
                        filled_assignment = filled_assignment + asn[0] + asn[1] + '-'
                    filled_assignment = filled_assignment.rstrip('-')
#                        tkMessageBox.showinfo('filled',filled_assignment)
                    if label.find(filled_assignment) <> -1:
                        iIndex = self.label_list.listbox.size()-1
#                    if self.peak.is_assigned == 1 and label.find(self.peak.assignment) <> -1: 
#                        iIndex = self.label_list.listbox.size()-1
                
    finally:
        f.close()
        
    if iIndex <> -1:
        self.label_list.listbox.selection_set(iIndex, )
        self.label_list.listbox.see(iIndex)
Beispiel #8
0
def tpa(session):
    ref_spec = session.selected_spectrum()
    save_peaks(ref_spec)
    ref_peaks = ref_spec.peak_list()
    for spec in session.project.spectrum_list():
        if ref_spec == spec:
            continue
        for peak in ref_peaks:
            peak2 = spec.place_peak(peak.frequency)
            if peak.is_assigned == 1:
                tasn = parse_assignment(peak.assignment)
                peak2.assign(0, tasn[0][0], tasn[0][1])
                peak2.assign(1, tasn[1][0], tasn[1][1])
                peak2.show_assignment_label()
        save_peaks(spec)
Beispiel #9
0
    def read_npc_cb(self):
        fileName = os.path.abspath(self.npc_read_path.get())
        diaSpec = self.dia_menu.spectrum()
        paraSpec = self.para_menu.spectrum()

        if not all([diaSpec, paraSpec, fileName]):
            raise IOError(
                "You need to select two spectra and a valid file name")

        pcs = {}
        with open(self.npc_read_path.get()) as f:
            for line in f:
                try:
                    seq, atom, value, error = line.split()
                    pcs[(int(seq), atom)] = float(value)
                except ValueError:
                    print("Line ignored while reading npc file:\n{}".format(
                        line))

        for peak in diaSpec.peak_list():
            new_freq = []
            parsed_assig = sputil.parse_assignment(peak.assignment)
            for (tmp, atom), value in zip(parsed_assig, peak.frequency):
                grp, seq = sputil.parse_group_name(tmp)
                key = seq, atom
                if key in pcs:
                    new_freq.append(value + pcs[key])

            if len(new_freq) != paraSpec.dimension:
                continue

            for freq, (low, high) in zip(new_freq, zip(*paraSpec.region)):
                if not low < freq < high:
                    break

            peak = paraSpec.place_peak(tuple(new_freq))
            for i, assig in enumerate(parsed_assig):
                peak.assign(i, assig[0], assig[1])

            peak.note = "PCS_backcalc"
            peak.show_assignment_label()
            peak.label.color = BACK_CALC_PEAK_COLOUR
            peak.color = BACK_CALC_PEAK_COLOUR

        self.message['text'] = "PCS values read from: \n{}".format(fileName)
Beispiel #10
0
  def InitSequences(self):
    # set sequences
    self.sequences = []
    self.groups = []
    ga = []
    # loop labels of selected spectrum
    #tkMessageBox.showinfo('InitSequences', '1')
    for spectrum in self.session.project.spectrum_list():
        for pLabel in spectrum.label_list():                                     # M3CA-M3N-M3H[0.997]:(xx.xx,xxx.xx,x.xx)
            if pLabel.text == '?-?-?' or pLabel.text == '?-?':
                continue
            splited = pLabel.text.split('[')                        # (M3CA-M3N-M3H, [0.997]:(xx.xx,xxx.xx,x.xx))
            groupatoms = sputil.parse_assignment(splited[0])        # (('M3','CA'), ('M3','N'), ('M3','H'))
            for groupatom in groupatoms:
                if groupatom[0] == '':
                    continue

                ga = sputil.parse_group_name(groupatom[0])             # ('M', 3)
                if len(self.sequences) == 0:
                    self.sequences.append(ga)
                    self.groups.append('%s%d' % (ga[0], ga[1]) )
                    continue
                
                # check if parsed sequence is already existed or not
                if ga in self.sequences:                                 # X in XXXXXXXXXXXXX ?
                    continue                                        # if already exists, continue
                bAdded = 0
                for seq in self.sequences: 
                    if ga[1] < seq[1]:
                        idx = self.sequences.index(seq)
                        self.sequences.insert(idx, ga)
                        self.groups.insert(idx, '%s%d' % (ga[0], ga[1]) )
                        bAdded = 1
                        break
                if bAdded == 0:
                    self.sequences.append(ga)
                    self.groups.append('%s%d' % (ga[0], ga[1]) )
Beispiel #11
0
  def UpdateLabelList(self):
      self.label_list.clear()
      if (self.selected_group == None) and (self.selected_atom == None):
          return

      if len(self.selected_atom) > 3:
          selected_atom = self.selected_atom[0:len(self.selected_atom)-1]
      else:
          selected_atom = self.selected_atom
      selected_group_atom = '%s%d%s' % (self.selected_group[0], self.selected_group[1], selected_atom)      # 'M13' + 'CA'
      
      spectra = self.selected_spectrum
      
      # find assigned_peaks which is related to the selected_group_atom
      assigned_peaks = []
      for peak in spectra.peak_list():
          if not peak.is_assigned:
              continue
          asns = sputil.parse_assignment(peak.assignment)
          filled_assignment = ''
          for asn in asns:
              filled_assignment = filled_assignment + asn[0] + asn[1] + '-'
          filled_assignment = filled_assignment.rstrip('-')
          #if peak.assignment.find(selected_group_atom, 0) <> -1:
          #tkMessageBox.showinfo('filled',filled_assignment)
          if filled_assignment.find(selected_group_atom, 0) <> -1:
              # distinguish C and CX
              if selected_atom != 'C' and selected_atom != 'H':
                  assigned_peaks.append(peak)
              else: # check string length of selected_atom
                  asns = sputil.parse_assignment(peak.assignment)
                  for asn in asns:
                      if asn == selected_group_atom:
                          assigned_peaks.append(peak)
                          break      
      
      self.label_list.listbox.selection_clear(0, 'end')
      
      in_file = open(self.selected_spectrum.save_path + '_pl', "r")
      try:
        for label in in_file.readlines():
          label = label.strip()
          # Check if label is related to the selected group and atom
          # Parsing text
          #tkMessageBox.showinfo('selected_group_atom',selected_atom)          
          if label.find(selected_group_atom, 0) == -1:     # check 
              continue;
          if selected_atom == 'C' or selected_atom == 'H':
              assignments = label.split('[')
              assignment = assignments[0]
              asns = sputil.parse_assignment(assignment)
              iOk = 0
              for asn in asns:
                  if asn == selected_group_atom:
                      iOk = 1
                      break
              if iOk == 0:
                  continue
          # if related..
          # add to the label list
          iAssigned = 0
          #tkMessageBox.showinfo('ga1','%d' % (len(assigned_peaks)))
          for peak in assigned_peaks:
              peak_pos = ''
              for i in range(self.selected_spectrum.dimension):
                  peak_pos = peak_pos + ('%7.3f,' % peak.position[i]).strip()
              peak_pos = peak_pos.rstrip(',')
              #tkMessageBox.showinfo('assignment',peak.assignment)
              groupatoms = sputil.parse_assignment(peak.assignment)
              assgn = ''
              ga1 = ''
              for ga in groupatoms:
                  if ga1 == '':
                      assgn = assgn + ga[0] + ga[1] + '-'
                  else:
                      if ga1 == ga[0]:
                          assgn = assgn + ga[1] + '-'
                      else:
                          assgn = assgn + ga[0] + ga[1] + '-'
                  ga1 = ga[0]  
                  
              assgn = assgn.rstrip('-') 
              #tkMessageBox.showinfo('ga1',peak_pos)
#              if label.find(peak_pos) <> -1 and label.find(assgn) <> -1:
              if label.find(peak_pos) <> -1:
                  iAssigned = 1
                  break
                  
          if iAssigned == 0:
              self.label_list.append(label, label)
          else:     # if it is already assign label,
              self.label_list.append(label + ';(*)', label + ';(*)')
              self.label_list.listbox.selection_includes(self.label_list.listbox.size()-1, )
        # Sorting probabilities.
        
      finally:
        in_file.close()  
Beispiel #12
0
 def InitGroupAtom(self):
   self.selected_group = None
   self.selected_atom = None
   self.selected_groupatom = None
   self.selected_group_prev = None 
   self.selected_group_next = None
   
   # if nothing is selected, set first sequence as selected_group
   if len(self.selected_spectrum.selected_peaks()) == 0:
       if len(self.sequences) > 0:
           self.selected_group = self.sequences[0]
           self.selected_atom = 'CA'                       # Default: CA
           self.selected_groupatom = '%s%dCA' % (self.sequences[0][0], self.sequences[0][1])
           self.selected_group_prev = None
           self.selected_group_next = self.sequences[1]
           self.selected_index = 0
           return
   # if a peak is selected
   else:       
       # If the peak is assigned, get group and atom name
       selected_peak = self.selected_spectrum.selected_peaks()[0]
       bFind = 0
       # The peak should be assigned...
       if selected_peak.is_assigned == 1:
           # get index from first axis -> parse assignment
           groupatoms = sputil.parse_assignment(selected_peak.assignment)        # (('M3','CA'), ('M3','N'), ('M3','H'))
           index = groupatoms[0][1]
           # Find index
           for seq in self.sequences:
               if bFind == 1:
                   self.selected_group_next = seq
                   break
               if seq[1] == index:
                   self.selected_group = self.seq
                   self.selected_atom = 'CA'
                   self.selected_groupatom = '%s%dCA' % (seq[0], index)
                   self.selected_group_prev = seq2
                   self.selected_index = index
                   bFind = 1
               seq2 = seq
       else:
           szPos = '('
           for pos in selected_peak.position:
               szPos = szPos + ('%7.3f,' % pos).strip() 
           szPos = szPos.rstrip(',')
           szPos = szPos + ')'
           # Find nearest label & probability
           if len(self.sequences) > 0:
               for pLabel in self.selected_spectrum.label_list():
                   # Parse label_list
                   # selected_peak.position = position of pLabel
                   # Let's parse pLabel   : XXX-XXX-XXX[xxx.xxx]:(xxx.xxx,xxx.xxx,xxx.xxx)
                   splited = pLabel.text.split(':')     # (xxx.xxx,xxx.xxx,xxx.xxx)
                   if len(splited) < 2:
                       continue
                   #
                   #
                   if splited[1] == szPos:
                       # Parse index
                       splitedsplited = splited[0].split('[')
                       groupatoms = sputil.parse_assignment(splitedsplited[0])
                       index = sputil.group_number(groupatoms[0][0])
                       #index = groupatoms[0][1]
                       #tkMessageBox.showinfo('InitGroupAtom', index)
                       # Find index
                       
                       for seq in self.sequences:
                           if seq[1] == index:
                               if self.sequences.index(seq) > 0:
                                   self.selected_group_prev = self.sequences[self.sequences.index(seq)-1]
                               else:
                                   self.selected_group_prev = None
                               self.selected_group = seq    
                               self.selected_atom = 'CA'
                               self.selected_groupatom = '%s%dCA' % (seq[0], index)
                               if self.sequences.index(seq) < len(self.sequences)-1:
                                   self.selected_group_next = self.sequences[self.sequences.index(seq)+1]
                               else:
                                   self.selected_group_next = None
                               bFind = 1
                               self.selected_index = self.sequences.index(seq)
                               break
       if bFind == 0:
           if len(self.sequences) > 0:
               self.selected_group = self.sequences[0]
               self.selected_atom = 'CA'                       # Default: CA
               self.selected_groupatom = '%s%dCA' % (self.sequences[0][0], self.sequences[0][1])
               self.selected_group_prev = None
               self.selected_group_next = self.sequences[1]
               self.selected_index = 0            
Beispiel #13
0
  def read_peaks(self, fin, fprot, fseq, spectrum):
 
    #s = self.get_settings()
    #self.settings = s

    stype=self.spectratype.get()
    if stype == '2D':
	    type='2D'
    else:
        type='3D'

    order=self.order.get()
    if len(order) == 3 and stype == '2D':
    	message='You have to select 2D order'
	self.progress_report(message)
	return None
    elif len(order) == 2 and stype == '3D':
	message='You have to select 3D order'
	self.progress_report(message)
	return None

    amino={'ALA' : 'A', # alanine
       'CYS' : 'C', # cysteine
       'CYSS' : 'C', # cysteine
       'ASP' : 'D', # aspartate
       'ASP-' : 'D', # aspartate
       'GLU' : 'E', # glutamate
       'GLU-' : 'E', # glutamate
       'PHE' : 'F', # phenylalanine
       'GLY' : 'G', # glycine
       'HIS' : 'H', # histidine
       'HIS+' : 'H', # histidine
       'HEM' : 'H', # histidine
       'ILE' : 'I', # isoleucine
       'LYS' : 'K', # lysine
       'LYS+' : 'K', # lysine
       'LEU' : 'L', # leucine
       'ASN' : 'N', # asparagine
       'MET' : 'M', # methionine
       'PRO' : 'P', # proline
       'GLN' : 'Q', # glutamine
       'ARG' : 'R', # arginine
       'ARG+' : 'R', # arginine
       'SER' : 'S', # serine
       'THR' : 'T', # threonine
       'VAL' : 'V', # valine
       'TRP' : 'W', # tryptophan
       'TYR' : 'Y'} # tyrosine

    input = open(fin, 'r')
    splines = input.readlines()
    input.close()

    input = open(fprot, 'r')
    plines=input.readlines()
    input.close()

    input = open(fseq, 'r')
    slines = input.readlines()
    input.close()

    seq={}
    # List of 1 letter aa codes per residue
    aa_list = [];
    # Fill in dummy value for aa_list[0]
    aa_list.append(' ');
    for i in range(len(slines)):
      sf=string.split(string.lstrip(slines[i]))
      aa_list.append(sf[0])
      seq[sf[1]]=sf[0]
   

    at1=""
    col1=""
    col2=""
    col3=""
    icol=""
    for i in range(len(splines)):
      self.check_for_stop()
      if re.compile("^#").search(splines[i], 0):
        continue

      fields=string.split(splines[i])

      if type == '2D' and len(fields) >= 10:
        np=fields[0]
        x=float(fields[1])
        y=float(fields[2])
        integ=fields[5]

        if int(fields[9]) == 0 and int(fields[10]) == 0:
          icol='?-?'
          assignment = sputil.parse_assignment(icol)
          frequency = []
          if order == 'xy':
                frequency.append(x)
                frequency.append(y)
          elif order == 'yx':
                frequency.append(y)
                frequency.append(x)
          note = integ + ' lo NP' + np
          self.create_peak(assignment, frequency, note, spectrum)
          continue

      if type == '3D' and len(fields) >= 12:
        np=fields[0]
        x=float(fields[1])
        y=float(fields[2])
        z=float(fields[3])
        integ=fields[6]

        if int(fields[10]) == 0 and int(fields[11]) == 0 and int(fields[12]) == 0:
          icol='?-?-?'
          assignment = sputil.parse_assignment(icol)
          frequency = []
  	  if order == 'xyz':
                frequency.append(x)
                frequency.append(y)
                frequency.append(z)
          elif order == 'yxz':
                frequency.append(y)
                frequency.append(x)
                frequency.append(z)
          elif order == 'xzy':
                frequency.append(x)
                frequency.append(z)
                frequency.append(y)
          elif order == 'zyx':
                frequency.append(z)
                frequency.append(y)
                frequency.append(x)
          elif order == 'zxy':
                frequency.append(z)
                frequency.append(x)
                frequency.append(y)
          elif order == 'yzx':
                frequency.append(y)
                frequency.append(z)
                frequency.append(x)
          note = integ + ' lo NP' + np
          self.create_peak(assignment, frequency, note, spectrum)
          continue

      nar=[]
      nn=[]

      if type == '3D':
        if len(fields) >= 12:
          nn.append(fields[10])
          nn.append(fields[11])
          nn.append(fields[12])
        else:
          nn.append(fields[0])
          nn.append(fields[1])
          nn.append(fields[2])

      if type == '2D': 
        if len(fields) >= 9:
          nn.append(fields[9])
          nn.append(fields[10])
        else:
          nn.append(fields[0])
          nn.append(fields[1])

      cyana_dict = cyana.CyanaDictionary();
      
      for jj in range(len(nn)):
        for j in range(len(plines)):
          pfields=string.split(plines[j])
          if nn[jj] == pfields[0]:
             atm=pfields[3]
             if atm[0] == 'C':
               nuc='13C'
             elif atm[0] == 'N':
               nuc='15N'
             else:
               nuc='1H'
             rns = pfields[4];
             aa = aa_list[int(rns)];
             # Convert cyana nomenclature to IUPAC if necessary
             atm = cyana_dict.toIUPAC(aa,atm);
             amm=amino[seq[rns]] + rns;
             if jj == 0:
               nar.append([amm, atm, nuc, x, integ])
             elif jj == 1:
               nar.append([amm, atm, nuc, y, np])
             else:
               nar.append([amm, atm, nuc, z])
             break
      
      if len(nar) > 1:
        x=float(nar[0][3])
        y=float(nar[1][3])
        integ=nar[0][4]
        npeack=nar[1][4]
        if type == '3D':
          z=float(nar[2][3])

        if nar[0][0]==nar[1][0]:
           if type == '3D':
	     if order=='yxz':
	       col2=nar[0][1]
               if nar[2][0]==nar[0][0]:
   	         col3=nar[2][1]
               else:
	         col3=nar[2][0]+nar[2][1]
	     if order=='zxy':
               col2=nar[0][1]
               if nar[1][0]==nar[0][0]:
	         col3=nar[1][1]
	       else:
	         col3=nar[1][0]+nar[1][1]
	     if order=='yzx':
	       col2=nar[2][1]
 	       if nar[0][0]==nar[2][0]:
	         col3=nar[0][1]
	       else:
	         col3=nar[0][0]+nar[0][1]
	     if order=='xzy':
	       col2=nar[2][1]
  	       if nar[1][0]==nar[2][0]:
	         col3=nar[1][1]
	       else:
	         col3=nar[1][0]+nar[1][1] 
	     if order=='zyx':
	       col2=nar[1][1]
	       if nar[1][0]==nar[0][0]:
	         col3=nar[0][1]
 	       else:
	         col3=nar[0][0]+nar[0][1]
	     elif order=='xyz':
               col2=nar[1][1]
	       if nar[1][0]==nar[2][0]:
	         col3=nar[2][1]
	       else:
                 col3=nar[2][0]+nar[2][1]
           else:
             if order=="yx":
               col2=nar[0][1]
             else:
               col2=nar[1][1]
        else:
           if type == '3D':
	     if order=='yxz':
               col2=nar[0][0]+nar[0][1]
               if nar[0][0]==nar[2][0]:
                 col3=nar[2][1]
               else:
                 col3=nar[2][0]+nar[2][1]
	     elif order=='xzy':
	       if nar[1][0]==nar[2][0]:
                 col3=nar[1][1]
                 col2=nar[2][0]+nar[2][1]
	     elif order=='zyx':
	       if nar[1][0]==nar[2][0]:
	         col2=nar[1][1]
	       else:
	         col2=nar[1][0]+nar[1][1]
               if nar[0][0]==nar[1][0]:
                 col3=nar[0][1]
               else:
	         col3=nar[0][0]+nar[0][1]
	     elif order=="zxy":
	       if nar[0][0]==nar[2][0]:
	         col2=nar[0][1]
	       else:
	         col2=nar[0][0]+nar[0][1]
	       if nar[1][0]==nar[0][0]:
	         col3=nar[1][1]
	       else:
	         col3=nar[1][0]+nar[1][1]
	     elif order=="yzx":
	       if nar[1][0]==nar[2][0]:
	         col2=nar[2][1]
	       else:
	         col2=nar[2][0]+nar[2][1]
	       if nar[2][0]==nar[0][0]:
	         col3=nar[0][1]
	       else:
	         col3=nar[0][0]+nar[0][1]
             elif order=='xyz':
	       if nar[0][0]==nar[1][0]:
    	         col2=nar[1][1]
	       else: 
                 col2=nar[1][0]+nar[1][1]
	       if nar[1][0]==nar[2][0]:
	         col3=nar[2][1]
  	       else:
	         col3=nar[2][0]+nar[2][1]
           else:
             if order=='yx':
               col2=nar[0][0]+nar[0][1]
             else:
               col2=nar[1][0]+nar[1][1]
  
             
        if type == '3D':
          frequency = []
          if order == 'xyz':
	    col1=nar[0][0]+nar[0][1]
            icol=col1+'-'+col2+'-'+col3
	  
            frequency.append(x)
            frequency.append(y)
            frequency.append(z)
	  elif order == 'yxz':
	    col1=nar[1][0]+nar[1][1]
	    icol=col1+'-'+col2+'-'+col3    
	  
            frequency.append(y)
            frequency.append(x)
            frequency.append(z)
	  elif order == 'xzy':
	    col1=nar[0][0]+nar[0][1]
            icol=col1+'-'+col2+'-'+col3
	    
            frequency.append(x)
            frequency.append(z)
            frequency.append(y)
	  elif order == 'zyx':
	    col1=nar[2][0]+nar[2][1]
            icol=col1+'-'+col2+'-'+col3
  
            frequency.append(z)
            frequency.append(y)
            frequency.append(x)
	  elif order == 'zxy':
	    col1=nar[2][0]+nar[2][1]
            icol=col1+'-'+col2+'-'+col3
            assignment = sputil.parse_assignment(icol)
  
            frequency.append(z)
            frequency.append(x)
            frequency.append(y)
	  elif order == 'yzx':
	    col1=nar[1][0]+nar[1][1]
            icol=col1+'-'+col2+'-'+col3
  
            frequency.append(x)
            frequency.append(z)
            frequency.append(y)
        else:
          frequency = []
	  if order == 'xy':
            col1=nar[0][0]+nar[0][1]
	    icol=col1+'-'+col2
  
            frequency.append(x)
            frequency.append(y)
	  elif order == 'yx':
            col1=nar[1][0]+nar[1][1]
	    icol=col1+'-'+col2
  
            frequency.append(y)
            frequency.append(x)
  
        assignment = sputil.parse_assignment(icol)
        note = integ + ' lo NP' + npeack
        self.create_peak(assignment, frequency, note, spectrum)

    return
Beispiel #14
0
url = 'https://api.bmrb.io/current/entry/%s/simulate_hsqc?format=sparky&filter=all' % (BMRB_entry)
response = requests.get(url)
if response.status_code != 200:
  s.show_message('Error', 'Failed to get data from BMRB:' + response.status_code)
  sys.exit(1)

# parse and apply
n = 0
from sputil import parse_assignment
lines = response.text.split('\n')
for line in lines:
  l = line.strip().split()
  if len(l) != 3:
    continue
  try:
    asgn = parse_assignment(l[0])
  except:
    continue # failed to parse
  if asgn == None or len(asgn) != 2:
    continue
  try:
    if flip:
      p = sp.place_peak((float(l[2])+offset1, float(l[1])+offset2))
      p.assign(0, asgn[1][0], asgn[1][1])
      p.assign(1, asgn[0][0], asgn[0][1])
    else:
      p = sp.place_peak((float(l[1])+offset1, float(l[2])+offset2))
      p.assign(0, asgn[0][0], asgn[0][1])
      p.assign(1, asgn[1][0], asgn[1][1])
    p.show_assignment_label()
    n += 1