<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Analyzing the Pathway Commons 2 (PC2) database SIF file
CS446/546 class session 2
Goal
Step1:  How long your program take to run?
How many protein-protein interactions are there in the data file?
How many unique protein names are there in the data file?
How many unique pairs of proteins (regarless of interaction type name) are there that interact?
How many interactions are there of each type, in PC2?
Step2:  Pythonistas
<ASSISTANT_TASK:>
Python Code:
from urllib.request import urlopen
import gzip
import timeit
baseURL = "http://www.pathwaycommons.org/archives/PC2/v9/"
filename = "PathwayCommons9.All.hgnc.sif.gz"
outFilePath = "pc.sif"
interaction_types_ppi = set(["interacts-with","in-complex-with","neighbor-of"])
start_time = timeit.default_timer()
zfd = urlopen(baseURL + filename)
fd = gzip.GzipFile(fileobj=zfd, mode="r")
# initialize the SIF file interaction counter
intctr = 0
linectr = 0
from collections import defaultdict
interactions = set()
proteins = set()
intnamectr = defaultdict(int)
for line in fd:
    if linectr < 6:
        print(line)
        
    linectr += 1
    
    linetext = line.decode("utf-8").rstrip("\n")
    ## MISSING CODE HERE:
    ## make a tuple of [prot1, interaction_type, prot2"] using the "split" method on "linetext"
    
    intnamectr[interaction_type] += 1
    if interaction_type in interaction_types_ppi:
        intctr += 1
        proteins |= set([prot1, prot2])
        interactions.add(min(prot1, prot2) + "-" + max(prot1, prot2))       
        
elapsed = timeit.default_timer() - start_time
Explanation: Analyzing the Pathway Commons 2 (PC2) database SIF file
CS446/546 class session 2
Goal: count the number of different types of biological interactions in PC2
Approach: retrieve compressed tab-delimited "edge-list" file and tabulate "interaction" column
Information you will need:
The URL is: http://www.pathwaycommons.org/archives/PC2/v9/PathwayCommons9.All.hgnc.sif.gz
You'll be using the Python modules gzip, timeit, pandas, urllib.request, collections and operator
Other stuff you should do:
Print the first six lines of the uncompressed data file
Use a timer to time how long your program takes
Count how many rows there are in the data file 
Estimate the number of proteins in the database; we'll define them operationally as strings in column 1 or column 3, for which the content of column 2 is one of these interactions: 'interacts-with', 'in-complex-with', 'neighbor-of'
Count the total number of unique pairs of interacting molecules (ignoring interaction type)
Count the number rows for each type of interaction in the database
Pythonistas:  do it using Pandas and without using Pandas
Step-by-step instructions for Python3:
Open a file object representing a stream of the remote, compressed data file, using urlopen
Open a file object representing a stream of the uncompressed data file, using gzip.GzipFile
Start the timer
Read one line at a time, until the end of the file
Split line on "\t" and pull out the tuple of species1, interaction_type, species2 from the line of text
End of explanation
from operator import itemgetter
sorted(intnamectr.items(), key=itemgetter(1), reverse=True)
Explanation: How long your program take to run?
How many protein-protein interactions are there in the data file?
How many unique protein names are there in the data file?
How many unique pairs of proteins (regarless of interaction type name) are there that interact?
How many interactions are there of each type, in PC2?
End of explanation
import pandas
zfd = urlopen(baseURL + filename)
fd = gzip.GzipFile(fileobj=zfd, mode="r")
Explanation: Pythonistas:  do it again, using Pandas:
read from the uncompressed data stream, and parse it into a data frame, using pandas.read_csv
End of explanation
<END_TASK>