File size: 3,936 Bytes
b17fedc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"def generate_random_dna_sequence(length):\n",
" return ''.join(random.choices('ATGC', k=length))\n",
"\n",
"np.random.seed(42)\n",
"\n",
"# Generate 200 sequences of random DNA sequences with lengths ranging from 200 to 2000\n",
"sequence_lengths = np.random.randint(200, 2001, size=200)\n",
"dna_sequences = [generate_random_dna_sequence(length) for length in sequence_lengths]\n",
"labels1 = np.random.randint(0, 2, size=200)\n",
"labels2 = np.random.randint(0, 3, size=200)\n",
"labels3 = np.random.randint(0, 5, size=200)\n",
"\n",
"# Create a DataFrame with the DNA sequences and random labels\n",
"df_dna = pd.DataFrame({\n",
" 'sequence': dna_sequences,\n",
" 'label1': labels1,\n",
" 'label2': labels2,\n",
" 'label3': labels3\n",
"})\n",
"\n",
"# Save to CSV\n",
"csv_dna_path = \"/data/project/hf_tutorial/data/train.csv\"\n",
"df_dna.to_csv(csv_dna_path, index=False)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Generate 200 sequences of random DNA sequences with lengths ranging from 200 to 2000\n",
"sequence_lengths = np.random.randint(200, 2001, size=200)\n",
"dna_sequences = [generate_random_dna_sequence(length) for length in sequence_lengths]\n",
"labels1 = np.random.randint(0, 2, size=200)\n",
"labels2 = np.random.randint(0, 3, size=200)\n",
"labels3 = np.random.randint(0, 5, size=200)\n",
"\n",
"# Create a DataFrame with the DNA sequences and random labels\n",
"df_dna = pd.DataFrame({\n",
" 'sequence': dna_sequences,\n",
" 'label1': labels1,\n",
" 'label2': labels2,\n",
" 'label3': labels3\n",
"})\n",
"\n",
"# Save to CSV\n",
"csv_dna_path = \"/data/project/hf_tutorial/data/eval.csv\"\n",
"df_dna.to_csv(csv_dna_path, index=False)\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# Function to generate a random string of a given length\n",
"def generate_random_string(length):\n",
" return ''.join(random.choices('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', k=length))\n",
"\n",
"# Generate random strings for each label category\n",
"label1_strings = {0: generate_random_string(2), 1: generate_random_string(2)}\n",
"label2_strings = {i: generate_random_string(3) for i in range(3)}\n",
"label3_strings = {i: generate_random_string(5) for i in range(5)}\n",
"\n",
"# Save each string to a separate text file\n",
"label1_path = \"/data/project/hf_tutorial/data/label1.txt\"\n",
"label2_path = \"/data/project/hf_tutorial/data/label2.txt\"\n",
"label3_path = \"/data/project/hf_tutorial/data/label3.txt\"\n",
"\n",
"def save_label_strings(label_strings, path):\n",
" with open(path, 'w') as f:\n",
" for label, string in label_strings.items():\n",
" f.write(f\"{label}: {string}\\n\")\n",
"\n",
"save_label_strings(label1_strings, label1_path)\n",
"save_label_strings(label2_strings, label2_path)\n",
"save_label_strings(label3_strings, label3_path)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|