Exemple #1
0
def main(argv):
    #Create variables
    expression_data = None
    motif = None
    ppi = None
    output_file = "output_panda.txt"
    rm_missing = False
    lioness_file = False
    # Get input options
    try:
        opts, args = getopt.getopt(argv, 'he:m:p:o:rq:', ['help', 'expression=', 'motif=', 'ppi=', 'out=', 'rm_missing', 'lioness'])
    except getopt.GetoptError:
        print(__doc__)
        sys.exit()
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print(__doc__)
            sys.exit()
        elif opt in ('-e', '--expression'):
            expression_data = arg
        elif opt in ('-m', '--motif'):
            motif = arg
        elif opt in ('-p', '--ppi'):
            ppi = arg
        elif opt in ('-o', '--out'):
            output_file = arg
        elif opt in ('-r', '--rm_missing'):
            rm_missing = arg
        elif opt in ('-q', '--lioness'):
            lioness_file = arg
    #Check if required options are given
    print('Input data:')
    print('Expression:', expression_data)
    print('Motif data:', motif)
    print('PPI data:', ppi)
    if expression_data is None and motif is None:
        print('Missing inputs!')
        print(__doc__)
        sys.exit()

    # Run PANDA
    print('Start Panda run ...')
    panda_obj = Panda(expression_data, motif, ppi, save_tmp=True, remove_missing=rm_missing, keep_expression_matrix=bool(lioness_file))
    #panda_obj = pypanda.Panda(expression_data, motif, None, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(None, motif, ppi, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(None, motif, None, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(expression_data, None, ppi, save_tmp=True, remove_missing=rm_missing)
    panda_obj.save_panda_results(output_file)
    #panda_obj.top_network_plot(top=70, file='panda_topgenes.png')
    #indegree = panda_obj.return_panda_indegree()
    #outdegree = panda_obj.return_panda_outdegree()

    if lioness_file:
        from netZooPy.lioness.lioness import Lioness
        lioness_obj = Lioness(panda_obj)
        lioness_obj.save_lioness_results(lioness_file)
    print('All done!')
Exemple #2
0
def test_panda():
    #print(os.getcwd())
    print('Start Panda run ...')
    ppi = 'tests/puma/ToyData/ToyPPIData.txt'
    motif = 'tests/puma/ToyData/ToyMotifData.txt'
    expression_data = 'tests/puma/ToyData/ToyExpressionData.txt'
    lioness_file = ''
    rm_missing = False
    output_file = 'travis_test_panda.txt'
    gt_file = 'tests/panda/union_test_panda.txt'

    #1. Union
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='union')
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #3. In-degree and out-degree
    panda_obj.return_panda_indegree()
    panda_obj.return_panda_outdegree()
    # Lazy test
    assert (round(panda_obj.panda_indegree.iloc[0].loc['force'], 5) == 1.13971)
    assert (round(panda_obj.panda_outdegree.iloc[0].loc['force'],
                  5) == 1030.06840)

    #2. Legacy
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=True,
                      remove_missing=rm_missing,
                      keep_expression_matrix=True,
                      save_memory=True,
                      modeProcess='legacy')
    panda_obj.save_panda_results(output_file)
    gt_file = 'tests/panda/legacy_test_panda.txt'
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)
    print('Test panda passed was successful!')
def test_panda():
    #print(os.getcwd())
    print('Start Panda run ...')
    ppi = 'tests/ToyData/ToyPPIData.txt'
    motif = 'tests/ToyData/ToyMotifData.txt'
    expression_data = 'tests/ToyData/ToyExpressionData.txt'
    lioness_file = ''
    rm_missing = False
    output_file = 'travis_test_panda.txt'
    gt_file = 'tests/panda/test_panda.txt'

    #1. Vanilla panda
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file))
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file, sep=' ', header=None)
    #assert(gt.equals(round(res,3)))
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #2. with argument values
    rm_missing = False
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=True,
                      remove_missing=rm_missing,
                      keep_expression_matrix=True,
                      save_memory=True)
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    assert (np.allclose(gt.iloc[:, 3], res.transpose().values.flatten()))
    print('Test panda passed was successful!')

    #3. From command line
    os.system(
        'python3 run_panda.py -e ./tests/ToyData/ToyExpressionData.txt -m ./tests/ToyData/ToyMotifData.txt -p ./tests/ToyData/ToyPPIData.txt -o test_panda.txt -q output_panda.txt'
    )
    res2 = pd.read_csv(output_file, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  res2,
                                  check_less_precise=False,
                                  check_exact=False)
Exemple #4
0
def test_panda():
    #print(os.getcwd())
    print('Start Panda run ...')
    ppi = 'tests/puma/ToyData/ToyPPIData.txt'
    motif = 'tests/puma/ToyData/ToyMotifData.txt'
    expression_data = 'tests/puma/ToyData/ToyExpressionData.txt'
    lioness_file = ''
    rm_missing = False
    output_file = 'travis_test_panda.txt'
    gt_file = 'tests/panda/union_test_panda.txt'
    gt_file_inter = 'tests/panda/inter_test_panda.txt'

    #0. Intersection
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='intersection')
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file_inter, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #0.1 Intersection via DataFrame
    expression = pd.read_csv(expression_data,
                             sep='\t',
                             header=None,
                             index_col=0)
    motif_data = pd.read_csv(motif, sep='\t', names=['source', 'target', 'w'])
    ppi_data = pd.read_csv(ppi, sep='\t', header=None)

    panda_obj = Panda(expression,
                      motif_data,
                      ppi_data,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='intersection')
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file_inter, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #0.2 Intersection with symmetric PPI
    ppi_data = pd.read_csv(ppi, sep='\t', header=None)
    new_df = pd.DataFrame(data={
        0: ppi_data[0],
        1: ppi_data[1],
        2: ppi_data[2]
    })
    ppi_data_symm = pd.concat([ppi_data, new_df])
    panda_obj = Panda(expression,
                      motif_data,
                      ppi_data_symm,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='intersection')
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file_inter, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #1. Union
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='union')
    panda_obj.save_panda_results(output_file)
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)

    #2. In-degree and out-degree
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=False,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file),
                      modeProcess='union',
                      save_memory=False)
    panda_obj.return_panda_indegree()
    panda_obj.return_panda_outdegree()
    # Lazy test
    assert (np.round(panda_obj.panda_indegree.iloc[0].loc['force'],
                     5) == 1.13971)
    assert (np.round(panda_obj.panda_outdegree.iloc[0].loc['force'],
                     5) == 1030.06840)

    #3. Legacy
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=True,
                      remove_missing=rm_missing,
                      keep_expression_matrix=True,
                      save_memory=True,
                      modeProcess='legacy')
    panda_obj.save_panda_results(output_file)
    gt_file = 'tests/panda/legacy_test_panda.txt'
    res = pd.read_csv(output_file, sep=' ', header=None)
    gt = pd.read_csv(gt_file, sep=' ', header=None)
    pd.testing.assert_frame_equal(res,
                                  gt,
                                  check_less_precise=False,
                                  check_exact=False)
    print('Test panda passed was successful!')

    #4. None Types
    i = 0
    gt_test_panda = 'gt_panda'
    test_panda = 'test_panda'
    for modeProcess in ['legacy', 'union', 'intersection']:
        print(modeProcess)
        #Motif
        i = i + 1
        panda_obj = Panda(expression_data,
                          None,
                          ppi,
                          save_tmp=True,
                          remove_missing=rm_missing,
                          keep_expression_matrix=True,
                          save_memory=True,
                          modeProcess=modeProcess)
        panda_obj.save_panda_results(test_panda + str(i) + '.txt')
        res = pd.read_csv(test_panda + str(i) + '.txt', sep=' ', header=None)
        os.system(
            'curl -O https://netzoo.s3.us-east-2.amazonaws.com/netZooPy/tutorial_datasets/'
            + gt_test_panda + str(i) + '.txt')
        gt = pd.read_csv(gt_test_panda + str(i) + '.txt', sep=' ', header=None)
        pd.testing.assert_frame_equal(res,
                                      gt,
                                      check_less_precise=False,
                                      check_exact=False)
        #PPI
        i = i + 1
        panda_obj = Panda(expression_data,
                          motif,
                          None,
                          save_tmp=True,
                          remove_missing=rm_missing,
                          keep_expression_matrix=True,
                          save_memory=True,
                          modeProcess=modeProcess)
        panda_obj.save_panda_results(test_panda + str(i) + '.txt')
        res = pd.read_csv(test_panda + str(i) + '.txt', sep=' ', header=None)
        os.system(
            'curl -O https://netzoo.s3.us-east-2.amazonaws.com/netZooPy/tutorial_datasets/'
            + gt_test_panda + str(i) + '.txt')
        gt = pd.read_csv(gt_test_panda + str(i) + '.txt', sep=' ', header=None)
        pd.testing.assert_frame_equal(res,
                                      gt,
                                      check_less_precise=False,
                                      check_exact=False)
        #Expression
        i = i + 1
        panda_obj = Panda(None,
                          motif,
                          ppi,
                          save_tmp=True,
                          remove_missing=rm_missing,
                          keep_expression_matrix=True,
                          save_memory=True,
                          modeProcess=modeProcess)
        panda_obj.save_panda_results(test_panda + str(i) + '.txt')
        res = pd.read_csv(test_panda + str(i) + '.txt', sep=' ', header=None)
        os.system(
            'curl -O https://netzoo.s3.us-east-2.amazonaws.com/netZooPy/tutorial_datasets/'
            + gt_test_panda + str(i) + '.txt')
        gt = pd.read_csv(gt_test_panda + str(i) + '.txt', sep=' ', header=None)
        pd.testing.assert_frame_equal(res,
                                      gt,
                                      check_less_precise=False,
                                      check_exact=False)
        #Expression and PPI
        i = i + 1
        panda_obj = Panda(None,
                          motif,
                          None,
                          save_tmp=True,
                          remove_missing=rm_missing,
                          keep_expression_matrix=True,
                          save_memory=True,
                          modeProcess=modeProcess)
        panda_obj.save_panda_results(test_panda + str(i) + '.txt')
        res = pd.read_csv(test_panda + str(i) + '.txt', sep=' ', header=None)
        os.system(
            'curl -O https://netzoo.s3.us-east-2.amazonaws.com/netZooPy/tutorial_datasets/'
            + gt_test_panda + str(i) + '.txt')
        gt = pd.read_csv(gt_test_panda + str(i) + '.txt', sep=' ', header=None)
        pd.testing.assert_frame_equal(res,
                                      gt,
                                      check_less_precise=False,
                                      check_exact=False)
Exemple #5
0
def main(argv):
    """
    Description:
        Run PANDA algorithm from the command line.

    Inputs:
        -h, --help: help
        -e, --expression: expression values
        -m, --motif: pair file of motif edges, or Pearson correlation matrix when not provided
        -p, --ppi: pair file of PPI edges
        -o, --out: output file
        -r, --rm_missing
        -q, --lioness: output for Lioness single sample networks 
    
    Example:
        python run_panda.py -e ../../tests/ToyData/ToyExpressionData.txt -m ../../tests/ToyData/ToyMotifData.txt -p ../../tests/ToyData/ToyPPIData.txt -o test_panda.txt -q output_panda.txt

    Reference:
        Glass, Kimberly, et al. "Passing messages between biological networks to refine predicted interactions." PloS one 8.5 (2013): e64832.
    """
    #Create variables
    expression_data = None
    motif = None
    ppi = None
    output_file = "output_panda.txt"
    rm_missing = False
    lioness_file = False
    # Get input options
    try:
        opts, args = getopt.getopt(argv, 'he:m:p:o:rq:', [
            'help', 'expression=', 'motif=', 'ppi=', 'out=', 'rm_missing',
            'lioness'
        ])
    except getopt.GetoptError:
        print(__doc__)
        sys.exit()
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print(__doc__)
            sys.exit()
        elif opt in ('-e', '--expression'):
            expression_data = arg
        elif opt in ('-m', '--motif'):
            motif = arg
        elif opt in ('-p', '--ppi'):
            ppi = arg
        elif opt in ('-o', '--out'):
            output_file = arg
        elif opt in ('-r', '--rm_missing'):
            rm_missing = arg
        elif opt in ('-q', '--lioness'):
            lioness_file = arg
    #Check if required options are given
    print('Input data:')
    print('Expression:', expression_data)
    print('Motif data:', motif)
    print('PPI data:', ppi)
    if expression_data is None and motif is None:
        print('Missing inputs!')
        print(__doc__)
        sys.exit()

    # Run PANDA
    print('Start Panda run ...')
    panda_obj = Panda(expression_data,
                      motif,
                      ppi,
                      save_tmp=True,
                      remove_missing=rm_missing,
                      keep_expression_matrix=bool(lioness_file))
    #panda_obj = pypanda.Panda(expression_data, motif, None, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(None, motif, ppi, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(None, motif, None, save_tmp=True, remove_missing=rm_missing)
    #panda_obj = pypanda.Panda(expression_data, None, ppi, save_tmp=True, remove_missing=rm_missing)
    panda_obj.save_panda_results(output_file)
    #panda_obj.top_network_plot(top=70, file='panda_topgenes.png')
    #indegree = panda_obj.return_panda_indegree()
    #outdegree = panda_obj.return_panda_outdegree()

    if lioness_file:
        from netZooPy.lioness.lioness import Lioness
        lioness_obj = Lioness(panda_obj)
        lioness_obj.save_lioness_results(lioness_file)
    print('All done!')