Skip to content

Instantly share code, notes, and snippets.

@kevin3
kevin3 / GPU-tensorflow-keras-check.py
Created June 5, 2022 10:58
testing if installed GPU enabled keras and tensorflow
###test if Using GPU for ML
#These commands in the Python terminal should bring up both a CPU and a GPU device, if TensorFlow correctly identifies your GPU.
import tensorflow as tf
tf.__version__
import keras
keras.__version__
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
awk '{print substr($0,1,10)}' bam.list
def read_date(date):
if isinstance(date, int):
return pd.to_datetime(date,unit='D', origin='1899-12-30')
#return xlrd.xldate.xldate_as_datetime(date, 0)
else:
return(pd.to_datetime(date))
print("Converting 42985 to")
print(read_date(42985 ))
~/bin/kraken2/kraken2 --db ~/k2_standard_16gb_20210517 --use-names --gzip-compressed $1 --output $1.kraken --report $1.kraken.report
cut -f2,3 $1.kraken > $1.kraken.kronainput
ktImportTaxonomy -tax /home/kev/Krona-master/KronaTools/taxonomy $1.kraken.kronainput -o $1.kraken.kronainput.html
#!/bin/bash
samtools view -b -f 4 $1 > $1.unmapped.bam
samtools index $1.unmapped.bam
java -Xmx8g -jar /opt/picard/picard-tools-current/picard.jar SamToFastq I=$1.unmapped.bam F=$1.unmapped.bam.fastq
/home/ionadmin/bin/bbmap/reformat.sh in=$1.unmapped.bam.fastq out=$1.unmapped.bam.fastq.fasta
gzip $1.unmapped.bam.fastq.fasta
The following tricks I find pretty useful in my daily Python work. I also added a few I stumbled upon lately.
1. Use collections
This really makes your code more elegant and less verbose, a few examples I absorbed this week:
Named tuples:
>>> Point = collections.namedtuple('Point', ['x', 'y'])
>>> p = Point(x=1.0, y=2.0)
rsync -ahP --times --owner --group /mnt/external/exportedReports/Auto_user_S5-00333-1 /media/USB
import plotly
from plotly.tools import FigureFactory as FF
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gantt_example.csv')
fig = FF.create_gantt(df, colors=['#333F44', '#93e4c1'], index_col='Complete', show_colorbar=True,
bar_width=0.2, showgrid_x=True, showgrid_y=True)
plotly.offline.plot(fig, filename='gantt-use-a-pandas-dataframe')
@kevin3
kevin3 / transaction.sql
Created March 22, 2013 18:10
trial sql create table for a record of stock transactions
Create Table "main"."transactions"
CREATE TABLE IF NOT EXISTS "main"."transactions" ("tid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
"stkcode" TEXT NOT NULL ,
"stkname" TEXT, "qty" INTEGER NOT NULL ,
"broker" TEXT NOT NULL ,
"price" REAL NOT NULL ,
"targetprice" REAL,
"stoploss" REAL,
"longshort" TEXT NOT NULL ,
"date" TEXT NOT NULL ,
@kevin3
kevin3 / parseSCBtrans.py
Created March 18, 2013 19:49
Simple python script to join every 4 lines and also misc formatting to get SCB transactions auto formatted as a csv file
#!/usr/bin/python
"""simple python script to join every 4 lines into one from a plain text file"""
data = open("SCBtransactions2013-03-19.orig.csv").readlines()
data = [ i.strip() for i in data ] #get rid of newlines
data = [ i.replace("\t \t","\t") for i in data ] #get rid of double tabs
data = [ i.replace("SGD","") for i in data ] #get rid of SGD
fourlines = range(0,len(data),4)
for num,line in enumerate(data):
if num in fourlines:
print ' '.join(data[num:num+4])