Skip to content

Commit

Permalink
Merge pull request #4 from morrislab/py3
Browse files Browse the repository at this point in the history
Python 3 compatible
  • Loading branch information
kcha authored Sep 18, 2018
2 parents e824e69 + 8f2958d commit 2ab101c
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 86 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
install:
travis_retry python setup.py install
script:
travis_retry python setup.py test
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build Status](https://travis-ci.org/morrislab/rnascan.svg?branch=master)](https://travis-ci.org/morrislab/rnascan)
![Version](https://img.shields.io/badge/version-0.10.2-brightgreen.svg)
[![GitHub license](https://img.shields.io/github/license/morrislab/rnascan.svg)](https://github.com/morrislab/rnascan/blob/master/LICENSE)

# rnascan

rnascan is a (mostly) Python suite to scan RNA sequences and secondary structures with sequence and secondary structure PFMs. Secondary structure is represented as weights in different secondary structure contexts, similar to how a PFM represents weights of different nucleotides or amino acids. This allows representation and use of secondary structures in a way that is similar to how PFMs are used to scan nucleotide sequences, and also allows for some flexibility in the structure, as you might find in the boltzmann distribution of secondary structures.
Expand Down Expand Up @@ -44,7 +48,7 @@ g++ -o ~/bin/parse_secondary_structure scripts/parse_secondary_structure.cpp

### 4. Install `rnascan` Python components

This package was written for Python 2.7.x or later (_not compatible with Python 3 yet_). To install the package, run the following:
This package requires Python 2.7+ or Python 3.5+. To install the package, run the following:

```
python setup.py install
Expand Down Expand Up @@ -80,7 +84,7 @@ Here are some example commands using minimal options:

```
# To run a test sequence
rnascan -p pfm_seq.txt -s AGTTCCGGTCCGGCAGAGATCGCG > hits.tab
rnascan -p pfm_seq.txt -t AGTTCCGGTCCGGCAGAGATCGCG > hits.tab
# Sequence-only (use -p)
rnascan -p pfm_seq.txt sequences.fasta > hits.tab
Expand Down
9 changes: 5 additions & 4 deletions rnascan/BioAddons/motifs/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#



from Bio.motifs import matrix
from Bio.Alphabet import NucleotideAlphabet
import platform

class ExtendedPositionSpecificScoringMatrix(matrix.PositionSpecificScoringMatrix):

class ExtendedPositionSpecificScoringMatrix(
matrix.PositionSpecificScoringMatrix):
"""This new class inherits Bio.motifs.matrix.PositionSpecificScoringMatrix.
It has been modified to support any kind of Alphabet. This allows us to
perform motif scans on RNA sequence as well as RNA secondary structure.
Expand Down Expand Up @@ -45,6 +46,7 @@ def _py_calculate(self, sequence, m, n):
# Fall back to the slower Python implementation if Jython or IronPython.
try:
from . import _pwm

def _calculate(self, sequence, m, n):

# Only RNA and DNA is supported right now. If sequence is
Expand All @@ -54,7 +56,7 @@ def _calculate(self, sequence, m, n):

letters = ''.join(sorted(self.alphabet.letters))
logodds = [[self[letter][i] for letter in letters]
for i in range(m)]
for i in range(m)]
return self._pwm.calculate(sequence, logodds)
except ImportError:
if platform.python_implementation() == 'CPython':
Expand All @@ -63,7 +65,6 @@ def _calculate(self, sequence, m, n):
def _calculate(self, sequence, m, n):
return self._py_calculate(sequence, m, n)


def calculate(self, sequence):

# TODO - Force uppercase here and optimise switch statement in C
Expand Down
6 changes: 3 additions & 3 deletions rnascan/average_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq
from pfmutil import norm_pfm
from .pfmutil import norm_pfm
import subprocess
import numpy as np

Expand All @@ -44,7 +44,7 @@ def struct_pfm_from_aligned(sequences):
def get_structure_probability_matrix_for_sequence(id,seq,frag_length,overlap):
aligned_annotated_sequences = []

for i in xrange(-frag_length/2,len(seq)-frag_length/2,frag_length-overlap):
for i in range(-frag_length/2,len(seq)-frag_length/2,frag_length-overlap):
temphandle = tempfile.NamedTemporaryFile(delete=False,mode='r+b') # for centroid structure
temphandle2 = tempfile.NamedTemporaryFile(delete=False,mode='r+b') # for output of structure parser

Expand Down Expand Up @@ -108,7 +108,7 @@ def get_structure_probability_matrix_from_probabilities(id,seq,frag_length):

probabilities = {}

for alph,p in programs.iteritems():
for alph,p in programs.items():
args = [p] + plfold_args
plfold_proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None)
#plfold_output = plfold_proc.communicate(input_record.format("fasta"))[0]
Expand Down
6 changes: 3 additions & 3 deletions rnascan/pfmutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def read_pfm(pfmfile):
pfm = {}
with open(pfmfile) as f:
reader = csv.reader(f, delimiter='\t')
headerline = reader.next()
headerline = next(reader)
alphabet = headerline[1:]
for base in alphabet:
pfm[base] = []
Expand Down Expand Up @@ -244,9 +244,9 @@ def reduce_pfm_alphabet(pfm):

pfm = read_pfm(file)

print(format_pfm(pfm))
print((format_pfm(pfm)))

reduced_pfm = reduce_pfm_alphabet(pfm)

print(format_pfm(reduced_pfm))
print((format_pfm(reduced_pfm)))

Loading

0 comments on commit 2ab101c

Please sign in to comment.