<commit_before>import rdflib
import logging
from indra.sources.biogrid.processor import BiogridProcessor

logger = logging.getLogger('cwms_rdf')


def process_file(filename):
    """Processes a biogrid tab-separated filer.

    Parameters:
    -----------
    text: str
        The filename of the biogrid file

    Returns
    -------
    bp: indra.sources.cwms.BiogridProcessor
        A BiogridProcessor, which contains a list of INDRA statements in its
        statements attribute.
    """
    bp = BiogridProcessor(filename)
    return bp
    
if __name__ == '__main__':
    fname = '/Users/daniel/Downloads/BIOGRID/BIOGRID-ALL-3.4.158.tab2.txt';bp = process_file(fname)<commit_msg>If the biogrid file is not present, download it from the web, and delete it when done processing<commit_after>from indra.sources.biogrid.processor import BiogridProcessor
import requests
import logging
import tempfile
import zipfile
import os
import shutil

logger = logging.getLogger('cwms_rdf')

biogrid_file_url = 'https://downloads.thebiogrid.org/Download/BioGRID/' + \
        'Release-Archive/BIOGRID-3.4.158/BIOGRID-ALL-3.4.158.tab2.zip'
biogrid_text_file = 'BIOGRID-ALL-3.4.158.tab2.txt'

def process_file(filename=None):
    """Processes a biogrid tab-separated filer.

    Parameters:
    -----------
    text: str
        The filename of the biogrid file, if None downloaded from the web.

    Returns
    -------
    bp: indra.sources.cwms.BiogridProcessor
        A BiogridProcessor, which contains a list of INDRA statements in its
        statements attribute.
    """
    tmp_dir = None
    if filename == None:
        # Filename not specified, download from the web
        tmp_dir = tempfile.mkdtemp('indra_biogrid')

        target_zip = os.path.join(tmp_dir, 'biogrid.zip')
        _download_file(biogrid_file_url, target_zip)

        zip_file = zipfile.ZipFile(target_zip)
        zip_file.extract(biogrid_text_file, tmp_dir)

        filename = os.path.join(tmp_dir, biogrid_text_file)

    bp = BiogridProcessor(filename)

    if tmp_dir is not None:
        # Clean up temporary files
        shutil.rmtree(tmp_dir)
    return bp

def _download_file(url, target):
    """Downloads a file to the specified target, works in python 2 and
    python 3."""
    r = requests.get(url)
    with open(target, 'wb') as f:
        f.write(r.content)
    
if __name__ == '__main__':
    fname = '/Users/daniel/Downloads/BIOGRID/BIOGRID-ALL-3.4.158.tab2.txt';bp = process_file(fname)

{'fraction_non_alphanumeric': 0.10462776659959759, 'fraction_numerical': 0.012474849094567404, 'mean_word_length': 2.9712460063897765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5199457', 'n_tokens_mistral': 854, 'n_tokens_neox': 810, 'n_words': 200}