示例#1
0
def convert_pilot_to_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  size = parse.size_str(params['fasta'])
  print_fn("Using sequences from %s (%s)...\n" % (params['fasta'], size))

  proteins = {}
  labels = []
  for fname, label in params['files_and_labels']:
    labels.append(label)
    size = parse.size_str(fname)
    print_fn("Processing %s (%s)...\n" % (fname, size))
    these_proteins = peptagram.pilot.get_proteins(fname)
    proteins = peptagram.proteins.merge_two_proteins(
        proteins, these_proteins)

  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': [0, 1],
      'mask_labels': [],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
  return os.path.abspath(html)
def convert_morpheus_to_peptagram(params, print_fn=sys.stdout.write):
    if len(params['files_and_labels']) == 0:
        raise ValueError('No files were selected.')

    q_good = float(params['q_good'])
    q_cutoff = float(params['q_cutoff'])

    modifications = params['modifications']
    proteins = {}
    labels = []
    for entry in params['files_and_labels']:
        fname = entry[0]

        size = parse.size_str(fname)
        print_fn("Processing %s (%s)...\n" % (fname, size))

        protein_group = fname.replace('PSMs', 'protein_groups')
        size = parse.size_str(protein_group)
        print_fn("Inferring protein group: %s (%s)\n" % (protein_group, size))

        these_proteins, these_sources = \
            peptagram.morpheus.get_proteins_and_sources(
                protein_group, fname, modifications, q_good, q_cutoff)
        proteins = peptagram.proteins.merge_two_proteins(
            proteins, these_proteins)
        labels.extend(map(parse.basename, these_sources))

    n_peak = int(params['n_peak'])
    for i_source, (mzml, label) in enumerate(params['mzmls_and_labels']):
        print_fn("Extracting spectra from %s (%s)...\n" %
                 (mzml, parse.size_str(mzml)))
        peptagram.mzml.load_mzml(proteins, i_source, mzml, n_peak)

    peptagram.proteins.filter_proteins(proteins, params)

    peptagram.proteins.make_graphical_comparison_visualisation({
        'title':
        params['title'],
        'proteins':
        proteins,
        'source_labels':
        labels,
        'color_names': ['Q=%s' % q_good, 'Q=%s' % q_cutoff],
        'mask_labels': [],
        'out_dir':
        params['out_dir'],
    })

    html = os.path.join(params['out_dir'], 'index.html')
    size = parse.size_str(params['out_dir'])
    print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
    return os.path.abspath(html)
示例#3
0
def convert_morpheus_to_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  q_good = float(params['q_good'])
  q_cutoff = float(params['q_cutoff'])

  modifications = params['modifications']
  proteins = {}
  labels = []
  for entry in params['files_and_labels']:
    fname = entry[0]

    size = parse.size_str(fname)
    print_fn("Processing %s (%s)...\n" % (fname, size))

    protein_group = fname.replace('PSMs', 'protein_groups')
    size = parse.size_str(protein_group)
    print_fn("Inferring protein group: %s (%s)\n" % (protein_group, size))

    these_proteins, these_sources = \
        peptagram.morpheus.get_proteins_and_sources(
            protein_group, fname, modifications, q_good, q_cutoff)
    proteins = peptagram.proteins.merge_two_proteins(
        proteins, these_proteins)
    labels.extend(map(parse.basename, these_sources))

  n_peak = int(params['n_peak'])
  for i_source, (mzml, label) in enumerate(params['mzmls_and_labels']):
    print_fn("Extracting spectra from %s (%s)...\n" % (mzml, parse.size_str(mzml)))
    peptagram.mzml.load_mzml(
        proteins, i_source, mzml, n_peak)

  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': ['Q=%s' % q_good, 'Q=%s' % q_cutoff],
      'mask_labels': [],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
  return os.path.abspath(html)
def convert_maxquant_to_peptagram(params, print_fn=sys.stdout.write):
    if len(params['files_and_labels']) == 0:
        raise ValueError('No files were selected.')

    size = parse.size_str(params['fasta'])
    print_fn("Using sequences from %s (%s)...\n" % (params['fasta'], size))

    great_expect = float(params['great_expect'])
    cutoff_expect = float(params['cutoff_expect'])

    proteins = {}
    labels = []
    for entry in params['files_and_labels']:
        fname = entry[0]
        size = parse.size_str(fname)
        print_fn("Processing %s (%s)...\n" % (fname, size))
        these_proteins, sources = \
            peptagram.maxquant.get_proteins_and_sources(
                fname, great_expect=great_expect, cutoff_expect=cutoff_expect)
        proteins = peptagram.proteins.merge_two_proteins(
            proteins, these_proteins)
        labels.extend(map(parse.basename, sources))

    peptagram.proteins.filter_proteins(proteins, params)

    peptagram.proteins.make_graphical_comparison_visualisation({
        'title':
        params['title'],
        'proteins':
        proteins,
        'source_labels':
        labels,
        'color_names': [
            'PEP=%s' % params['great_expect'],
            'PEP=%s' % params['cutoff_expect']
        ],
        'mask_labels': [],
        'out_dir':
        params['out_dir'],
    })

    html = os.path.join(params['out_dir'], 'index.html')
    size = parse.size_str(params['out_dir'])
    print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
    return os.path.abspath(html)
示例#5
0
    def run(self, params):

        self.print_output("Building new peptagram...\n")
        seqids = []
        proteins = {}
        for data in self.datas:
            for seqid, protein in data['proteins'].iteritems():
                if seqid not in proteins:
                    new_protein = peptagram.proteins.new_protein(seqid)
                    new_protein['sources'] = []
                    for key in ['sequence', 'description']:
                        new_protein[key] = protein[key]
                    new_protein['attr'] = protein['attr']
                    seqids.append(seqid)
                    proteins[seqid] = new_protein

        new_sources = []
        labels = []
        for source_label, label in params['in_peptagram']:
            i_data, i_source = self.extract_indices_from_source_label(
                source_label)
            new_sources.append((i_data, i_source))
            labels.append(label)

        for seqid in seqids:
            protein = proteins[seqid]
            for i_data, i_source in new_sources:
                old_data = self.datas[i_data]
                if seqid in old_data['proteins']:
                    old_protein = old_data['proteins'][seqid]
                    old_source = old_protein['sources'][i_source]
                    protein['sources'].append(old_source)
                else:
                    protein['sources'].append({'matches': []})

        peptagram.proteins.filter_proteins(proteins, params)

        data = {
            'title': params['title'],
            'proteins': proteins,
            'source_labels': labels,
            'color_names': ['1.5', '1', '0.66'],
            'mask_labels': [],
        }

        out_dir = os.path.abspath(params['out_dir'])
        peptagram.proteins.make_graphical_comparison_visualisation(
            data, out_dir)
        self.print_output(
            'Successfully built peptagram webpage (%s):\n' % \
                parse.size_str(out_dir))

        html = os.path.join(out_dir, 'index.html')
        cmd_fn = lambda: webbrowser.open('file://' + html)
        self.print_output(html, cmd_fn)
def convert_prophet_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  size = parse.size_str(params['fasta'])
  print_fn("Using sequences from %s (%s)...\n" % (params['fasta'], size))

  size = parse.size_str(params['prot_xml'])
  print_fn('Processing %s (%s)...\n' % (params['prot_xml'], size))

  proteins = {}
  prot_xml = params['prot_xml'] 
  peptide_error = float(params['peptide_error'])
  protein_error = float(params['protein_error'])
  great_expect = float(params['great_expect'])
  cutoff_expect = float(params['cutoff_expect'])
  pep_xmls = [e[0] for e in params['files_and_labels']]
  size = parse.size_str(*pep_xmls)
  print_fn('Processing %s (%s)...\n' % (pep_xmls, size))
  proteins, labels = peptagram.prophet.get_proteins_and_sources(
      prot_xml, 
      pep_xmls, 
      peptide_error=peptide_error,
      protein_error=protein_error,
      good_expect=great_expect,
      cutoff_expect=cutoff_expect)
  labels = map(parse.basename, labels)
  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': ['expect=%s' % great_expect, 'expect=%s' % cutoff_expect],
      'mask_labels': [],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
  return os.path.abspath(html)
示例#7
0
  def run(self, params):

    self.print_output("Building new peptagram...\n")
    seqids = []
    proteins = {}
    for data in self.datas:
      for seqid, protein in data['proteins'].iteritems():
        if seqid not in proteins:
          new_protein = peptagram.proteins.new_protein(seqid)
          new_protein['sources'] = []
          for key in ['sequence', 'description']:
            new_protein[key] = protein[key]
          new_protein['attr'] = protein['attr']
          seqids.append(seqid)
          proteins[seqid] = new_protein

    new_sources = []
    labels = []
    for source_label, label in params['in_peptagram']:
      i_data, i_source = self.extract_indices_from_source_label(source_label)
      new_sources.append((i_data, i_source))
      labels.append(label)

    for seqid in seqids:
      protein = proteins[seqid]
      for i_data, i_source in new_sources:
        old_data = self.datas[i_data]
        if seqid in old_data['proteins']:
          old_protein = old_data['proteins'][seqid]
          old_source = old_protein['sources'][i_source]
          protein['sources'].append(old_source)
        else:
          protein['sources'].append({'matches':[]})

    peptagram.proteins.filter_proteins(proteins, params)

    data = {
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': ['1.5', '1', '0.66'],
      'mask_labels': [],
    }

    out_dir = os.path.abspath(params['out_dir'])
    peptagram.proteins.make_graphical_comparison_visualisation(
        data, out_dir)
    self.print_output(
        'Successfully built peptagram webpage (%s):\n' % \
            parse.size_str(out_dir))

    html = os.path.join(out_dir, 'index.html')
    cmd_fn = lambda: webbrowser.open('file://' + html)
    self.print_output(html, cmd_fn)
示例#8
0
def convert_xtandem_to_peptagram(params, print_fn=sys.stdout.write):
    if len(params['files_and_labels']) == 0:
        raise ValueError('No files were selected.')

    n_peak = int(params['n_peak'])
    great_expect = float(params['great_expect'])
    cutoff_expect = float(params['cutoff_expect'])

    proteins = {}
    labels = []
    for fname, label in params['files_and_labels']:
        labels.append(label)
        size = parse.size_str(fname)
        print_fn("Processing %s (%s)...\n" % (fname, size))
        these_proteins = peptagram.xtandem.get_proteins(
            fname,
            n_peak=n_peak,
            good_expect=great_expect,
            cutoff_expect=cutoff_expect)
        proteins = peptagram.proteins.merge_two_proteins(
            proteins, these_proteins)

    peptagram.proteins.filter_proteins(proteins, params)

    peptagram.proteins.make_graphical_comparison_visualisation({
        'title':
        params['title'],
        'proteins':
        proteins,
        'source_labels':
        labels,
        'color_names': [great_expect, cutoff_expect],
        'mask_labels': [],
        'out_dir':
        params['out_dir'],
    })

    html = os.path.join(params['out_dir'], 'index.html')
    size = parse.size_str(params['out_dir'])
    print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
    return os.path.abspath(html)
示例#9
0
def convert_maxquant_to_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  size = parse.size_str(params['fasta'])
  print_fn("Using sequences from %s (%s)...\n" % (params['fasta'], size))

  great_expect = float(params['great_expect'])
  cutoff_expect = float(params['cutoff_expect'])

  proteins = {}
  labels = []
  for entry in params['files_and_labels']:
    fname = entry[0]
    size = parse.size_str(fname)
    print_fn("Processing %s (%s)...\n" % (fname, size))
    these_proteins, sources = \
        peptagram.maxquant.get_proteins_and_sources(
            fname, great_expect=great_expect, cutoff_expect=cutoff_expect)
    proteins = peptagram.proteins.merge_two_proteins(
        proteins, these_proteins)
    labels.extend(map(parse.basename, sources))

  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': ['PEP=%s'%params['great_expect'], 
                      'PEP=%s'%params['cutoff_expect']],
      'mask_labels': [],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
  return os.path.abspath(html)
示例#10
0
def convert_xtandem_to_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  n_peak = int(params['n_peak'])
  great_expect = float(params['great_expect'])
  cutoff_expect = float(params['cutoff_expect'])

  proteins = {}
  labels = []
  for fname, label in params['files_and_labels']:
    labels.append(label)
    size = parse.size_str(fname)
    print_fn("Processing %s (%s)...\n" % (fname, size))
    these_proteins = peptagram.xtandem.get_proteins(
        fname, 
        n_peak=n_peak,
        good_expect=great_expect,
        cutoff_expect=cutoff_expect)
    proteins = peptagram.proteins.merge_two_proteins(
        proteins, these_proteins)

  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': [great_expect, cutoff_expect],
      'mask_labels': [],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))
  return os.path.abspath(html)
示例#11
0
def convert_mascot_to_peptagram(params, print_fn=sys.stdout.write):
  if len(params['files_and_labels']) == 0:
    raise ValueError('No files were selected.')

  size = parse.size_str(params['fasta'])
  print_fn("Using sequences from %s (%s)...\n" % (params['fasta'], size))

  great_ionscore = float(params['great_ionscore'])
  cutoff_ionscore = float(params['cutoff_ionscore'])
  proteins = {}
  labels = []

  for fname, label in params['files_and_labels']:
    labels.append(label)
    size = parse.size_str(fname)
    print_fn("Processing %s (%s)...\n" % (fname, size))
    these_proteins = peptagram.mascot.get_proteins(
        fname, great_ionscore, cutoff_ionscore)
    proteins = peptagram.proteins.merge_two_proteins(
        proteins, these_proteins)

  peptagram.proteins.filter_proteins(proteins, params)

  peptagram.proteins.make_graphical_comparison_visualisation({
      'title': params['title'],
      'proteins': proteins,
      'source_labels': labels,
      'color_names': [great_ionscore, cutoff_ionscore],
      'out_dir': params['out_dir'],
  })

  html = os.path.join(params['out_dir'], 'index.html')
  size = parse.size_str(params['out_dir'])
  print_fn('Successfully built peptagram (%s): %s\n' % (size, html))

  return os.path.abspath(html)