Ryan's Blog

C: singly linked list

Posted in programming by ryanlayer on May 19, 2014

struct uint_ll {
   unsigned int value;
   struct uin_ll *next;
};

struct uint_ll *n = (struct uint_ll *) malloc(sizeof(struct uint_ll));
n->value = rel_v;
n->next = NULL;

if (head == NULL)
   head = n;
else
   tail->next = n;

tail = n;

Advertisements
Tagged with: , ,

Matplotlib: Set Font

Posted in Uncategorized by ryanlayer on April 22, 2014

from matplotlib import rcParams
rcParams['font.family'] = 'Arial'

Tagged with: ,

Matplotlib: black background

Posted in research by ryanlayer on February 18, 2014


matplotlib.rcParams.update({'font.size': 12})
fig = matplotlib.pyplot.figure(figsize=(5,5),dpi=300,facecolor='black')
fig.subplots_adjust(wspace=.05,left=.01,bottom=.01)
ax = fig.add_subplot(1,1,1,axisbg='k')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
ax.spines['bottom'].set_color('white')
ax.spines['left'].set_color('white')

ax.title.set_color('white')
ax.yaxis.label.set_color('white')
ax.xaxis.label.set_color('white')
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')

ax.tick_params(axis='both', direction='in')
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

ax.set_xlabel('X-Axis Label Here')
ax.set_ylabel('Y-Axis Label Here')
ax.set_title('Title Here')

ax.plot(range(10),range(10),'.-',color='yellow',\
  linewidth=2,\
  markersize=12)

matplotlib.pyplot.savefig("dark.png",\
  bbox_inches='tight',\
  facecolor=fig.get_facecolor(),\
  transparent=True)

Here for a Matplotlib color names.

Tagged with: , ,

Latex: add date/time to footer

Posted in Uncategorized by ryanlayer on December 31, 2013
\usepackage{fancyhdr}
\usepackage{datetime} %access to \currenttime
\pagestyle{fancy}
\fancyhead{} %clear out default
\fancyfoot[R]{\today\ \currenttime} %set date/time on right
\fancyfoot[C]{\thepage} % page in center
\renewcommand{\headrulewidth}{0pt} % remove awful top bar

More at here and MORE here.

Tagged with: , ,

Matplotlib: plot border, removing and setting width

Posted in Uncategorized by ryanlayer on December 17, 2013
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
Tagged with: ,

Matplotlib: axis labels, rotating and aligning

Posted in Uncategorized by ryanlayer on December 17, 2013
n=5

x = np.arange(n)
y = np.sin(np.linspace(-3,3,n))
xlabels = ['Ticklabel %i' % i for i in range(n)]

fig, axs = plt.subplots(1,3, figsize=(12,3))

ha = ['right', 'center', 'left']

for n, ax in enumerate(axs):
    ax.plot(x,y, 'o-')
    ax.set_title(ha[n])
    ax.set_xticks(x)
    ax.set_xticklabels(xlabels, rotation=40, ha=ha[n])

 

http://stackoverflow.com/questions/14852821/aligning-rotated-xticklabels-with-their-respective-xticks

Tagged with: , ,

Venter Genome Simulation

Posted in Uncategorized by ryanlayer on December 19, 2012

$ wc -ml Simulated_Venter_Chr17.fa
1575757 80363571 Simulated_Venter_Chr17.fa

There are 1575757 lines and 80363571 characters (including new line chars).  Minus new lines, there are 78787814 characters.  The first line is “>Simulated_Venter_Chr17”, which is 24 characters, so the final genome size is 78787790.

To find the number of pairs we want to simulate we use the following formula:

NUM_PAIRS=`echo “($SIZE*$COVERAGE)/($READ_LENGTH*2)” | bc`

Latex scientific notation, made easy

Posted in latex by ryanlayer on January 13, 2012

\providecommand{\e}[1]{\ensuremath{\times 10^{#1}}}

Then, typing

The [111] crystal planes are 3.2\e{-10} m apart.

http://www.tapdancinggoats.com/easy-scientific-notation-in-latex.htm

R plot magic

Posted in Uncategorized by ryanlayer on January 12, 2012

To move the axis labels/lines:

par(mpg=c(, , ))

default is mpg=c(3,1,0), but mgp=c(1.75, 0.5, 0) works

To move margins:

par(mar=c(,,,))

default is mar=c(5,4,4,2)+0.1, but mar=c(3,3,0,0)+0.1 works

Using awk to randomly sample a file

Posted in Uncategorized by ryanlayer on January 6, 2012

Create a file with 1000 lines:

for i in {1..1000};do echo $i; done > f


export P=0.5
cat f | awk -v p=$P 'BEGIN{srand()} {r = rand(); if (r <= p) print}'