Skip to content

Commit

Permalink
Merge pull request #26 from jpiper/0.2.6
Browse files Browse the repository at this point in the history
0.2.6 updates
  • Loading branch information
jpiper authored Jan 27, 2018
2 parents 000a774 + 198c209 commit 1e3e24f
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 905 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python:
- "3.3"
- "3.4"
- "3.5"
- "3.6"
addons:
apt:
packages:
Expand Down
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.2.6 - 2018-01-27
==================
* ENHANCEMENT: License changed to MIT
* BUGFIX: Scripts should now all work for Python 3
* BUGFIX: Empty lines in BED files are now ignored
* BUGFIX: Fix issue with passing values to the "-pv" argument on `wellington_footprints.py`

0.2.5 - 2016-07-23
==================
* IMPORTANT: Python 2.6 and 3.2 support dropped. 2.7, 3.3, 3.4, and 3.5 are where it's at.
Expand Down
622 changes: 4 additions & 618 deletions LICENSE.TXT

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ Reference
License
-------

Copyright (C) 2015 Jason Piper. This work is licensed under the GNU GPLv3 license, see ``LICENCE.TXT`` for details. If you require the use of this software under a difference license (e.g. for commercial purposes), please email me at `j.piper@me.com`.
Copyright (C) 2015 Jason Piper. This work is licensed under the MIT license, see ``LICENCE.TXT`` for details. If you require the use of this software under a difference license, please email me at `j.piper@me.com`.
15 changes: 0 additions & 15 deletions examples/footprinttest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import matplotlib.pyplot as plt
import pyDNase
from pyDNase.footprinting import wellington
Expand Down
30 changes: 8 additions & 22 deletions pyDNase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from . import _version
__version__ = _version.__version__

Expand Down Expand Up @@ -277,11 +262,12 @@ def loadBEDFile(self,filename):
records = []

intervalCount = max(enumerate(open(filename)))[0] + 1
for _ in progress.bar(range(intervalCount)):
for _ in progress.bar(list(range(intervalCount))):
line = BEDfile.readline()
#Skip lines in the bed files which are UCSC track metadata or comments
if not self.__isBEDHeader(line):
records.append(self.__parseBEDString(line))
if line:
#Skip lines in the bed files which are UCSC track metadata or comments
if not self.__isBEDHeader(line):
records.append(self.__parseBEDString(line))

for i in records:
self.__addInterval(GenomicInterval(i[0], i[1], i[2], i[3], i[4], i[5]))
Expand Down Expand Up @@ -372,22 +358,22 @@ def __len__(self):
Return the number of intervals in the set
"""
intervals = 0
for each in self.intervals.values():
for each in list(self.intervals.values()):
intervals += len(each)
return intervals

def __iter__(self):
"""
Iterates over the intervals in the order that the intervals were generated
"""
for each in sorted(sum(self.intervals.values(),[]), key=lambda peak: peak.importorder):
for each in sorted(sum(list(self.intervals.values()),[]), key=lambda peak: peak.importorder):
yield each

def __getitem__(self, i):
"""
Indexes the intervals in the order that the intervals were generated
"""
return sorted(sum(self.intervals.values(),[]), key=lambda peak: peak.importorder)[i]
return sorted(sum(list(self.intervals.values()),[]), key=lambda peak: peak.importorder)[i]

def __delitem__(self,i):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyDNase/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.5"
__version__ = "0.2.6"
19 changes: 2 additions & 17 deletions pyDNase/footprinting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import warnings, random
import numpy as np
import pyDNase
from . import WellingtonC

class wellington(object):

def __init__(self,interval,reads,shoulder_sizes=range(35,36), footprint_sizes = range(11,26,2),FDR_cutoff=0.01,FDR_iterations=100,bonferroni=None):
def __init__(self,interval,reads,shoulder_sizes=list(range(35,36)), footprint_sizes = list(range(11,26,2)),FDR_cutoff=0.01,FDR_iterations=100,bonferroni=None):

#Set up the model parameters
self.shoulder_sizes = shoulder_sizes
Expand Down Expand Up @@ -99,7 +84,7 @@ def footprints(self, withCutoff=-30, merge = 1):
while templogProb.min() < withCutoff:
minimapos = templogProb.argmin()
minimafplen = tempMLE[minimapos]
minimaphalffplen = int(minimafplen)/2
minimaphalffplen = int(minimafplen/2)
lbound = max(minimapos-(minimaphalffplen),0)
rbound = min(minimapos+(minimaphalffplen),len(templogProb))
ranges.append((lbound,rbound,templogProb.min(),minimafplen))
Expand Down
21 changes: 2 additions & 19 deletions pyDNase/scripts/dnase_average_profile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import pyDNase
import numpy as np
Expand Down Expand Up @@ -72,8 +55,8 @@
rv.append(reads[each]["-"])

if args.n:
fw = [map(float,i)for i in fw]
rv = [map(float,i) for i in rv]
fw = [list(map(float,i))for i in fw]
rv = [list(map(float,i)) for i in rv]
fw = [np.divide(np.subtract(i, min(i)), np.subtract(max(i) , min(i))) for i in fw]
rv = [np.divide(np.subtract(i, min(i)), np.subtract(max(i) , min(i))) for i in rv]

Expand Down
29 changes: 6 additions & 23 deletions pyDNase/scripts/dnase_bias_estimator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os, argparse, tempfile, operator, pickle
from collections import defaultdict
import pybedtools, pysam
Expand Down Expand Up @@ -55,7 +38,7 @@ def generate_6mer_bed(bam_file, gdict):
# Ignore unmapped reads
if not i.is_unmapped:
chrom = samfile.getrname(i.reference_id)
if chrom in gdict.keys():
if chrom in list(gdict.keys()):
# Determine which end of the read is the 5' end
if i.is_reverse:
strand = "-"
Expand All @@ -64,7 +47,7 @@ def generate_6mer_bed(bam_file, gdict):
strand = "+"
startbp, endbp = i.reference_start - 3, i.reference_start + 3
if startbp > 0 and endbp < gdict[chrom]:
print >> outfile, "\t".join((str(i) for i in (chrom, startbp, endbp, 0, 0, strand)))
print("\t".join((str(i) for i in (chrom, startbp, endbp, 0, 0, strand))), file=outfile)
outfile.close()
return outfile.name

Expand Down Expand Up @@ -126,16 +109,16 @@ def genome_dic(g_file):
expected = get_kmers(shuffled_cuts.seqfn)

print("Calculating...")
enriched = {i:observed[i]/float(expected[i]) for i in observed.keys()}
enriched = {i:observed[i]/float(expected[i]) for i in list(observed.keys())}

print("Dumping bias txt file...")
with open(outfile + ".txt", 'w') as ofile:
for i in sorted(enriched.items(), key=operator.itemgetter(1)):
print >> ofile, "\t".join(map(str,i))
for i in sorted(list(enriched.items()), key=operator.itemgetter(1)):
print("\t".join(map(str,i)), file=ofile)

print("Writing bias pickle file...")
totalsum = float(sum(enriched.values()))
whatdic = {key:{'forward':val/totalsum,'reverse':enriched[rev_comp(key)]/totalsum} for key,val in enriched.iteritems()}
whatdic = {key:{'forward':val/totalsum,'reverse':enriched[rev_comp(key)]/totalsum} for key,val in enriched.items()}
with open(outfile + ".pickle", "w") as bias_file:
pickle.dump(whatdic,bias_file)

Expand Down
21 changes: 2 additions & 19 deletions pyDNase/scripts/dnase_cut_counter.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import pyDNase
from clint.textui import progress, puts
Expand All @@ -32,5 +15,5 @@

puts("Writing output...")
for i in progress.bar(regions):
i.score = sum([sum(j) for j in reads[i].values()])
print >> ofile, i
i.score = sum([sum(j) for j in list(reads[i].values())])
print(i, file=ofile)
27 changes: 5 additions & 22 deletions pyDNase/scripts/dnase_ddhs_scorer.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import pyDNase
import math
Expand Down Expand Up @@ -44,12 +27,12 @@

puts("Calculating enrichment for Treatment")
for i in progress.bar(treat_dhs):
treat_total_cuts += sum([sum(j) for j in reads_treat[i].values()])
treat_total_cuts += sum([sum(j) for j in list(reads_treat[i].values())])
treat_base_pairs += len(i)

puts("Calculating enrichment for Control")
for i in progress.bar(control_dhs):
control_total_cuts += sum([sum(j) for j in reads_control[i].values()])
control_total_cuts += sum([sum(j) for j in list(reads_control[i].values())])
control_base_pairs += len(i)

treat_base_pairs = float(treat_base_pairs)
Expand All @@ -61,10 +44,10 @@

puts("Calculating dDHS scores...")
for i in progress.bar(regions):
treat_cuts = sum([sum(j) for j in reads_treat[i].values()])
control_cuts = sum([sum(j) for j in reads_control[i].values()])
treat_cuts = sum([sum(j) for j in list(reads_treat[i].values())])
control_cuts = sum([sum(j) for j in list(reads_control[i].values())])
LHS = math.sqrt( treat_cuts /( treat_total_cuts / treat_base_pairs))
RHS = math.sqrt(control_cuts /(control_total_cuts / control_base_pairs))
i.score = LHS - RHS
print >> ofile, i
print(i, file=ofile)
ofile.close()
19 changes: 1 addition & 18 deletions pyDNase/scripts/dnase_fos_scorer.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import pyDNase
from clint.textui import progress
Expand All @@ -32,4 +15,4 @@
outfile = open(args.output,"w")
for i in progress.bar(regions):
i.score = reads.FOS(i)
print >> outfile, i
print(i, file=outfile)
4 changes: 2 additions & 2 deletions pyDNase/scripts/dnase_pretty_picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
rv.append(reads[each]["-"])


fw = [map(float,i) for i in fw]
rv = [map(float,i) for i in rv]
fw = [list(map(float,i)) for i in fw]
rv = [list(map(float,i)) for i in rv]
fw = [np.divide(np.subtract(i, min(i)), np.subtract(max(i) , min(i))) for i in fw]
rv = [np.divide(np.subtract(i, min(i)), np.subtract(max(i) , min(i))) for i in rv]

Expand Down
17 changes: 0 additions & 17 deletions pyDNase/scripts/dnase_to_JSON.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse, pyDNase
from clint.textui import puts, progress
parser = argparse.ArgumentParser(description='Writes a JSON file of DNase I cuts for regions from a BED file')
Expand Down
17 changes: 0 additions & 17 deletions pyDNase/scripts/dnase_to_javatreeview.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/usr/bin/env python

# Copyright (C) 2016 Jason Piper - j.piper@me.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse, pyDNase, csv, random
import numpy as np
from clint.textui import puts, progress
Expand Down
Loading

0 comments on commit 1e3e24f

Please sign in to comment.