Skip to content

Commit

Permalink
+ Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyewer committed Feb 6, 2017
1 parent d0f185e commit 503d8cf
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 564 deletions.
19 changes: 0 additions & 19 deletions functions/junctionf_gui.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import os
import sys
import time
import struct
import cPickle
import subprocess
from PyQt4 import QtCore
from sys import platform as _platform
from collections import Counter

import libraries.joblib.parallel as Parallel
import functions.process as process
import functions.spinbar as spinbar
import functions.structures as sts

def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print '>>> Function %r finished %2.2f sec' % (method.__name__.upper().replace("_", " "), te-ts)
sys.stdout.flush()
return result
return timed

class junctionf():
def __init__(self, f, p):
self.fileio = f
Expand Down Expand Up @@ -59,7 +46,6 @@ def _get_unprocessed_files(self, list, suffix1, processed_list, suffix2):
break
return list

@timeit
def junction_search(self, directory, junction_folder, input_data_folder, blast_results_folder,
blast_results_query, junction_sequence, exclusion_sequence):
# junction_sequence = self._getjunction(">junctionseq")
Expand Down Expand Up @@ -92,7 +78,6 @@ def _multi_convert(self, directory, infolder, outfolder, blast_results_query):
self.fileio.make_FASTA(os.path.join(directory, infolder, f),
os.path.join(directory, outfolder, f[:-4] + ".fa"))

@timeit
def blast_search(self, directory, db_name, blast_results_folder):
platform_specific_path = 'osx'
suffix = ''
Expand Down Expand Up @@ -126,14 +111,10 @@ def blast_search(self, directory, db_name, blast_results_folder):
# blast_command = " ".join(blast_command_list)
print ">>> Running BLAST search for file: " + file_name
sys.stdout.flush()
self._spin = spinbar.SpinCursor(msg="Please wait for BLAST to finish...", speed=2)
self._spin.start()
# os.system(blast_command)
self.blast_pipe = subprocess.Popen(blast_command_list, shell=False)
self.blast_pipe.wait()
self._spin.stop()

@timeit
def generate_tabulated_blast_results(self, directory, blast_results_folder, blast_results_query_folder, gene_list_file):
blast_list = self.fileio.get_file_list(directory, blast_results_folder, ".txt")
processed_file_list = self.fileio.get_file_list(directory, blast_results_query_folder, ".bqa")
Expand Down
2 changes: 1 addition & 1 deletion functions/printio_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_text_block_as_array(self, tag):

def print_progress(self, infile, x, y, z, a):
if a == 1:
sys.stdout.write('>>> Processing {}:'.format(infile))
sys.stdout.write('>>> Processing {}:\n'.format(infile))
sys.stdout.flush()
if a == 2:
sys.stdout.write('>>> Counting. {} sequences with blast hits in file: {}'.format(x, infile))
Expand Down
32 changes: 8 additions & 24 deletions gene_count_gui.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
import re
import sys
import glob
import time
import cPickle as pickle
import libraries.joblib.parallel as Parallel

# Custom Functions
import functions.fileio_gui as f
import functions.printio_gui as p
import functions.spinbar as spinbar

input_folder = 'mapped_sam_files'
# Creates the folder that will hold the Genecounts summaries
Expand All @@ -27,17 +25,6 @@
input_folder = 'sam_files'


def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
sys.stdout.write('>>> Function %r finished %2.2f sec' % (method.__name__, te-ts))
sys.stdout.flush()
return result
return timed


def get_dictionary(fileName):
dictionary = pickle.load(open(fileName, 'rb'))
return dictionary
Expand Down Expand Up @@ -97,12 +84,14 @@ def query(chromosome, geneName, Dict, totalReads, output_file, summary_file):
for exonTuple in Dict[chromosome]:
if exonTuple[4] == geneName:
counts = Dict[chromosome][exonTuple]
PPM = counts * float(1000000) / totalReads
PPM = 0
if totalReads > 0:
PPM = counts * float(1000000) / totalReads
RPKM = PPM * float(1000) / (exonTuple[1] - exonTuple[0])
output_file.write("\n" + str(exonTuple) + " Counts:" + str(counts) + " PPM:" + str(PPM) + " RPKM:" + str(RPKM))
Ctotal += counts
Ptotal += PPM
length += (exonTuple[1] - exonTuple[0])
length += exonTuple[1] - exonTuple[0]
accession = exonTuple[5]
Rtotal = Ptotal * float(1000) / length
output_file.write("\n" + "TOTALS" + "\n" + "Counts:" + str(Ctotal) + " PPM:" + str(Ptotal) + " RPKM:" + str(Rtotal) + " Length:" + str(length) + "\n")
Expand Down Expand Up @@ -131,7 +120,7 @@ def write_all_to_file(directory, Dictionary, totalReads, totalReads2, f, sumfold


def letsCount(directory, summary_folder, chromosomes_folder, input_folder, chromosomes_list, filename):
sys.stdout.write(">>> Started processing file %s" % filename)
sys.stdout.write(">>> Started processing file %s\n" % filename)
sys.stdout.flush()
exonDict = get_dictionary(os.path.join('dictionaries', gene_dictionary))
infile = os.path.join(directory, input_folder, filename)
Expand All @@ -142,7 +131,7 @@ def letsCount(directory, summary_folder, chromosomes_folder, input_folder, chrom
# else:
# bin_folder = os.path.join(directory, input_folder, filename[:-4])
(readDict, totalReads) = make_read_dictionary(infile, chromosomes_list, gene_count_bin_folder, exonDict)
sys.stdout.write(">>> %d Total Reads (%s)" % (totalReads, filename))
sys.stdout.write(">>> %d Total Reads (%s)\n" % (totalReads, filename))
sys.stdout.flush()
totalReads2 = 0
exon_index = 0
Expand All @@ -160,25 +149,20 @@ def letsCount(directory, summary_folder, chromosomes_folder, input_folder, chrom
elif read > exon[1]:
exon_index += 1
# exonList.remove(exon)
sys.stdout.write('>>> Finished Chromosome %s%s for File (%s)' % (chrom[:20], '' if len(chrom) <= 20 else '...',
sys.stdout.write('>>> Finished Chromosome %s%s for File (%s)\n' % (chrom[:20], '' if len(chrom) <= 20 else '...',
filename))
sys.stdout.flush()
time.sleep(1)
sys.stdout.write('>>> Creating files and cleaning up... ( %s )' % filename)
sys.stdout.write('>>> Creating files and cleaning up... ( %s )\n' % filename)
sys.stdout.flush()
write_all_to_file(directory, exonDict, totalReads, totalReads2, filename, summary_folder, chromosomes_folder)

@timeit
def gene_count(directory, summary_folder, chromosomes_folder, input_folder, chromosomes_list, sam_file_list):
num_cores = Parallel.cpu_count()
print ">>> Using %d Processor Cores" % (num_cores - 1)
_spin = spinbar.SpinCursor(msg="Processing mapped .sam files ...", speed=2)
_spin.start()
Parallel.Parallel(n_jobs=num_cores-1)(Parallel.delayed(letsCount)(directory, summary_folder, chromosomes_folder,
input_folder, chromosomes_list, f) for f in
sam_file_list)
_spin.stop()


def initialize_folders(directory):
# Creates the folder that will hold the Genecounts summaries
Expand Down
2 changes: 1 addition & 1 deletion setup_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def find_data_files(sources, targets, patterns):
}
DATA_FILES = find_data_files(['ui', '', 'statistics', 'libraries', ''],
['ui', 'lib/python2.7', 'statistics', 'libraries', ''],
['Stat_Maker.ui', 'DragDropListView.py', '*.pkg', '*.py', 'install_deepn.sh'])
['Stat_Maker.ui', 'DragDropListView.py', '*.pkg', '*.py', '*.sh'])

if sys.platform == 'darwin':
setup(
Expand Down
12 changes: 7 additions & 5 deletions stat_maker_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,15 @@ def on_verify_installation_btn_clicked(self): ##################### new defin
subprocess.Popen(['bash install_deepn.sh ' + self.r_path], shell=True)
while not self.check_deepn_installed():
time.sleep(0.5)
else:
self.statusbar.showMessage("Updating DEEPN...")
subprocess.Popen(['bash update_deepn.sh ' + self.r_path], shell=True)

self.set_interaction_state(True)
self.run_btn.setEnabled(False)
self.verify_installation_btn.setEnabled(False)
self.verify_installation_btn.setText("Installations are Correct")
self.statusbar.showMessage("R, JAGS, and DEEPN Installation is Correct")
self.statusbar.showMessage("R, JAGS, and DEEPN Installations is Correct")

def which(self, program):
try:
Expand Down Expand Up @@ -308,9 +311,8 @@ def bait2_nonsel_fileDropped_2(self, path):
self.fileDropped(self.bait2_nonsel_list_2, path, "Bait2_Non-Selected_2")

def write_four_columns_from_csv(self, csv_file):

filehandle = open(csv_file, 'r')
outhandle = open(csv_file[:-4] + "_temp.csv", 'w')
outhandle = open(csv_file.replace("_summary.csv", "_stats.csv"), 'w')
count = 0
for line in filehandle.readlines():
if count > 3:
Expand All @@ -322,9 +324,9 @@ def write_four_columns_from_csv(self, csv_file):

def write_r_input(self):
output = open(os.path.join(self.directory, 'r_input.params'), 'w')
for key in self.data.keys():
for key in sorted(self.data.keys()):
self.write_four_columns_from_csv(self.data[key])
output.write("%-25s = %s_temp.csv\n" % (key, self.data[key][:-4]))
output.write("%-25s = %s\n" % (key, self.data[key].replace("_summary.csv", "_stats.csv")))
output.write("%-25s = %d\n" % ("Threshold", self.threshold_sbx.value()))
# output.write("%-25s = %s\n" % ("R Path", self.r_path))
# output.write("%-25s = %s" % ("JAGS Path", self.jags_path))
Expand Down
Loading

0 comments on commit 503d8cf

Please sign in to comment.