Skip to content

Commit

Permalink
Merge pull request #346 from CGATOxford/AH-CGATScriptsPy36
Browse files Browse the repository at this point in the history
py36 compatibility
  • Loading branch information
AndreasHeger authored Aug 21, 2017
2 parents 6acb3ee + 012f162 commit 0968e30
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 58 deletions.
13 changes: 7 additions & 6 deletions CGAT/scripts/_bam2bam.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ def filter_bam(AlignmentFile input_samfile,
raise ValueError("require another bam file for mismatch filtering" )

# L = 1 byte (unsigned char)
def _gen(): return array.array('B')
def _gen():
return array.array('B')

index = collections.defaultdict(_gen)

while ret > 0:
ret = bam_read1(hts_get_bgzfp(reference_samfile.htsfile),
b)
ret = bam_read1(
hts_get_bgzfp(reference_samfile.htsfile),
b)
if ret > 0:
# ignore unmapped reads
if b.core.flag & 4:
Expand All @@ -151,7 +154,6 @@ def filter_bam(AlignmentFile input_samfile,
else:
nm = 0
index[qname].append(nm)

E.info( "built index for %i reads" % len(index))
bam_destroy1(b)

Expand All @@ -167,8 +169,7 @@ def filter_bam(AlignmentFile input_samfile,
for read in input_samfile:

ninput += 1
# if ninput > 10000: break


# remove unmapped reads
if read._delegate.core.flag & 4:
if c_remove_unmapped:
Expand Down
25 changes: 18 additions & 7 deletions CGAT/scripts/bam2bam.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,11 @@ def main(argv=None):
bamfiles = []

if options.stdin != sys.stdin:
from_stdin = True
bamfiles.append(options.stdin.name)

else:
from_stdin = False

if options.inplace:
bamfiles.extend(args)
if len(bamfiles) == 0:
Expand All @@ -369,6 +372,8 @@ def main(argv=None):
if len(bamfiles) == 0:
bamfiles = ["-"]

to_stdout = False

for bamfile in bamfiles:

E.info('processing %s' % bamfile)
Expand All @@ -383,8 +388,8 @@ def main(argv=None):

# reading bam from stdin does not work with only the "r" tag
pysam_in = pysam.AlignmentFile(bamfile, "rb")

if bamfile == "-":
if bamfile == "-" or (from_stdin and bamfile == options.stdin.name):
to_stdout = True
if options.output_sam:
pysam_out = pysam.AlignmentFile("-", "wh", template=pysam_in)
else:
Expand All @@ -397,7 +402,8 @@ def main(argv=None):
tmpfile.close()

E.debug("writing temporary bam-file to %s" % tmpfile.name)
pysam_out = pysam.AlignmentFile(tmpfile.name, "wb",
pysam_out = pysam.AlignmentFile(tmpfile.name,
"wb",
template=pysam_in)

if "filter" in options.methods:
Expand Down Expand Up @@ -431,7 +437,12 @@ def main(argv=None):
remove_mismatches=remove_mismatches,
colour_mismatches=colour_mismatches)

options.stdlog.write("category\tcounts\n%s\n" % c.asTable())
if pysam_ref:
pysam_ref.close()

# do not write to stdlog in the middle of a SAM/BAM stdout stream.
if options.stdlog != options.stdout:
E.info("category\tcounts\n%s\n" % c.asTable())
else:

# set up the modifying iterators
Expand Down Expand Up @@ -610,8 +621,8 @@ def keep_first_base(i):
for read in it:
pysam_out.write(read)

pysam_in.close()
pysam_out.close()
pysam_in.close()
pysam_out.close()

if options.inplace:
# set date and file permissions according to original
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/scripts-nosetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
# bioinformatics tools
- ucsc-wigtobigwig
# python deps
- python=3.5
- python
- biopython
- cython
- alignlib-lite
Expand Down
4 changes: 2 additions & 2 deletions install-CGAT-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ if [[ $INSTALL_SCRIPTS ]] ; then
conda create -q -n ${CONDA_INSTALL_ENV} cgat-scripts --override-channels -c bioconda -c conda-forge -c defaults -y
else
# to-update once we merge to master:
# wget -O env.yml https://raw.githubusercontent.com/CGATOxford/cgat/conda/environments/${CONDA_INSTALL_TYPE}
wget -O env.yml https://raw.githubusercontent.com/CGATOxford/cgat/SLV-update-install/conda/environments/${CONDA_INSTALL_TYPE}
# wget -O env.yml https://raw.githubusercontent.com/CGATOxford/cgat/master/conda/environments/${CONDA_INSTALL_TYPE}
wget -O env.yml https://raw.githubusercontent.com/CGATOxford/cgat/${TRAVIS_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE}
conda env create -f env.yml
fi

Expand Down
54 changes: 27 additions & 27 deletions tests/counts2counts.py/counts_rowspikes_logfold.tsv
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
spike wt-N-1 wt-N-2 wt-N-3 wt-P-1 wt-P-2 wt-P-3
spike-in_6.5_2.5_0 96 98 144 889 758 519
spike-in_5.5_8.5_1 51 30 42 14505 16477 14570
spike-in_5.5_1.5_2 77 44 66 131 197 163
spike-in_7.5_4.5_3 186 172 218 3660 4986 4420
spike-in_5.5_6.5_4 51 40 47 6449 4275 3019
spike-in_7.5_1.5_5 56 60 332 372 306 244
spike-in_3.5_1.5_6 11 3 14 29 32 44
spike-in_9.5_4.5_7 873 733 934 39474 14358 11350
spike-in_5.5_7.5_8 40 34 35 10374 9391 7415
spike-in_0.5_6.5_9 2 1 0 107 184 186
spike-in_7.5_3.5_10 175 167 251 2595 2949 2272
spike-in_5.5_5.5_11 39 33 41 1334 1472 1256
spike-in_4.5_5.5_12 23 20 15 618 696 645
spike-in_6.5_6.5_13 109 83 95 7453 10100 8401
spike-in_6.5_1.5_14 98 90 67 204 292 224
spike-in_6.5_3.5_15 178 76 56 1193 1105 654
spike-in_5.5_2.5_16 48 73 61 278 317 248
spike-in_4.5_3.5_17 32 27 22 317 473 394
spike-in_9.5_3.5_18 744 701 791 6962 11651 9331
spike-in_6.5_0.5_19 147 91 123 150 191 160
spike-in_1.5_6.5_20 1 2 2 216 295 289
spike-in_0.5_6.5_0 2 1 0 107 184 186
spike-in_1.5_6.5_1 1 2 2 216 295 289
spike-in_2.5_3.5_2 7 6 7 107 133 77
spike-in_3.5_1.5_3 11 3 14 29 32 44
spike-in_3.5_2.5_4 12 9 12 56 78 74
spike-in_4.5_3.5_5 32 27 22 317 473 394
spike-in_4.5_5.5_6 23 20 15 618 696 645
spike-in_5.5_0.5_7 52 60 67 120 89 69
spike-in_5.5_1.5_8 77 44 66 131 197 163
spike-in_5.5_2.5_9 48 73 61 278 317 248
spike-in_5.5_5.5_10 39 33 41 1334 1472 1256
spike-in_5.5_6.5_11 51 40 47 6449 4275 3019
spike-in_5.5_7.5_12 40 34 35 10374 9391 7415
spike-in_5.5_8.5_13 51 30 42 14505 16477 14570
spike-in_6.5_0.5_14 147 91 123 150 191 160
spike-in_6.5_1.5_15 98 90 67 204 292 224
spike-in_6.5_2.5_16 96 98 144 889 758 519
spike-in_6.5_3.5_17 178 76 56 1193 1105 654
spike-in_6.5_4.5_18 128 104 125 3384 3387 2364
spike-in_6.5_6.5_19 109 83 95 7453 10100 8401
spike-in_7.5_1.5_20 56 60 332 372 306 244
spike-in_7.5_2.5_21 106 169 153 955 1209 848
spike-in_8.5_1.5_22 423 268 309 157 492 1499
spike-in_2.5_3.5_23 7 6 7 107 133 77
spike-in_5.5_0.5_24 52 60 67 120 89 69
spike-in_6.5_4.5_25 128 104 125 3384 3387 2364
spike-in_3.5_2.5_26 12 9 12 56 78 74
spike-in_8.5_4.5_27 398 300 330 7865 9033 8825
spike-in_7.5_3.5_22 175 167 251 2595 2949 2272
spike-in_7.5_4.5_23 186 172 218 3660 4986 4420
spike-in_8.5_1.5_24 423 268 309 157 492 1499
spike-in_8.5_4.5_25 398 300 330 7865 9033 8825
spike-in_9.5_3.5_26 744 701 791 6962 11651 9331
spike-in_9.5_4.5_27 873 733 934 39474 14358 11350
30 changes: 15 additions & 15 deletions tests/counts2counts.py/counts_rowspikes_relative.tsv
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
spike wt-N-1 wt-N-2 wt-N-3 wt-P-1 wt-P-2 wt-P-3
spike-in_65.0_250.0_0 48 73 61 278 317 248
spike-in_5.0_50.0_1 7 6 7 107 133 77
spike-in_15.0_50.0_2 12 9 12 56 78 74
spike-in_45.0_50.0_3 43 43 39 43 63 39
spike-in_65.0_150.0_4 77 44 66 131 197 163
spike-in_115.0_650.0_5 96 98 144 889 758 519
spike-in_105.0_850.0_6 178 76 56 1193 1105 654
spike-in_15.0_650.0_7 23 20 15 618 696 645
spike-in_85.0_150.0_8 98 90 67 204 292 224
spike-in_55.0_50.0_9 52 60 67 120 89 69
spike-in_145.0_850.0_10 106 169 153 955 1209 848
spike-in_5.0_250.0_11 1 2 2 216 295 289
spike-in_25.0_350.0_12 32 27 22 317 473 394
spike-in_5.0_150.0_13 2 1 0 107 184 186
spike-in_5.0_50.0_0 7 6 7 107 133 77
spike-in_5.0_150.0_1 2 1 0 107 184 186
spike-in_5.0_250.0_2 1 2 2 216 295 289
spike-in_15.0_50.0_3 12 9 12 56 78 74
spike-in_15.0_650.0_4 23 20 15 618 696 645
spike-in_25.0_350.0_5 32 27 22 317 473 394
spike-in_45.0_50.0_6 43 43 39 43 63 39
spike-in_45.0_150.0_7 11 35 81 134 191 180
spike-in_55.0_50.0_8 52 60 67 120 89 69
spike-in_65.0_150.0_9 77 44 66 131 197 163
spike-in_65.0_250.0_10 48 73 61 278 317 248
spike-in_85.0_150.0_11 98 90 67 204 292 224
spike-in_105.0_850.0_12 178 76 56 1193 1105 654
spike-in_115.0_650.0_13 96 98 144 889 758 519
spike-in_125.0_50.0_14 147 91 123 150 191 160
spike-in_145.0_150.0_15 56 60 332 372 306 244
spike-in_45.0_150.0_16 11 35 81 134 191 180
spike-in_145.0_850.0_16 106 169 153 955 1209 848

0 comments on commit 0968e30

Please sign in to comment.