diff --git a/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/.ipynb_checkpoints/Untitled-checkpoint.ipynb deleted file mode 100644 index 286dcb3..0000000 --- a/.ipynb_checkpoints/Untitled-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb b/.ipynb_checkpoints/Untitled1-checkpoint.ipynb deleted file mode 100644 index 6233763..0000000 --- a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb +++ /dev/null @@ -1,217 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from __future__ import division\n", - "from reportlab.graphics.barcode import code128\n", - "from reportlab.lib.pagesizes import letter\n", - "from reportlab.lib.units import inch\n", - "from reportlab.pdfgen import canvas\n", - "import pandas as pd\n", - "import numpy as np\n", - "from IPython.display import FileLink, FileLinks" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "def get_ids(input_fh):\n", - "\n", - " id_df = pd.read_csv(input_fh)\n", - " id_list = id_df.ix[:, 0]\n", - "\n", - " return list(id_list)\n", - "\n", - "\n", - "def get_x_y_coordinates(columns, rows, x_start, y_start):\n", - "\n", - " x_coords = np.arange(x_start, (columns*2.2), 2.2)\n", - " y_coords = np.arange(y_start, (y_start - (rows*1.21)), -1.21)\n", - "\n", - " xy_coords = []\n", - " for x_coord in x_coords:\n", - " for y_coord in y_coords:\n", - " xy_coords.append((x_coord*inch, y_coord*inch))\n", - "\n", - " return xy_coords\n", - "\n", - "\n", - "def get_barcodes(input_fh,\n", - " output_fp,\n", - " columns=4,\n", - " rows=9,\n", - " x_start=0,\n", - " y_start=10):\n", - "\n", - " sample_ids = get_ids(input_fh)\n", - " \n", - " barcode_canvas = canvas.Canvas(output_fp, pagesize=letter)\n", - "\n", - " xy_coords = get_x_y_coordinates(columns, rows, x_start, y_start)\n", - " \n", - " c = 0\n", - " for sample_id in sample_ids:\n", - " x = xy_coords[c][0]\n", - " y = xy_coords[c][1]\n", - " # Create the barcodes and sample_id text and draw them on the canvas\n", - " barcode = code128.Code128(sample_id, barWidth=0.009*inch,\n", - " barHeight=0.4*inch)\n", - " barcode.drawOn(barcode_canvas, x, y)\n", - " # the offset for the text will change automatically as x and y\n", - " # coordinates are\n", - " # changed therefore the the following values do not need to be changed.\n", - " barcode_canvas.drawString((x + .47 * inch), (y - .15 * inch),\n", - " sample_id)\n", - " if c < ((rows*columns) - 1):\n", - " c += 1\n", - " else:\n", - " c = 0\n", - " barcode_canvas.showPage()\n", - " barcode_canvas.save()\n", - "# return barcode_ids" - ] - }, - { - "cell_type": "code", - "execution_count": 77, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "input_fh = open('test-files/foo_map.txt')\n", - "output_fp = 'toss_out/toss.pdf'\n", - "get_barcodes(input_fh, output_fp)" - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "toss_out/toss.pdf
" - ], - "text/plain": [ - "/Users/jc33/dev/Barcode-pdf-generator/toss_out/toss.pdf" - ] - }, - "execution_count": 78, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "FileLink('toss_out/toss.pdf')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "output_fp = 'toss_out/toss2.pdf'\n", - "barcode_canvas = canvas.Canvas(output_fp, pagesize=letter)\n", - "barcode = code128.Code128('afc41a02-531a-4fb8-8986-53e4f81eb95a', barWidth=0.009*inch,\n", - " barHeight=0.4*inch)\n", - "barcode.drawOn(barcode_canvas, 1*inch, 10*inch)\n", - "barcode_canvas.drawString((1*inch + .47 * inch), (10*inch - .15 * inch),\n", - " 'afc41a02-531a-4fb8-8986-53e4f81eb95a')\n", - "barcode_canvas.save()" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "toss_out/toss2.pdf
" - ], - "text/plain": [ - "/Users/jc33/dev/Barcode-pdf-generator/toss_out/toss2.pdf" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "FileLink('toss_out/toss2.pdf')" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "afc41a02-531a-4fb8-8986-53e4f81eb95a\n" - ] - } - ], - "source": [ - "import uuid\n", - "print uuid.uuid4()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -}