diff --git a/jcvi/graphics/landscape.py b/jcvi/graphics/landscape.py index bed4567e..0b9f34cf 100644 --- a/jcvi/graphics/landscape.py +++ b/jcvi/graphics/landscape.py @@ -1062,6 +1062,10 @@ def stackarray(binfile: BinFile, chr: str, window: int, shift: int): n = np.array(n, dtype=float) w = window // shift + nw = m.shape[0] + if nw < w: + logger.info("%s length < window, using %d bins instead of %d", chr, nw, w) + w = nw m = moving_sum(m, window=w) n = moving_sum(n, window=w) m /= n @@ -1215,6 +1219,7 @@ def stack(args): pf = fastafile.rsplit(".", 1)[0] image_name = pf + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts) + return image_name if __name__ == "__main__": diff --git a/tests/graphics/data/TAIR10_organelles.fas.gz b/tests/graphics/data/TAIR10_organelles.fas.gz new file mode 100644 index 00000000..4bf01a37 Binary files /dev/null and b/tests/graphics/data/TAIR10_organelles.fas.gz differ diff --git a/tests/graphics/data/exons.bed b/tests/graphics/data/exons.bed new file mode 100644 index 00000000..d80a044c --- /dev/null +++ b/tests/graphics/data/exons.bed @@ -0,0 +1,321 @@ +ChrC 3 76 exon_588928 0 - +ChrC 382 1444 exon_588933 0 - +ChrC 1716 1751 exon_588937 0 - +ChrC 2055 3636 exon_588942 0 - +ChrC 4310 4347 exon_588936 0 - +ChrC 5083 5283 exon_588949 0 - +ChrC 6148 6188 exon_588947 0 - +ChrC 6615 6687 exon_588952 0 - +ChrC 7016 7202 exon_588961 0 + +ChrC 7582 7693 exon_588966 0 + +ChrC 7784 7872 exon_588970 0 + +ChrC 8645 8668 exon_588973 0 + +ChrC 9382 9431 exon_588974 0 + +ChrC 9589 9661 exon_588977 0 + +ChrC 9937 11461 exon_588982 0 - +ChrC 11528 11938 exon_588989 0 - +ChrC 12653 12798 exon_588987 0 - +ChrC 13261 13507 exon_588994 0 - +ChrC 14020 14770 exon_588999 0 - +ChrC 15012 15723 exon_589004 0 - +ChrC 15937 20068 exon_589009 0 - +ChrC 20250 21861 exon_589016 0 - +ChrC 22652 23084 exon_589014 0 - +ChrC 23110 26329 exon_589021 0 - +ChrC 27372 27443 exon_589024 0 + +ChrC 28088 28178 exon_589028 0 + +ChrC 28706 28811 exon_589034 0 - +ChrC 29800 29874 exon_589037 0 - +ChrC 30322 30406 exon_589040 0 - +ChrC 30465 30538 exon_589043 0 - +ChrC 31368 31440 exon_589046 0 + +ChrC 32710 33772 exon_589050 0 + +ChrC 33719 35141 exon_589055 0 + +ChrC 35311 35403 exon_589059 0 + +ChrC 35750 35939 exon_589063 0 + +ChrC 36489 36560 exon_589067 0 + +ChrC 36703 36777 exon_589070 0 - +ChrC 36937 37240 exon_589075 0 - +ChrC 37374 39579 exon_589080 0 - +ChrC 39604 41857 exon_589085 0 - +ChrC 42583 42736 exon_589092 0 - +ChrC 43523 43751 exon_589090 0 - +ChrC 44826 44913 exon_589095 0 + +ChrC 45222 45828 exon_589100 0 - +ChrC 46212 46285 exon_589103 0 - +ChrC 46893 46928 exon_589106 0 + +ChrC 47440 47490 exon_589107 0 + +ChrC 48174 48247 exon_589110 0 + +ChrC 48676 49153 exon_589115 0 - +ChrC 49256 49934 exon_589120 0 - +ChrC 50000 50363 exon_589125 0 - +ChrC 51198 51233 exon_589129 0 - +ChrC 51832 51871 exon_589128 0 - +ChrC 52055 52128 exon_589132 0 + +ChrC 52264 52663 exon_589137 0 - +ChrC 52659 54156 exon_589142 0 - +ChrC 54957 56397 exon_589146 0 + +ChrC 57074 58541 exon_589151 0 + +ChrC 59246 59360 exon_589156 0 + +ChrC 59771 60326 exon_589161 0 + +ChrC 60740 61430 exon_589166 0 + +ChrC 61656 62619 exon_589171 0 + +ChrC 63537 63660 exon_589177 0 - +ChrC 63803 63920 exon_589182 0 - +ChrC 63941 64061 exon_589187 0 - +ChrC 64070 64322 exon_589192 0 - +ChrC 65711 65807 exon_589196 0 + +ChrC 65997 66111 exon_589201 0 + +ChrC 66228 66302 exon_589205 0 - +ChrC 66489 66563 exon_589208 0 - +ChrC 66928 67063 exon_589212 0 + +ChrC 67487 67688 exon_589217 0 + +ChrC 67916 68222 exon_589222 0 + +ChrC 68511 68865 exon_589228 0 - +ChrC 69610 69724 exon_588957 0 - +ChrC 69909 70137 exon_589237 0 - +ChrC 70652 70944 exon_589235 0 - +ChrC 71811 71882 exon_589233 0 - +ChrC 72370 73897 exon_589241 0 + +ChrC 74081 74183 exon_589246 0 + +ChrC 74248 74380 exon_589252 0 - +ChrC 74484 74706 exon_589256 0 + +ChrC 74840 74846 exon_589261 0 + +ChrC 75650 76292 exon_589263 0 + +ChrC 76480 76488 exon_589268 0 + +ChrC 77197 77672 exon_589270 0 + +ChrC 77900 78890 exon_589276 0 - +ChrC 78959 79376 exon_589281 0 - +ChrC 79488 79602 exon_589286 0 - +ChrC 80067 80472 exon_589291 0 - +ChrC 80695 81064 exon_589296 0 - +ChrC 81188 81587 exon_589303 0 - +ChrC 82643 82652 exon_589301 0 - +ChrC 82825 83482 exon_589308 0 - +ChrC 83466 83949 exon_589313 0 - +ChrC 84004 84283 exon_589318 0 - +ChrC 84336 84771 exon_589325 0 - +ChrC 85453 85843 exon_589323 0 - +ChrC 85861 86143 exon_589330 0 - +ChrC 86311 86385 exon_589333 0 - +ChrC 86473 93358 exon_589337 0 + +ChrC 93494 93728 exon_589342 0 + +ChrC 94275 94356 exon_589346 0 - +ChrC 94940 95702 exon_589353 0 - +ChrC 96387 96795 exon_589351 0 - +ChrC 97477 97945 exon_589358 0 - +ChrC 97998 98024 exon_589365 0 - +ChrC 98561 98793 exon_589363 0 - +ChrC 100708 100780 exon_589368 0 + +ChrC 101011 102502 exon_589371 0 + +ChrC 102800 102837 exon_589374 0 + +ChrC 103566 103601 exon_589375 0 + +ChrC 103664 103702 exon_589378 0 + +ChrC 104503 104538 exon_589379 0 + +ChrC 104690 107500 exon_589382 0 + +ChrC 107598 107701 exon_589385 0 + +ChrC 107948 108069 exon_589388 0 + +ChrC 108301 108375 exon_589391 0 + +ChrC 109012 109084 exon_589394 0 - +ChrC 109404 110436 exon_589398 0 + +ChrC 110397 112638 exon_589404 0 - +ChrC 113448 113607 exon_589408 0 + +ChrC 114269 114349 exon_589412 0 + +ChrC 114460 115447 exon_589416 0 + +ChrC 115664 117185 exon_589422 0 - +ChrC 117317 117563 exon_589427 0 - +ChrC 117803 118109 exon_589432 0 - +ChrC 118376 118907 exon_589437 0 - +ChrC 119243 119762 exon_589442 0 - +ChrC 119846 120376 exon_589449 0 - +ChrC 121456 122009 exon_589447 0 - +ChrC 122010 123192 exon_589454 0 - +ChrC 123295 123562 exon_589459 0 - +ChrC 123883 129244 exon_589464 0 - +ChrC 129564 129636 exon_589467 0 + +ChrC 130273 130347 exon_589470 0 - +ChrC 130579 130700 exon_589473 0 - +ChrC 130947 131050 exon_589476 0 - +ChrC 131148 133958 exon_589479 0 - +ChrC 134110 134145 exon_589483 0 - +ChrC 134946 134984 exon_589482 0 - +ChrC 135047 135082 exon_589487 0 - +ChrC 135811 135848 exon_589486 0 - +ChrC 136146 137637 exon_589490 0 - +ChrC 137868 137940 exon_589493 0 - +ChrC 139855 140087 exon_589497 0 + +ChrC 140624 140650 exon_589499 0 + +ChrC 140703 141171 exon_589504 0 + +ChrC 141853 142261 exon_589509 0 + +ChrC 142946 143708 exon_589511 0 + +ChrC 144292 144373 exon_589515 0 + +ChrC 144920 145154 exon_589520 0 - +ChrC 145290 152175 exon_589525 0 - +ChrC 152263 152337 exon_589528 0 + +ChrC 152505 152787 exon_589532 0 + +ChrC 152805 153195 exon_589537 0 + +ChrC 153877 154312 exon_589539 0 + +ChrM 272 734 exon_589546 0 - +ChrM 8847 11415 exon_589549 0 - +ChrM 11917 12241 exon_589553 0 + +ChrM 16843 17791 exon_589559 0 - +ChrM 16855 17251 exon_589563 0 + +ChrM 20570 20717 exon_589571 0 - +ChrM 21691 22086 exon_589569 0 - +ChrM 23662 24235 exon_589576 0 - +ChrM 25075 25615 exon_589581 0 - +ChrM 25481 27077 exon_589588 0 - +ChrM 28658 28733 exon_589586 0 - +ChrM 28897 28970 exon_589591 0 - +ChrM 30462 31083 exon_589595 0 + +ChrM 32040 32472 exon_589601 0 - +ChrM 34189 34555 exon_589605 0 + +ChrM 34598 35102 exon_589610 0 + +ChrM 35781 36132 exon_589615 0 + +ChrM 40501 40585 exon_589623 0 - +ChrM 41929 42628 exon_589621 0 - +ChrM 48112 48532 exon_589627 0 + +ChrM 51292 51871 exon_589635 0 - +ChrM 52831 53611 exon_589633 0 - +ChrM 53735 53809 exon_589638 0 - +ChrM 55766 56090 exon_589643 0 - +ChrM 57773 58331 exon_589647 0 + +ChrM 60234 61416 exon_589652 0 + +ChrM 62348 62433 exon_589656 0 + +ChrM 68917 69253 exon_589661 0 - +ChrM 71452 71526 exon_589664 0 + +ChrM 76131 76437 exon_589668 0 + +ChrM 76641 77259 exon_589674 0 - +ChrM 77818 78151 exon_589679 0 - +ChrM 79739 80132 exon_589686 0 - +ChrM 81112 81297 exon_589684 0 - +ChrM 82027 83116 exon_589691 0 - +ChrM 89616 90054 exon_589696 0 - +ChrM 90882 91347 exon_589701 0 - +ChrM 91000 91384 exon_589705 0 + +ChrM 103826 103914 exon_589709 0 + +ChrM 104220 104295 exon_589712 0 + +ChrM 104456 104531 exon_589715 0 + +ChrM 104884 104995 exon_589718 0 + +ChrM 104953 105553 exon_589723 0 - +ChrM 105886 105948 exon_589726 0 + +ChrM 106796 106879 exon_589729 0 + +ChrM 110929 111403 exon_589734 0 - +ChrM 111586 112907 exon_589738 0 + +ChrM 112952 113039 exon_589743 0 + +ChrM 115430 115751 exon_589747 0 + +ChrM 116295 116754 exon_589752 0 + +ChrM 119380 119701 exon_589758 0 - +ChrM 127020 127094 exon_589761 0 - +ChrM 127474 127843 exon_589766 0 - +ChrM 129908 130385 exon_589770 0 + +ChrM 130816 131140 exon_589775 0 + +ChrM 130967 131393 exon_589780 0 + +ChrM 132070 132213 exon_589785 0 + +ChrM 133176 133245 exon_589787 0 + +ChrM 134308 134775 exon_589789 0 + +ChrM 135828 136072 exon_589791 0 + +ChrM 137891 138153 exon_589793 0 + +ChrM 140723 141939 exon_589801 0 - +ChrM 142768 142998 exon_589799 0 - +ChrM 143218 143477 exon_589808 0 - +ChrM 144293 146312 exon_589813 0 - +ChrM 146989 147048 exon_589806 0 - +ChrM 147281 147611 exon_589818 0 - +ChrM 150782 151151 exon_589822 0 + +ChrM 151264 151747 exon_589828 0 - +ChrM 154743 155660 exon_589832 0 + +ChrM 157212 157345 exon_589834 0 + +ChrM 157490 158351 exon_589839 0 + +ChrM 161692 162153 exon_589844 0 + +ChrM 163624 164139 exon_589846 0 + +ChrM 167220 167642 exon_589848 0 + +ChrM 169584 169674 exon_589850 0 + +ChrM 169795 170737 exon_589855 0 + +ChrM 174204 174525 exon_589860 0 + +ChrM 176541 177027 exon_589866 0 - +ChrM 182277 182697 exon_589870 0 + +ChrM 183110 183443 exon_589875 0 + +ChrM 188083 188662 exon_589881 0 - +ChrM 188928 189231 exon_589886 0 - +ChrM 190103 190553 exon_589891 0 - +ChrM 190739 190761 exon_589896 0 - +ChrM 191054 191882 exon_589901 0 - +ChrM 201728 202097 exon_589905 0 + +ChrM 203587 204310 exon_589911 0 - +ChrM 204339 204412 exon_589914 0 - +ChrM 207552 207915 exon_589919 0 - +ChrM 209498 209822 exon_589923 0 + +ChrM 217630 219077 exon_589928 0 + +ChrM 220470 220773 exon_589935 0 - +ChrM 220829 221189 exon_589939 0 + +ChrM 221699 222029 exon_589945 0 - +ChrM 222686 222989 exon_589950 0 - +ChrM 227108 227196 exon_589953 0 + +ChrM 227501 227577 exon_589956 0 + +ChrM 227614 227686 exon_589959 0 + +ChrM 227708 228431 exon_589964 0 - +ChrM 228572 229085 exon_589969 0 - +ChrM 231893 233042 exon_589974 0 - +ChrM 234537 234903 exon_589979 0 - +ChrM 235337 235661 exon_589983 0 + +ChrM 235915 236392 exon_589988 0 + +ChrM 236926 237481 exon_589994 0 - +ChrM 237052 237616 exon_589998 0 + +ChrM 239635 239956 exon_590004 0 - +ChrM 239987 240758 exon_590009 0 - +ChrM 241305 241953 exon_590014 0 - +ChrM 249271 249919 exon_590019 0 - +ChrM 250079 250153 exon_590022 0 - +ChrM 251402 251897 exon_590027 0 - +ChrM 254504 254571 exon_590030 0 - +ChrM 256864 257476 exon_590035 0 - +ChrM 258044 258398 exon_590040 0 - +ChrM 260223 260601 exon_590045 0 - +ChrM 260646 261006 exon_590050 0 - +ChrM 260962 261307 exon_590055 0 - +ChrM 261104 261461 exon_590060 0 - +ChrM 261616 262078 exon_590065 0 - +ChrM 264112 264433 exon_590070 0 - +ChrM 270237 270561 exon_590075 0 - +ChrM 272943 273423 exon_590080 0 - +ChrM 274898 275222 exon_590084 0 + +ChrM 275102 275176 exon_590088 0 + +ChrM 278648 279152 exon_590092 0 + +ChrM 279462 280251 exon_590098 0 + +ChrM 281613 281931 exon_590103 0 + +ChrM 283033 283789 exon_590109 0 - +ChrM 287916 288108 exon_590116 0 - +ChrM 289002 289083 exon_590114 0 - +ChrM 289196 289517 exon_590121 0 - +ChrM 292972 293431 exon_590126 0 - +ChrM 293975 294296 exon_590131 0 - +ChrM 296687 296784 exon_590134 0 - +ChrM 296819 298204 exon_590140 0 - +ChrM 300965 301301 exon_590145 0 - +ChrM 302165 303689 exon_590150 0 - +ChrM 303835 304720 exon_590155 0 - +ChrM 304778 305084 exon_590160 0 - +ChrM 305220 305562 exon_590165 0 - +ChrM 308931 309369 exon_590169 0 + +ChrM 309337 309640 exon_590175 0 - +ChrM 310513 310882 exon_590179 0 + +ChrM 312544 313162 exon_590185 0 - +ChrM 314626 315073 exon_590189 0 + +ChrM 318003 318390 exon_590195 0 - +ChrM 318587 319463 exon_590200 0 - +ChrM 324258 324594 exon_590204 0 + +ChrM 325299 325710 exon_590209 0 + +ChrM 326098 326509 exon_590214 0 + +ChrM 327889 328078 exon_590224 0 - +ChrM 329081 329465 exon_590229 0 - +ChrM 329734 330306 exon_590222 0 - +ChrM 332944 333105 exon_590220 0 - +ChrM 337668 337741 exon_590232 0 + +ChrM 346756 347194 exon_590236 0 + +ChrM 349829 351413 exon_590242 0 - +ChrM 360716 361052 exon_590247 0 - +ChrM 361061 361179 exon_590250 0 - +ChrM 361349 363284 exon_590253 0 - +ChrM 363724 364042 exon_590257 0 + +ChrM 366085 366700 exon_590263 0 - diff --git a/tests/graphics/test_landscape.py b/tests/graphics/test_landscape.py new file mode 100644 index 00000000..ac537051 --- /dev/null +++ b/tests/graphics/test_landscape.py @@ -0,0 +1,16 @@ +import os +import os.path as op + +from jcvi.apps.base import cleanup +from jcvi.graphics.landscape import stack + + +def test_stack(): + cwd = os.getcwd() + os.chdir(op.join(op.dirname(__file__), "data")) + cleanup("TAIR10_organelles.fas.pdf") + image_name = stack( + ["TAIR10_organelles.fas.gz", "--stacks=exons", "--window=25000", "--shift=5000"] + ) + assert op.exists(image_name) + os.chdir(cwd)