Changeset 9002:d1aa1e599216 in orange


Ignore:
Timestamp:
09/23/11 19:49:40 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
78c1c5d8881eca0f1f05877e584f5b311edf5e0d
Message:
 
Location:
orange/Orange/network
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/network/__init__.py

    r8042 r9002  
    6565 
    6666import community 
     67import snap 
    6768 
    6869from deprecated import * 
  • orange/Orange/network/readwrite.py

    r8866 r9002  
    2222import itertools 
    2323import tempfile 
     24import gzip 
    2425 
    2526import networkx as nx 
     
    114115     
    115116    #supported = ['.net', '.gml', '.gpickle', '.gz', '.bz2', '.graphml'] 
    116     supported = ['.net', '.gml', '.gpickle'] 
     117    supported = ['.net', '.gml', '.gpickle', '.gz'] 
    117118     
    118119    if not os.path.isfile(path): 
     
    131132    if ext == '.gpickle': 
    132133        return read_gpickle(path, auto_table=auto_table) 
     134     
     135    if ext == '.gz' and path[-6:] == 'txt.gz': 
     136        return read_txtgz(path) 
    133137 
    134138def write(G, path, encoding='UTF-8'): 
     
    361365    rwgml.write_gml(G, path) 
    362366 
     367def read_txtgz(path): 
     368    f = gzip.open(path, 'rb') 
     369    content = f.read() 
     370    f.close() 
     371     
     372    content = content.split('\n') 
     373    comments = (line for line in content if line.strip().startswith('#')) 
     374    content = (line for line in content if not line.strip().startswith('#')) 
     375     
     376    if "directed graph" in ''.join(comments).lower(): 
     377        G = Orange.network.DiGraph() 
     378    else: 
     379        G = Orange.network.Graph() 
     380     
     381    G.add_edges_from([int(node) for node in coors.strip().split('\t')] for coors in content if len(coors.strip().split('\t')) == 2) 
     382     
     383    return G 
     384 
    363385_add_doc(write_gml, rwgml.write_gml) 
Note: See TracChangeset for help on using the changeset viewer.