<jupyter_start><jupyter_text>Process STRING protein interactions DataJupyter Notebook to download and preprocess files to transform to BioLink RDF. Download filesThe download can be defined:* in this Jupyter Notebook using Python* as a Bash script in the `download/download.sh` file, and executed using `d2s download string`<jupyter_code>import os
import glob
import requests
import functools
import shutil
import pandas as pd 

# Use Pandas, load file in memory
def convert_tsv_to_csv(tsv_file):
    csv_table=pd.read_table(tsv_file,sep='\t')
    csv_table.to_csv(tsv_file[:-4] + '.csv',index=False)

# Variables and path for the dataset
dataset_id = 'string'
dsri_flink_pod_id = 'flink-jobmanager-###'
input_folder = '/notebooks/workspace/input/' + dataset_id
mapping_folder = '/notebooks/datasets/' + dataset_id + '/mapping'
os.makedirs(input_folder, exist_ok=True)
# Use input folder as working folder
os.chdir(input_folder)

files_to_download = [
    'https://raw.githubusercontent.com/MaastrichtU-IDS/d2s-scripts-repository/master/resources/cohd-sample/concepts.tsv'
]

# Download each file and uncompress them if needed
# Use Bash because faster and more reliable than Python
for download_url in files_to_download:
    os.system('wget -N ' + download_url)
    os.system('find . -name "*.tar.gz" -exec tar -xzvf {} \;')
    os.system('unzip -o \*.zip')

# Rename .txt to .tsv
listing = glob.glob('*.txt')
for filename in listing:
    os.rename(filename, filename[:-4] + '.tsv')

    
## Convert TSV to CSV to be processed with the RMLStreamer
# use Pandas (load in memory)
convert_tsv_to_csv('concepts.tsv')
# Use Bash 
# cmd_convert_csv = """sed -e 's/"/\\"/g' -e 's/\t/","/g' -e 's/^/"/' -e 's/$/"/'  -e 's/\r//' concepts.tsv > concepts.csv"""
# os.system(cmd_convert_csv)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13204419889502764, 'fraction_numerical': 0.0022099447513812156, 'mean_word_length': 4.487878787878788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '200122', 'license': 'MIT', 'n_tokens_mistral': 644, 'n_tokens_neox': 628, 'n_words': 173, 'path': 'archived-datasets/string/process-string.ipynb', 'repo_name': 'MaastrichtU-IDS/data2services-cwl-workflows', 'size': '1810'}