def write_out(new_exp, multipeptides, outfile, matrix_outfile, single_outfile): """ Write the result to disk """ # write out the complete original files writer = csv.writer(open(outfile, "w"), delimiter="\t") header_first = new_exp.runs[0].header for run in new_exp.runs: assert header_first == run.header writer.writerow(header_first) print "number of precursors quantified:", len(multipeptides) for m in multipeptides: # selected_peakgroups = [p.peakgroups[0] for p in m.get_peptides()] # if (len(selected_peakgroups)*2.0 / len(new_exp.runs) < fraction_needed_selected) : continue for p in m.getAllPeptides(): for selected_pg in p.peakgroups: if single_outfile: # Only write the newly imputed ones ... if float(selected_pg.get_value("m_score")) > 1.0: row_to_write = selected_pg.row writer.writerow(row_to_write) else: row_to_write = selected_pg.row writer.writerow(row_to_write) if len(matrix_outfile) > 0: helper.write_out_matrix_file(matrix_outfile, new_exp.runs, multipeptides, 0.0, style=options.matrix_output_method)
def write_out(new_exp, multipeptides, outfile, matrix_outfile, single_outfile=None): """ Write the result to disk This writes all peakgroups to disk (newly imputed ones as previously found ones) as even some "previously good" peakgroups may have changed location due to isotopic_transfer. """ # write out the complete original files writer = csv.writer(open(outfile, "w"), delimiter="\t") header_first = new_exp.runs[0].header for run in new_exp.runs: assert header_first == run.header writer.writerow(header_first) print("number of precursors quantified:", len(multipeptides)) for m in sorted(multipeptides, key=lambda x: str(x)): # selected_peakgroups = [p.peakgroups[0] for p in m.get_peptides()] # if (len(selected_peakgroups)*2.0 / len(new_exp.runs) < fraction_needed_selected) : continue for p in m.getAllPeptides(): for selected_pg in sorted(p.peakgroups): if single_outfile is not None: if single_outfile == selected_pg.get_value("run_id"): # Only write the values for this run ... row_to_write = selected_pg.row writer.writerow(row_to_write) else: row_to_write = selected_pg.row writer.writerow(row_to_write) if len(matrix_outfile) > 0: helper.write_out_matrix_file(matrix_outfile, new_exp.runs, multipeptides, 0.0, style=options.matrix_output_method)
def write_out(new_exp, multipeptides, outfile, matrix_outfile, single_outfile=None): """ Write the result to disk This writes all peakgroups to disk (newly imputed ones as previously found ones) as even some "previously good" peakgroups may have changed location due to isotopic_transfer. """ # write out the complete original files writer = csv.writer(open(outfile, "w"), delimiter="\t") header_first = new_exp.runs[0].header for run in new_exp.runs: assert header_first == run.header writer.writerow(header_first) print("number of precursors quantified:", len(multipeptides)) for m in sorted(multipeptides, key=lambda x: str(x)): # selected_peakgroups = [p.peakgroups[0] for p in m.get_peptides()] # if (len(selected_peakgroups)*2.0 / len(new_exp.runs) < fraction_needed_selected) : continue for p in m.getAllPeptides(): for selected_pg in sorted(p.peakgroups): if single_outfile is not None: if single_outfile == selected_pg.get_value("run_id"): # Only write the values for this run ... row_to_write = selected_pg.row writer.writerow(row_to_write) else: row_to_write = selected_pg.row writer.writerow(row_to_write) if len(matrix_outfile) > 0: helper.write_out_matrix_file(matrix_outfile, new_exp.runs, multipeptides, 0.0, style=options.matrix_output_method)
def write_out(new_exp, multipeptides, outfile, matrix_outfile, single_outfile): """ Write the result to disk """ # write out the complete original files writer = csv.writer(open(outfile, "w"), delimiter="\t") header_first = new_exp.runs[0].header for run in new_exp.runs: assert header_first == run.header writer.writerow(header_first) print "number of precursors quantified:", len(multipeptides) for m in multipeptides: # selected_peakgroups = [p.peakgroups[0] for p in m.get_peptides()] # if (len(selected_peakgroups)*2.0 / len(new_exp.runs) < fraction_needed_selected) : continue for p in m.getAllPeptides(): for selected_pg in p.peakgroups: if single_outfile: # Only write the newly imputed ones ... if float(selected_pg.get_value("m_score")) > 1.0: row_to_write = selected_pg.row writer.writerow(row_to_write) else: row_to_write = selected_pg.row writer.writerow(row_to_write) if len(matrix_outfile) > 0: helper.write_out_matrix_file(matrix_outfile, new_exp.runs, multipeptides, 0.0, style=options.matrix_output_method)
def test_matrix_out_2(self): """Test the output matrix writers""" import msproteomicstoolslib.algorithms.alignment.AlignmentHelper as helper runs = self.exp2.runs multipeptides = self.multipeptides2 tmpfile = "tmp.output.csv" helper.write_out_matrix_file(tmpfile, runs, multipeptides, 0.0, style="full", write_requant=False) os.remove(tmpfile) tmpfile = "tmp.output.tsv" helper.write_out_matrix_file(tmpfile, runs, multipeptides, 0.0, style="full", write_requant=False) os.remove(tmpfile) tmpfile = "tmp.output.xls" helper.write_out_matrix_file(tmpfile, runs, multipeptides, 0.0, style="full", write_requant=False) os.remove(tmpfile) tmpfile = "tmp.output.xlsx" helper.write_out_matrix_file(tmpfile, runs, multipeptides, 0.0, style="full", write_requant=False) os.remove(tmpfile)