Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX command to select the best edge values from a network file Post 303045006 by Sanchari on Tuesday 10th of March 2020 06:16:47 PM
Old 03-10-2020
UNIX command to select the best edge values from a network file

I have a tab-delimited data representing network data (undirected). Among the duplicated edges, I wanted to select those edges for which I have the higher absolute value of the log values.
I have written a code in python, but its taking a lot of time. I would be grateful if someone helps me with an awk command. Kindly note, the network is undirected, i.e. A--B and B--A are duplicate edges. My original file has a large number of columns, I have given a simplified test data

Test data



Code:
     Gene1    Gene2    Log
    AT1G01020    AT1G01010    1.682708
    AT1G01020    AT1G01010    -1.90043
    AT1G01020    AT1G01010    -1.832192
    AT1G01070    AT1G01060    -0.591932
    AT1G01070    AT1G01060    -1.204241
    AT1G01073    AT1G01070    0.790549
    AT1G01060    AT1G01070    1.214972

Expected Output

Code:
    AT1G01020    AT1G01010    -1.90043
    AT1G01070    AT1G01060    1.214972
    AT1G01073    AT1G01070    0.790549

Code:
gene_table=file1.readlines() # In the real file, j[12]=Gene1, j[13]=Gene2 and j[27]=log value
lfc=[]
for j in gene_table:
    j=j.split("\t")
    j[12]=j[12].strip()
    j[13]=j[13].strip()
    lfc=[]
    int_list=[]
    lfc.append(float(j[27]))
    int_list.append(j[0])
    dict_int={}
    for k in gene_table:
        k=k.split("\t")
        k[12]=k[12].strip()
        k[13]=k[13].strip()
        if (j[0]!=k[0]) and ((j[12]==k[12] and j[13]==k[13]) or (j[12]==k[13] and j[12]==k[13])):
            lfc.append(float(k[27]))
    dict_int=dict(zip(int_list, lfc))
    x=max(lfc, key=abs)
    #print x
    listOfKeys = [key  for (key, value) in dict_int.items() if value == x]
    print listOfKeys


Last edited by Scrutinizer; 03-11-2020 at 12:29 AM..
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to select a particular media from the printer with a UNIX command

Problem Overview: We have a scheduler that prints report on any of the network printer. Problem Statement: We need to find a UNIX command that picks up either A4, legal or letter size paper form the printer. I found out a command but it's not working on our environment. ... (3 Replies)
Discussion started by: HelpMeOUt
3 Replies

2. Shell Programming and Scripting

Select distinct values from a flat file

Hi , I have a similar problem. Please can anyone help me with a shell script or a perl. I have a flat file like this fruit country apple germany apple india banana pakistan banana saudi mango india I want to get a output like fruit country apple ... (7 Replies)
Discussion started by: smalya
7 Replies

3. Shell Programming and Scripting

Identify high values "ÿ" in a text file using Unix command

I have high values (such as ÿÿÿÿ) in a text file contained in an Unix AIX server. I need to identify all the records which are having these high values and also get the position/column number in the record structure if possible. Is there any Unix command by which this can be done to : 1.... (5 Replies)
Discussion started by: devina
5 Replies

4. Shell Programming and Scripting

Running a select script through UNIX and sending output to file

Hi, (Oracle, AIX) I have googled this and searched this forum, however I haven't had much luck with an answer and have tried several different things. Basically I have a SQL select statement which generates a whole load of UPDATE statements, I want to run the select statement via... (13 Replies)
Discussion started by: dbchud
13 Replies

5. Shell Programming and Scripting

Unix command to select first few characters and last character of a line

I have a huge file and I want to select first 10 charcters and last 2 characters of everyline and than will filter the unique line. I know, it must be easy bt I am new to unix scripting:) Ex. I have file as below and need to e3kbaird and last 2 characters. and than unique records. ... (3 Replies)
Discussion started by: Sanjeev Yadav
3 Replies

6. Shell Programming and Scripting

Comparing multiple network files (edge lists)

I want to compare 4 edge-lists to basically see if an edge is present in all 4 networks. The issue is that an edge A-B in one file can be present as B-A in another file. Example: Input 1: net1.txt A B 0.1 C D 0.65 D E 0.9 E A 0.7 Input 2: net2.txt A Z 0.1 C D 0.65 E D 0.9 E A... (1 Reply)
Discussion started by: Sanchari
1 Replies

7. Shell Programming and Scripting

UNIX command -Filter rows in fixed width file based on column values

Hi All, I am trying to select the rows in a fixed width file based on values in the columns. I want to select only the rows if column position 3-4 has the value AB I am using cut command to get the column values. Is it possible to check if cut -c3-4 = AB is true then select only that... (2 Replies)
Discussion started by: ashok.k
2 Replies

8. Shell Programming and Scripting

Split a content in a file with specific interval base on the delimited values using UNIX command

Hi All, we have a requirement to split a content in a text file every 5 rows and write in a new file . conditions: if 5th line falls between center of the statement . it should look upto after ";" files are below format: 1 UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS' 2 WHERE... (3 Replies)
Discussion started by: KK230689
3 Replies
gv(3python)															       gv(3python)

NAME
gv_python - graph manipulation in python SYNOPSIS
#!/usr/bin/python import gv USAGE
INTRODUCTION
gv_python is a dynamically loaded extension for python that provides access to the graph facilities of graphviz. COMMANDS
New graphs New empty graph graph_handle gv.graph (name); graph_handle gv.digraph (name); graph_handle gv.strictgraph (name); graph_handle gv.strictdigraph (name); New graph from a dot-syntax string or file graph_handle gv.readstring (string); graph_handle gv.read (string filename); graph_handle gv.read (channel); Add new subgraph to existing graph graph_handle gv.graph (graph_handle, name); New nodes Add new node to existing graph node_handle gv.node (graph_handle, name); New edges Add new edge between existing nodes edge_handle gv.edge (tail_node_handle, head_node_handle); Add a new edge between an existing tail node, and a named head node which will be induced in the graph if it doesn't already exist edge_handle gv.edge (tail_node_handle, head_name); Add a new edge between an existing head node, and a named tail node which will be induced in the graph if it doesn't already exist edge_handle gv.edge (tail_name, head_node_handle); Add a new edge between named tail and head nodes which will be induced in the graph if they don't already exist edge_handle gv.edge (graph_handle, tail_name, head_name); Setting attribute values Set value of named attribute of graph/node/edge - creating attribute if necessary string gv.setv (graph_handle, attr_name, attr_value); string gv.setv (node_handle, attr_name, attr_value); string gv.setv (edge_handle, attr_name, attr_value); Set value of existing attribute of graph/node/edge (using attribute handle) string gv.setv (graph_handle, attr_handle, attr_value); string gv.setv (node_handle, attr_handle, attr_value); string gv.setv (edge_handle, attr_handle, attr_value); Getting attribute values Get value of named attribute of graph/node/edge string gv.getv (graph_handle, attr_name); string gv.getv (node_handle, attr_name); string gv.getv (edge_handle, attr_name); Get value of attribute of graph/node/edge (using attribute handle) string gv.getv (graph_handle, attr_handle); string gv.getv (node_handle, attr_handle); string gv.getv (edge_handle, attr_handle); Obtain names from handles string gv.nameof (graph_handle); string gv.nameof (node_handle); string gv.nameof (attr_handle); Find handles from names graph_handle gv.findsubg (graph_handle, name); node_handle gv.findnode (graph_handle, name); edge_handle gv.findedge (tail_node_handle, head_node_handle); attribute_handle gv.findattr (graph_handle, name); attribute_handle gv.findattr (node_handle, name); attribute_handle gv.findattr (edge_handle, name); Misc graph navigators returning handles node_handle gv.headof (edge_handle); node_handle gv.tailof (edge_handle); graph_handle gv.graphof (graph_handle); graph_handle gv.graphof (edge_handle); graph_handle gv.graphof (node_handle); graph_handle gv.rootof (graph_handle); Obtain handles of proto node/edge for setting default attribute values node_handle gv.protonode (graph_handle); edge_handle gv.protoedge (graph_handle); Iterators Iteration termination tests bool gv.ok (graph_handle); bool gv.ok (node_handle); bool gv.ok (edge_handle); bool gv.ok (attr_handle); Iterate over subgraphs of a graph graph_handle gv.firstsubg (graph_handle); graph_handle gv.nextsubg (graph_handle, subgraph_handle); Iterate over supergraphs of a graph (obscure and rarely useful) graph_handle gv.firstsupg (graph_handle); graph_handle gv.nextsupg (graph_handle, subgraph_handle); Iterate over edges of a graph edge_handle gv.firstedge (graph_handle); edge_handle gv.nextedge (graph_handle, edge_handle); Iterate over outedges of a graph edge_handle gv.firstout (graph_handle); edge_handle gv.nextout (graph_handle, edge_handle); Iterate over edges of a node edge_handle gv.firstedge (node_handle); edge_handle gv.nextedge (node_handle, edge_handle); Iterate over out-edges of a node edge_handle gv.firstout (node_handle); edge_handle gv.nextout (node_handle, edge_handle); Iterate over head nodes reachable from out-edges of a node node_handle gv.firsthead (node_handle); node_handle gv.nexthead (node_handle, head_node_handle); Iterate over in-edges of a graph edge_handle gv.firstin (graph_handle); edge_handle gv.nextin (node_handle, edge_handle); Iterate over in-edges of a node edge_handle gv.firstin (node_handle); edge_handle gv.nextin (graph_handle, edge_handle); Iterate over tail nodes reachable from in-edges of a node node_handle gv.firsttail (node_handle); node_handle gv.nexttail (node_handle, tail_node_handle); Iterate over nodes of a graph node_handle gv.firstnode (graph_handle); node_handle gv.nextnode (graph_handle, node_handle); Iterate over nodes of an edge node_handle gv.firstnode (edge_handle); node_handle gv.nextnode (edge_handle, node_handle); Iterate over attributes of a graph attribute_handle gv.firstattr (graph_handle); attribute_handle gv.nextattr (graph_handle, attr_handle); Iterate over attributes of an edge attribute_handle gv.firstattr (edge_handle); attribute_handle gv.nextattr (edge_handle, attr_handle); Iterate over attributes of a node attribute_handle gv.firstattr (node_handle); attribute_handle gv.nextattr (node_handle, attr_handle); Remove graph objects bool gv.rm (graph_handle); bool gv.rm (node_handle); bool gv.rm (edge_handle); Layout Annotate a graph with layout attributes and values using a specific layout engine bool gv.layout (graph_handle, string engine); Render Render a layout into attributes of the graph bool gv.render (graph_handle); Render a layout to stdout bool gv.render (graph_handle, string format); Render to an open file bool gv.render (graph_handle, string format, channel fout); Render a layout to an unopened file by name bool gv.render (graph_handle, string format, string filename); Render to an open channel bool gv.renderchannel (graph_handle, string format, string channelname); Render to a string result gv.renderresult (graph_handle, string format, string outdata); Render a layout to a malloc'ed string, to be free'd by the caller (deprecated - too easy to leak memory) (still needed for "eval [gv::renderdata $G tk]" ) string gv.renderdata (graph_handle, string format); Writing graph back to file bool gv.write (graph_handle, string filename); bool gv.write (graph_handle, channel); KEYWORDS
graph, dot, neato, fdp, circo, twopi, python. 11 January 2014 gv(3python)
All times are GMT -4. The time now is 09:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy