Skip to content

Commit

Permalink
networkx fix, bugfix for BAM files with no reads, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvh committed Mar 10, 2016
1 parent 04605a2 commit f7838e2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions pita/annotationdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def splice_stats(self, exon1, exon2, identifier):
def nreads(self, identifier):
q = self.session.query(ReadSource)
q = q.filter(ReadSource.name == identifier)

return sum([s.nreads for s in q.all()])

def get_splice_count(self, e1, e2):
Expand Down
6 changes: 3 additions & 3 deletions pita/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from networkx.algorithms.components.connected import connected_components
import networkx as nx
from networkx.algorithms.connectivity import minimum_st_node_cut
from networkx.algorithms.flow import ford_fulkerson
from networkx.algorithms.flow import edmonds_karp
from itertools import izip, count
from gimmemotifs.genome_index import GenomeIndex

Expand Down Expand Up @@ -151,10 +151,10 @@ def get_connected_models(self):
def get_node_cuts(self, model):

node_cuts = []
cuts = list(minimum_st_node_cut(self.graph, model[0], model[-1], flow_func=ford_fulkerson))
cuts = list(minimum_st_node_cut(self.graph, model[0], model[-1], flow_func=edmonds_karp))
while len(cuts) == 1:
node_cuts = cuts + node_cuts
cuts = list(minimum_st_node_cut(self.graph, model[0], cuts[0], flow_func=ford_fulkerson))
cuts = list(minimum_st_node_cut(self.graph, model[0], cuts[0], flow_func=edmonds_karp))
return node_cuts

def get_best_variant(self, model, weight):
Expand Down
1 change: 1 addition & 0 deletions pita/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self):
""" fname: name of yaml configuration file
"""
self.logger = logging.getLogger("pita")

self.maxentpath = ""

def load(self, fname, reannotate=False):
Expand Down
2 changes: 1 addition & 1 deletion pita/db_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ReadSource(Base):
id = Column(Integer, primary_key=True)
name = Column(String(250))
source = Column(String(250))
nreads = Column(Integer)
nreads = Column(Integer, default=0)

class FeatureReadCount(Base):
__tablename__ = "read_count"
Expand Down
10 changes: 5 additions & 5 deletions pita/dbcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
from networkx.algorithms.components.connected import connected_components
import networkx as nx
from networkx.algorithms.connectivity import minimum_st_node_cut
from networkx.algorithms.flow import ford_fulkerson
from networkx.algorithms.flow import edmonds_karp
from itertools import izip, count
from gimmemotifs.genome_index import GenomeIndex
import random

def connected_models(graph):
for u, v in graph.edges():
graph[u][v]['weight'] = -1

for c in nx.weakly_connected_components(graph):
starts = [k for k,v in graph.in_degree(c).items() if v == 0]
ends = [k for k,v in graph.out_degree(c).items() if v == 0]
Expand Down Expand Up @@ -71,7 +70,8 @@ def __init__(self, db, chrom=None):

self.logger.debug("Loading introns in graph")
n = 0
for junction in self.db.get_splice_junctions(chrom, ev_count=1, read_count=20):
#for junction in self.db.get_splice_junctions(chrom, ev_count=1, read_count=20):
for junction in self.db.get_splice_junctions(chrom, ev_count=0, read_count=1):
#for junction in self.db.get_splice_junctions(chrom):
#print junction
n += 1
Expand Down Expand Up @@ -118,10 +118,10 @@ def get_connected_models(self):

def get_node_cuts(self, model):
node_cuts = []
cuts = list(minimum_st_node_cut(self.graph, model[0], model[-1], flow_func=ford_fulkerson))
cuts = list(minimum_st_node_cut(self.graph, model[0], model[-1], flow_func=edmonds_karp))
while len(cuts) == 1:
node_cuts = cuts + node_cuts
cuts = list(minimum_st_node_cut(self.graph, model[0], cuts[0], flow_func=ford_fulkerson))
cuts = list(minimum_st_node_cut(self.graph, model[0], cuts[0], flow_func=edmonds_karp))
return node_cuts

def get_best_variant(self, model, weight):
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools.command.test import test as TestCommand
import sys

VERSION = "1.72"
VERSION = "1.73"
DESCRIPTION = """
pita - pita improves transcript annotation
"""
Expand Down Expand Up @@ -43,12 +43,12 @@ def run_tests(self):
install_requires=[
"SQLAlchemy",
"gimmemotifs > 0.8.6",
"pysam < 0.8",
"pysam >= 0.9",
"pyyaml",
"HTSeq",
"bcbio-gff",
"biopython",
"networkx ==1.9",
"networkx >= 1.10",
"numpy",
],
cmdclass = {'test': PyTest},
Expand Down
4 changes: 4 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import os
import pytest
from pita.config import config

config.maxentpath = os.environ["MAXENT"]

@pytest.fixture
def three_exons():
Expand Down

0 comments on commit f7838e2

Please sign in to comment.