diff --git a/Cargo.lock b/Cargo.lock index 5f17692..8bdb149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "anyhow" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" + [[package]] name = "assert_cmd" version = "1.0.2" @@ -753,6 +759,7 @@ dependencies = [ name = "subtract" version = "0.1.0" dependencies = [ + "anyhow", "assert_cmd", "clap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 39bfe7f..9a8809a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0.38" clap = "2.33.3" env_logger = "0.8.2" log = "0.4.14" diff --git a/data/bat2-LU__AAACCTGAGCCACGCT-s100.sig b/data/bat2-LU__AAACCTGAGCCACGCT-s100.sig new file mode 100644 index 0000000..d2da3b8 --- /dev/null +++ b/data/bat2-LU__AAACCTGAGCCACGCT-s100.sig @@ -0,0 +1 @@ +[{"class":"sourmash_signature","email":"","hash_function":"0.murmur64","filename":null,"name":"bat2-LU__AAACCTGAGCCACGCT","license":"CC0","signatures":[{"num":0,"ksize":42,"seed":42,"max_hash":184467440737095520,"mins":[166650139278972,386618876530547,491293889052531,623073431126123,630197283274915,674078048358738,740907096186591,842021086795186,926470043618465,961244914707697,995783001506612,1093538737607421,1096718888680575,1110157120305188,1112926687126208,1124855768304799,1313221564357224,1453634800810515,1673650448535053,1800969732293403,1811665572504430,1938229109709282,2114958507405470,2209036793167610,2342298763313237,2367116392396652,2407794781640150,2455156568287786,2465719265201604,2489234359275980,2661024098047086,2872822604013164,2931481027948937,3253150869989382,3274927814497469,3375998023110016,3437989740075590,3453469434016571,3513166741568680,3537227565626032,3841552885981586,3918953486998592,4107599944830051,4488852675201574,4652151193483921,4844473098508628,4971441408744196,5007898766909476,5043725148035227,5127905444814793,5142409997557178,5166702502951255,5253456690514576,5307260916932192,5616268213599113,5759471004417358,5806642506750160,5913920312932849,5965318233940326,6171060396818257,6196767888773760,6266444928655620,6284377291845504,6328774157369698,6458547701214884,6588141651239777,6628032319138902,6798768462063544,6805903997319799,6874032133604350,6880429910171469,6898186604634852,6970670643623184,7024859624177137,7247855577201131,7327625908905613,7362563402803013,7452540928118253,7672580952940267,7916405890952547,7923255831772813,7929701494032736,8127836363031336,8140533962506713,8214091795300801,8271431902501976,8343211354871737,8370104687646470,8395937861818595,8691903595434115,8731940940209019,8754746286500787,8819050860328845,8848731936385921,8959119371815747,9007772845968997,9076331317609610,9093232140856015,9244935695137378,9327315441458017,9402333244543685,9435627249696322,9453425236455231,9667557441727058,9704677246783213,9867290716103451,9936627960938550,10039240211053869,10177366125887444,10248235088478992,10486480593184618,10497734281033185,10636246005809579,10714886779034608,10721020389585773,10726856920835828,10843785205735919,10857142119755928,10982042133459135,10991103765223106,11163749995620574,11230140027048829,11628639711729073,11694512317014220,11697635070864147,11723257833988121,11730138568845156,11974607143905511,12002847699772553,12146431314092465,12348705327612271,12394883327611082,12408383228669803,12665603796498861,12948663014035835,13230988422041945,13238779814921539,13251292504894009,13267962579601162,13607985448131968,13643989911066597,13683184275342868,13857063328325384,13876416965113276,13928286587160468,13936184667872377,14185209660937368,14570305806226860,14636830411989773,14670409059714523,14678154461630948,14759591447656996,14834053911536957,14917458592763596,15049043388912067,15110877825037937,15331662568939842,15445305063841141,15498251944872112,15627732645364045,15668134882728062,15745153245391605,15855327970815779,16061544764375341,16067571627094821,16105567490627168,16178814864772033,16196444784006479,16318110966403972,16330048899976559,16382120221284861,16487274438287549,16532227756425628,16634814728576994,16686490819904524,16950333282649904,16959764044810122,17026797454745913,17046464580066944,17050246564530947,17051764854358918,17054235414661266,17076678488598142,17118171145010755,17126337638247720,17179964893488266,17232312954157508,17270582611804097,17282464287079877,17329147627288274,17340341403579890,17405482774993186,17726976462665939,17839075128088804,18085940885397183,18196984503567475,18207148582570169,18257702670024098,18278455743602679,18397496035728531,18482269488009439,18630158323459894,18798061459691628,18945607763587419,19060382142220345,19068461292749295,19139901559501608,19327769821329270,19397344798241427,19537487004800675,19555840028777857,19594995805140694,19721392760439505,19773427134168179,19797882393475956,19929572547514763,19964323270903650,19999509902794123,20037067585874331,20066987287521336,20088795460805098,20355571688748279,20383060923438485,20502265370074037,20569143977220296,20622497144315165,20640909372403319,20723844316606129,20740462590016472,20856615905906142,20941615634432625,20946208657146858,21089456221971988,21300661535474443,21311019865902985,21500583080761998,21549322568270962,21551429723254779,21562062387748568,21570372740641076,21611617817240124,21637309311379459,21835922466716317,21953509392842121,21993293957555379,21996740119642566,22021049904473674,22175486468982627,22409054010316899,22418083238159880,22542181449450014,22661609820967918,22783833421254590,23095265146594554,23155038468082725,23264376175291459,23283485309532624,23330158762737193,23364141427855904,23500670594904837,23562376369186745,23616903659999802,23842269578871070,23881642270151634,23948941939984962,23956492383551826,24159560147585804,24274796400123037,24340227837865309,24385903091351077,24443302281507685,24470289913033329,24528469619784516,24535103091805043,24584188220623042,24704326977474427,24736924179557936,24773304452299995,24779541675460984,24783092814209349,24788267502185834,24804257109894977,24918997827632624,24961058929076054,24961646873781208,25088114336068282,25721457023946001,25869972034125778,25939846634399207,25997092266604355,26028595805598477,26110213151728692,26120210061465186,26127678727232725,26218456043225551,26305765479786227,26313127070919128,26328743317098329,26337983717629011,26371763349091549,26383878786172822,26575582635531336,26675595964895081,26849952450776358,26910199571120374,26913971629809306,26945515107737796,27157327154523089,27314248043672998,27558493245316647,27575719278577145,27696611145035784,27700693753230636,27731783810302674,27955677801467109,27963645157763484,28152853341321708,28193329493970904,28220585178276762,28230292847514459,28282230864857122,28379593391172935,28445254169631738,28524776139809309,28688629758503955,28699937686626162,28744148095026186,28759603348967620,28986000284546229,29070522964736049,29166813566093111,29167127138460521,29414174905059861,29580214349205145,29600625763905997,29656546817068837,29773142565314759,29833479521157523,29865460840818850,30081318424485951,30486522324034786,30519111299378326,30536114602758022,30628217988425248,30697614400758831,30741485136259531,30758905444265141,30761303968850023,30793983875441235,31085910560628339,31255945334375918,31374729799128228,31391056806961701,31413871155931311,31658433649258475,31861051394886527,31877658987321992,31903680848827237,31943955609647016,32173273641564550,32290882074043924,32323619097005873,32377590166833388,32393236358326418,32503071207260531,32635020431737021,32642035338602740,32697149546905385,32961618830049676,32966766939567075,32985638960404704,33163068243091121,33188477570924884,33259191307936201,33281649160198826,33311632490588055,33497050138895313,33628440624846253,33643228181541667,33687494986231998,33725125200188138,33742786052829798,33766318610758258,33847852010386685,33887103450951685,33908949659081717,33994506112246947,34143768420261820,34166324371663926,34253399893714739,34261612973862845,34492990232771803,34512833676488573,34585803714007717,34671737489829179,34756254966166405,34828036441958899,34995781924006543,35046634396258957,35314282312506278,35512368433441506,35573274609955742,35605117879326673,35687866220346264,35720411005545657,35774726253061480,35944637471498556,35978448404180151,36104522178779114,36230835663816249,36486017749975359,37122428609541568,37186121056592496,37202238205404221,37239299624593410,37558807211446448,37881688635310689,38083635008813176,38091512285742921,38296957791720612,38369344569416735,38388092464876079,38500639868703358,38571946996647157,38585237872520316,38743982927831139,38777087429484833,38783125187627899,38787859525865771,38927379500668376,39072603659591366,39170211804272045,39205020228385915,39293567032446872,39408236504532620,39524288924812928,39544536904508762,39902933322907710,39997840152815846,40027600215096710,40141262936096420,40584878959023049,40615330015861936,40678007584102309,40760295084668318,41042098881269066,41047801648607639,41250549345181552,41439609140822035,41534623020671063,41569770988811591,41627748926841562,41665289072857058,41668168893895487,41699235201250741,41757819127362982,41772994770179473,41835138639792426,41867098826997411,41868471716640805,42076664633976937,42150840634761559,42213221674046875,42349871663418038,42373844615965505,42447647261211795,42749872618174082,42795881617440845,42811389055676360,42884697902410110,42925411947550499,42954322472810324,43084294807549999,43158458898446710,43477684188302056,43485471560495468,43557628925771994,43560296504813822,43582561875315765,43892530334097855,43916218123362393,43921896642254217,44181493589243844,44370193567875600,44371626426162697,44435367508936207,44619065746936250,44772865381614109,44943697576620030,44990696022790193,45068567485746117,45147955790599803,45448390172064710,45451320069520407,45727979980588919,45751174242127951,45828298530809143,45913747196994191,45953589772413282,45957947871080148,45990082163570948,46045350140475552,46203532231899236,46264294207468345,46559837996590028,46636721086810155,46651350126298280,46930332108119875,46988076634202912,47298131084908041,47305649645414136,47446089072142072,47538159696020893,47605225603007193,47663808783391567,47928631243579735,48035765721729120,48122325829075959,48137331283694679,48253882095991511,48482507166366934,48537189949610876,48606939739760647,48633247096302413,48707288068401735,48796211565787330,48839716252763856,48999755719016917,49041694418639312,49279204449464595,49341907645760437,49405257854747465,49432538051825322,49449353560641698,49549596699084913,49633122345632280,49770824034870588,49772685610993462,49789038629705028,49822649020221941,49972951327417720,49986635969241652,50081855799232035,50131566595432108,50194377067321180,50237162473786691,50287549173664693,50348305481378828,50355305038984582,50658296984329528,50695352080006084,50775348719743914,50784448187432293,50879085195435491,50970938428688317,51000427622542320,51032991537537949,51046117895368339,51095000648560527,51144660350990856,51218955635368800,51444711703717363,51455044600391463,51493504038584081,51656038775128834,51701910711867717,51750882140753168,51784757502440302,51981406196950579,52100085438092968,52168421276402427,52182854639856491,52297900852547351,52354801698530781,52357800065609469,52438583190757525,52634408597218306,52731138924081769,52889439376292592,52918566198548655,53030869950378110,53079477646831627,53115399782265826,53465169437015335,53556582712020931,53788281384050530,53870819079633228,53988940198673379,54003892836395793,54234855095103075,54328279254458631,54404810533593700,54560724488474136,54881364589051078,54976879272871673,55086500493543972,55294545406971227,55457348167864041,55495293246954036,55619820831953423,55647043101187016,55677818123556119,55688844834641319,55743046464377559,55744636616802329,55881317783513064,55914951899773201,56020402755309318,56121254658321660,56138278610521153,56224237020671803,56253565511932988,56341644353287220,56394087997477047,56414872371511233,56539775881356468,56590950388713761,56794090196895314,57439347526596363,57542855942481194,57674283236345410,57748050083703912,57785884677552971,57862558855222556,57870427310190507,57898927384845970,57917178443243853,57936783057080539,58106369241255766,58335734681152318,58346156589588694,58395575457246169,58418957722637704,58423671625797062,58429987431847589,58501052626034152,58562738558672212,58583293573282398,58751551288608942,58813273803872115,58976917257312440,58983384092222373,59001389539159174,59076202101502818,59166429855197911,59264432726329519,59345550256461885,59481124680265519,59575582375618453,59607576818540750,59860637427040624,59941978320143327,60126088050413038,60231962584530360,60234137651843534,60315996819138510,60348595541001089,60431681629184473,60754473715021627,60762052267749875,60814912085525420,61313445900648704,61326421543328929,61347686944989632,61539429576031510,61545722560407473,61724494180100997,62121056468006441,62121077022305321,62220603518735781,62348295351725380,62422103448842977,62614329997764883,62734130757920426,62809686033735502,62819959870745173,62875599108731443,62902896600560157,63080835086370425,63087275097459575,63115310284896821,63141945431373631,63291809577859769,63516488772586291,63540167432123932,63562297562759459,63629133388621575,63650960350891837,63764823764384222,63913973905440804,64056099600303931,64094822226449535,64187364579401849,64219844995803221,64306919486364245,64399324787093905,64522528785679699,64678873990632838,64684239278650302,64688232505846265,64765260591971437,64825045394893903,64831471441510673,64941112550563168,64995765387025899,65074589615128360,65200122818677418,65372872615090296,65398633501973388,65936660377837219,65956976180526533,65958989022272698,65981579536286958,66166191309030182,66374070001548139,66496140905723602,66504738329096080,66557372041902507,66895332084588465,67039816450688422,67066516229696647,67102339604648565,67103030937968027,67117446890785746,67189436209294929,67656973214389675,67776886675252221,68081858208969693,68141511286411432,68271541252237862,68277064013975769,68337214281542846,68511148841680982,68567726807529750,68571566788584282,68599853676418213,68639809863698341,68741019677324429,68919787098627789,69049501002311001,69052456261153414,69058655774396013,69122516992949698,69170168378107728,69224340682433867,69466046355154127,69500209273445080,69511793685241591,69523868037699170,69678694081828566,69766411545898809,69819780093606332,69948419424627873,70283809578705631,70305211917691262,70392977121960288,70472376758892497,70508188893305284,70529739681847079,70549364824511886,70555187432146910,70765950876687384,70778945015899101,70784814247794174,70847959413792044,70877523955315935,70958790049288821,71348234900704254,71427399604991833,71468689344363784,71564160853826526,71671061696220257,71697366098503481,71958861266446231,71995136609952601,72097148345184612,72128026173626184,72383611213215010,72740551512348655,72896069197305454,72941753865723512,73008804496489269,73307113342289939,73333919783395428,73364584622050443,73767502281888260,73966812523648157,74053199888149498,74099122164045541,74261756697388400,74272120074164139,74322539931515620,74492785919568692,74936403912551550,74986673499665827,75147209422979930,75177624579643640,75277496181622803,75288912223811695,75673108857009401,75694762657381358,75730828215262997,75874329476880653,75878523307757938,75970764470913159,75986623254193592,76047642127498400,76134579257896764,76160030138234119,76181222248940833,76205154350741143,76302448479044580,76603292472638998,76819318808795822,76927400173434901,76974448938020770,77054223691978215,77110743460939273,77139951145039352,77460963959838956,77730777805151549,77855414181537523,77904339630738773,77929682373272335,78049254460021133,78054287424572362,78266918225947734,78374672315238681,78627774616258105,78634553606576763,78688907870916164,78766683819513721,78809157293148738,78843683284799323,78940932151113760,79033736108793456,79253888199768273,79324047024836240,79368741287568165,79534052290439013,79543233565830727,79634361951904264,79675398054742711,79853142276435887,79994185831917396,80019948697127179,80159225063217676,80241078252945525,80259897551927344,80267271106978197,80269772087891813,80391462578705105,80486810883421099,80655298860837196,80684302791548454,80985031474371786,80986164072019432,81069586034359102,81124021580470195,81166816614364230,81295906682023457,81334753054923846,81489191782599917,81724450684707981,81749790467852250,81761871842715178,81873915164192094,82024644067910763,82153826420482685,82244061709610991,82344210365992965,82475607625692737,82764448213190198,82766293764004027,82820353549533062,82859645476834018,82900739664394063,82908524280337163,83165507281319466,83324165600343327,83376878454852963,83443871963156048,83565261215559650,83676677822072011,83805254761873838,83813087768723160,83819780335344515,83875416035716754,83947090959689908,83971352569998067,84080173387108744,84085406214756051,84253332954540827,84382301080247502,84460942521896072,84611081960787179,84694797624127828,84980721219670615,85415594628223465,85531639407840384,85745496687725294,85776943929895159,85884225419317071,85992503127998043,86038618827715824,86297031075930846,86479290837219711,86525811843116785,86639989674059876,86667719559309215,86722895830492150,86802187342651164,86873882169871818,87140893985442694,87142702975374653,87298456008788615,87382165243695031,87477596934949201,87772374118743826,87784078799347040,87784347296083150,87834826928726182,87847567892079723,87972237425531484,88069863301033724,88167802506835712,88508542560875901,88579700369179554,88595393152753427,88820306034571113,88832502626935524,88858458637020774,89102311792054912,89112832552494207,89231744538051637,89238684657413443,89396920556090876,89427998355289599,89670787406838618,89718775270618003,89735909621218950,89936616006277040,89970204470735301,90115729916894695,90265275791893680,90265435199841817,90374918550918148,90432102415195980,90547797353763736,90554806818964577,90583342168924186,90645658264112285,90675151894203026,90759649009832787,90781143484004649,90871307877328510,90987641808444846,91003942408119863,91030034911036341,91110564291741680,91213068671379462,91467273435277512,91623923439291895,91634248223977132,91762596524934915,91797252452264377,91817765360517788,91994248386185306,92150684971210853,92216839396604531,92308430108063206,92373064773456010,92566907262224930,92677662473695372,92954739682094660,93056140089044046,93058618397053038,93114101395580737,93525643661712975,93529155396439268,93696162216964922,93769165443018427,93918226577681960,94040633676158189,94421467064097285,94557915283187280,94605810747338991,94624200082914461,94626846600752902,94645922508084114,94748279133612252,94776671439155865,94837318784682733,94875166068856932,94943115182544987,95022966801539854,95058242246646572,95126651243943929,95174267784643731,95230686361333221,95369343763952223,95495428104919018,95693085755474508,95765500254544972,95776361323965959,95862916339961976,96134321076198166,96138495911162781,96602424059703022,96636206040751929,96796335621492901,96798018456125483,96802583955895938,96985516661630432,97261991473866253,97558205848912865,97620852915182894,97697583797346930,97807617348911925,98172592059626895,98213915871683363,98359650206987102,98396305716381057,98660902578830397,98730163107281984,98761968699198332,98819786296928621,98827045008404696,98861268764199504,99028393987717057,99101152928823619,99121074169335723,99186068279904504,99355048502003821,99555824359323837,99652186774652281,99792934732604519,99847185133838279,99849740605255102,99898703299897858,99945533075504251,100355999599566948,100436414578527812,100696018304456016,100699862590799801,100709064312509417,100754565016518884,100994628562382314,101124968061631206,101465192268787450,101879496831203724,101961368233968587,102055808284673759,102128519861484016,102294611425690232,102321681482335410,102361887500896609,102529235487130106,102596061282602245,102716552090276443,102744507791763973,102844876808381041,103119309991062678,103220907931339423,103361914877701523,103452091348770164,103585916672895873,103606439996016763,103816447361964943,103864069476041108,104220461638025672,104605658041642470,104606018123769202,104708768475268326,104738360058367219,104745769659374327,104808272008976138,104869526805119156,105194035336196063,105519646767071650,105581493625025120,105585528839689193,105779151408344548,105969126211596880,106005622444286678,106068143088778811,106177375257931612,106356523252453585,106506379467155600,106651581092940284,106844742409839992,106888618244572695,106984732514653767,107016622734956749,107169785981891501,107200117644943924,107369479726746603,107426519899348905,107445753287468300,107477272105290922,107477367872196077,107495383350259489,107593904999824620,107608968672861926,107641952103607366,107760218640600151,107785035905499165,107834431933304295,107934127661291799,107997391949274531,108177610348750465,108459278620526826,108501179139909883,108584811631201391,108590229877590599,108700461579448387,108711595186759508,108785549727424551,109150829392638994,110053068766469625,110099945863931264,110226653640785391,110232191026028260,110236820450987666,110263614981644806,110321661162119352,110847706516485512,110860237282389659,110981721378329887,111019384567725435,111082470256240793,111298095982996972,111304023415547647,111340215351471940,111411169733447861,111499540003090943,111529670429210894,111668915440102453,112092655730522776,112126419963123964,112346971221047396,112381986758370300,112556283731943782,112577478262430406,112634265918971578,112722559035631967,112744645363403628,112757635362333984,112839934722566076,112930375237029520,112942336246359986,112981068776761549,113022947478974667,113069682828208758,113189712710889425,113226371289884945,113321646391728064,113557479902403151,113678505368877872,113692122069183087,113702826512815298,113959636858426580,114034509322328023,114056050559057954,114090407568488873,114139865553024058,114159833649560082,114439934625865064,114598082056567965,114636783770957494,114712751110407075,114786303028263549,114893526939047253,115163347115596369,115176639526223971,115195611696924424,115230740393088877,115235412056038432,115968214019700421,115999779272979758,116112923686056995,116148749342946197,116218103505595948,116286831213415061,116381588333758255,116431488289922486,116466533371142358,116569822835373426,116720695707951356,116774157032961407,116897180537962444,117009548024645053,117103542756321700,117193275020187788,117255686937895669,117730372578703875,117936612542206091,118011638550425753,118031772066823444,118042069104175694,118048644854122546,118071275037765402,118194170612793835,118204139642517095,118429187750643495,118451232562547511,118503811928155740,118660501988107076,118694214984989865,119005260980576012,119116308314368048,119165368106574075,119171705341315732,119241761984205147,119264372777177332,119296448906274473,119430811121468029,119594281515046005,119700816361472178,119721746924749801,119758817292669110,119852710830695785,119967357218686304,120068376020841024,120515559234444248,120702962937626594,120863529502343975,120879288151655753,120885547969359394,121115239564275706,121235868282245942,121237651622072109,121429441264857384,121455053039014020,121517633204371936,121596138791718846,121625421252006528,121634135356046720,121646590873280300,121768426455443993,121847802372327832,121920786209923661,121975488925567732,122354041841068435,122456369187347553,122535766825357272,122551861543699684,122629098459403332,122700212186899412,122712836606745303,122819923783459867,123133301804088670,123204524864166583,123342733626685387,123361850244277228,123482614638834326,123528610958399747,123608279349956908,123617677842583352,123643011422788296,123724364638377607,123729974495421840,123802460302364113,123805560522401906,123827262634320846,123829484332135748,124074665315420113,124141767392938355,124190611976804326,124312629435566374,124354682947777948,124397087935749632,124411637520888457,124421387697875213,124486091525119265,124531101895114901,124542824252530423,124636960662392761,124690917401675057,124905688051607703,124905822743648395,125169335422943834,125242629550112755,125359559237521405,125408161778905636,125582891473855796,125590287447064119,125811408242157623,126416996677497866,126652757666260434,126722962949817405,126825180000809689,126841178074410933,127072119971655372,127413577214159361,127533602043497327,127603351268576361,127822606242755959,128091713261833884,128183689823389523,128413149200386648,128552206258384314,128569975317286078,129027739143500741,129379176305099644,129676509767265944,129698076705042890,129854106464236434,129905501949814693,129921442404128898,129939777033152215,129971032382904412,130003529840053195,130067917993718584,130171419105331013,130337141126237684,130414865155207758,130652413649975829,130709347491609383,130725673461368934,130784027898600644,130933174026836491,130967672714969500,131067755768091302,131307042135036633,131317364254112804,131362479141829333,131433294422542567,131485827156683551,131634935688257723,131857398930287558,132054240438009811,132058063926621294,132274633986847783,132316386515192575,132341886893439850,132619052943663567,132658693408104616,132916877605982916,132924629969332398,132929572872977946,132999213369552800,133017418439407940,133176871415833701,133192278901904563,133302359045758337,133444077818945157,133556208010964756,133702650563810729,133710273282487929,133935863762442125,134063428845416369,134115988147962168,134327552084834908,134361022933424251,134403699097929209,134499610476053531,134657955633736575,134726569563179490,134918321682836496,134980563724388674,135048970372609378,135072858434599830,135128727960893031,135234619044395355,135425442971844572,135730605430262306,135738470460807603,135937510641177667,136092587831727322,136116524946115158,136283818000198962,136286196606445621,136333288395227715,136416668540274221,136525060343589764,136620170905873787,136730979412654113,136731491216446976,136874324901186517,136951473140510005,137020334561940291,137077481689571842,137315252460923431,137365873620950765,137399589693839940,137482293045052218,137571594286196819,137927077519961253,137937299978612412,137979279973148331,138216996814902445,138432262093420023,138459628245163335,138488171748872260,138720261168664014,138740236516216492,138770191048705141,138773196573055217,138980248846183341,139444464504675121,139454690609707150,139535825492957691,139563922461885304,139611026136372036,139698378485403524,139895262339695697,139983902045909817,139997995187993269,140043448846471158,140084819838383781,140192950437624469,140283182366084035,140460091663640837,140480453120996910,140518514173898326,141076597845951592,141121994771407056,141284530173934686,141330321010914847,141497254813624143,141499541214384056,141507059408289119,141608076399474454,141701315779820918,141768087064536783,141842442149225000,141848838860759079,141860524046604605,141910530452997115,142014215090148686,142038680443563331,142136888559769677,142195869743819427,142199241644601212,142289226401750762,142289478449550848,142378917382470442,142469056240660097,142647695521188385,142663537079477786,142768656449109794,142823511289997170,142863360211629142,142885082431947677,142898979817397613,143086117478101374,143191565049615973,143245970860188837,143295661264161757,143334715109813645,143509525656807414,143620338059039272,143699879520516980,143843196245495066,144354509966921323,144362421270844693,144393830020543286,144425316065457015,144900436842503536,144949682583830226,145082502470190152,145161867275158631,145303718680395223,145380789749362084,145466227045943900,145634111004677218,145644955497473504,145665384010179350,145690504080747785,145883603262216916,145995910283194901,146022263002222549,146046661924495697,146295271940275443,146346437947822458,146577785950927593,146606661697981065,146637255835446350,146648739118857305,146732624793150649,146743146724247597,146871970105612748,146981961755448839,147188049214980341,147290808721498222,147350974967858526,147353871587596808,147386668253283769,147433371708600522,147462933329013334,147467860141064927,147504723448999955,147701208818936431,147783482737053022,147894711891420535,147990002049586738,148109021665027872,148267662642025949,148364927317466608,148369541959414656,148479759961971552,148486444530178149,148520368146593889,148623529026501056,148648999948939481,148702970797712049,148738095753881468,148846518191840180,148968246056449574,149201267927836269,149286692740639796,149363716339189995,149467210123414617,149516201070831437,149810983634954458,149828314180341254,150018025039016252,150089983008842302,150467150719253214,150481306885240073,150502947561180335,150714258171092854,150759142502331153,150764788465124685,150768647317605811,150859062393660659,151300860134069945,151479528915861127,151494334470191468,151566892362193156,151780768890617386,151822452713712625,151872300503360024,151894139419628183,151999013037725352,152162538468306825,152205500148417003,152656445968983754,152673867803538541,152847344695371579,152876594569428338,152927755250487727,152970745635194239,153048803230334574,153141213273456929,153202573167832739,153443271149871344,153537344627884690,153693196192697136,153784181606495536,153830705006108297,153903967374817440,153924903518924197,153963453455393931,153985806807296428,154325732039804729,154439052865188849,154901787550911373,154911950298498125,154926237860553036,154972300330655976,155052738273425420,155166011930886961,155285122833273622,155285872224029157,155314409634142481,155397312615576285,155568025044717651,155611218949860133,155657731201718864,155869987609659946,155928075997904471,155931490324041697,155994533183530628,156032517390601698,156094562675671015,156105622804569008,156278985840305621,156378650677824554,156452230625632182,156556785719216977,156619067608945812,156883367239099772,156941973416893754,156970226942821889,157005059494232679,157100797497537156,157262266807964432,157482839001151795,157486940028074530,157528171641182524,157535948704814500,157710453968203769,157844851718662257,158260553892613470,158415093023479829,158426974973071656,158486519151081297,158590126716885530,158790468076402004,158972406098291560,159080604686265888,159085563116299362,159105404502824002,159142514048890641,159285576851653767,159337044882889645,159353784809490238,159526992827418075,159545537159194220,159750701760857631,159853270065652873,159966270403261180,160424506963632790,160455900682180405,160722955315850975,160862930324627585,161129405735582575,161178114894831861,161464829568948284,161554801828156199,161679141412777210,161738787056365777,161817091802842059,162015628241187904,162095055785164629,162254276560012492,162409782091865438,162412828208957393,162615436822982502,162618734632169332,163218583750553811,163389509856944162,164215932395311350,164413769086027554,165067954904665220,165078680159784875,165085161679192544,165135962040100283,165185311150840915,165345323979043347,165454514243592416,165501832057524721,165531397604861550,165570971302046629,165631838851357322,165671511056204888,165730090472658650,165730183176856909,165812139483920114,165845768803300520,165888927403757515,165901147920744549,166036742536704686,166267229024180492,166478324195530413,166591303942061664,166614564133825469,166879165792855778,167146125206201819,167180871702218109,167357078298774888,167403079527928952,167693788603704694,167766968322382558,167768933283843908,167793994897222452,168165444876924029,168190276448608154,168230902854069748,168383720919256291,168573856203437049,168764129308500676,169025520018661556,169028029349841456,169075618384023561,169263420559402022,169320460380783315,169436844295597618,169437722680311904,169540459556277673,169541276933409115,169680797402211954,169725066072381129,169832814470024577,169931014049152843,169970604164153267,170133614311175857,170636672427024701,170662036722332942,170760651368648698,170851393425528563,171125116899431435,171128975932707059,171164362647827164,171231268862059435,171522912649136101,171748574844133717,171810497456017357,171905359708965622,172105357921379965,172256745521420842,172320768013549097,172358633131914783,172507617848801788,172599990356727305,172725552943913321,172871314353860368,172892778025066638,172934100361495292,172944985320581059,172946546174653413,172988846583943848,173168530543962112,173430717292860313,173539247592166987,173574379295554645,173668790244363820,173782821012638819,173860668461431732,174007005826568832,174187953034030437,174261916610006019,174418747019598004,174548528818207116,174574310949363862,174719008902540618,174738913515291548,174873014203353541,174894998689875173,174971251094230660,175166032633850364,175348737398077656,175380478493319164,175403809837312182,175463342388339559,175487708908413265,176226899579218122,176327303905896331,176445656068820596,176553494606924767,176620140150471495,176879266188377882,176892643406146807,176910585579759758,177042145471615748,177118533623606888,177151609142220755,177226849610765856,177231398080863520,177248426524420789,177320689910654814,177358252011277091,177452952565438298,177479210303679611,177541590549458779,177699023927282195,177733666432195235,178113114888650489,178173378714355390,178237858024294526,178288943573534442,178314571086833393,178361301755803187,178423341281215927,178445406268658730,178483858957566073,178552959525020826,178656919391414911,178769547110970456,178859058672444271,178876369710381595,178934132880380321,179038521803194201,179112925908246369,179144953608551903,179159723376405076,179271137390217119,179457593466714201,179483042631386422,179536073186350127,179562367543435186,179593202891988194,179750549332450188,179905867237802929,179976104979997092,179981101188425381,180091027075849407,180569847510728018,180828995671384397,180837735746151753,180854678531257283,180917785439226934,181127174777818334,181257752602001095,181311353271483000,181371499521683823,181718194629279162,181914656941867235,182005740244041402,182094569461816786,182152393634098470,182331684118027880,182364137037952491,182579766163466032,182640335396612969,182817439666401956,182873888141941222,182887417380445928,182898832592313947,183036591865572814,183069934847726956,183091058272628699,183159048878014598,183160993163066180,183201458391896973,183231430137519715,183297676053363896,183311299151852758,183370953152768410,183376677299925804,183480047313662929,183485641057028490,183486058153370109,183563590316648821,183605964221677843,183648944810378507,183730886855164719,184114705165180509,184119937403667772,184222170813903806,184267827986910513],"md5sum":"dcc790330a35a49d789cb890ecc9bfe4","abundances":[1,1,2,1,1,9,8,3,1,66,1,4,5,7,3,3,3,2,10,1,16,5,1,10,1,1,2,1,2,6,6,14,1,3,9,1,1,5,2,1,3,8,1,1,13,1,1,4,1,1,7,1,2,15,13,1,1,9,1,1,1,17,5,1,1,2,4,2,3,5,1,1,2,1,3,10,1,2,1,1,1,6,2,1,1,1,1,2,1,3,3,1,1,1,1,1,1,5,1,13,6,1,7,1,16,2,3,21,1,1,1,1,6,10,6,1,1,1,7,1,1,2,1,6,1,1,1,2,2,7,6,6,2,6,5,2,2,9,7,1,2,1,1,8,1,2,1,2,1,1,1,2,2,9,1,25,40,1,4,1,14,1,1,11,9,1,1,1,2,7,1,5,8,1,1,2,10,1,8,1,9,4,4,3,3,3,4,2,106,3,2,2,5,1,8,8,1,7,4,8,3,1,2,2,7,1,2,1,1,4,13,1,1,1,1,19,4,2,1,1,5,8,1,1,1,1,4,1,7,3,2,1,1,9,11,3,1,5,3,1,3,7,1,1,1,1,1,1,5,1,1,1,4,1,1,1,1,1,2,1,1,2,6,27,12,5,11,4,1,2,1,2,6,3,3,1,1,3,1,10,7,2,9,1,1,1,1,9,9,1,3,1,5,1,1,1,1,1,1,2,1,1,1,5,1,5,1,6,5,1,5,1,5,15,1,7,1,1,1,1,11,24,1,6,11,3,1,7,9,2,1,2,13,1,1,2,8,1,8,2,1,1,7,10,4,1,5,16,3,2,15,1,10,1,1,2,2,1,1,6,11,1,3,23,2,4,4,8,2,5,25,3,3,2,1,12,2,1,2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3,1,6,1,5,12,1,1,14,1,1,51,395,1,1,6,4,9,1,2,3,6,2,12,5,1,3,2,1,1,14,10,29,14,3,2,1,14,1,6,1,5,5,1,1,1,1,1,6,1,1,1,7,2,26,4,3,4,3,5,11,6,4,9,1,1,1,1,5,6,1,1,1,1,1,4,1,3,1,1,2,1,14,3,1,2,4,1,1,12,3,1,4,1,4,1,14,1,12,1,20,6,6,7,20,1,10,1,1,1,3,2,1,9,23,2,5,2,1,1,1,1,1,5,8,3,1,1,3,1,1,1,1,17,2,1,5,2,1,3,3,1,6,5,4,14,1,3,15,6,17,2,1,1,33,11,4,1,2,5,1,4,2,3,9,2,35,3,1,8,22,6,3,5,1,1,6,13,3,1,1,5,1,1,1,2,8,2,9,3,4,1,1,1,1,1,1,2,1,6,1,1,3,15,2,2,18,8,1,9,1,2,6,1,1,5,2,1,3,1,1,19,4,11,1,1,1,1,2,1,6,3,1,20,3,14,23,7,13,1,6,4,15,1,2,1,5,1,8,4,6,1,2,1,1,2,2,7,15,1,5,1,4,1,1,2,3,3,1,1,6,1,7,1,1,3,1,27,1,11,1,1,4,1,13,2,12,2,2,4,3,491,1,4,1,5,1,1,1,4,2,7,2,11,1,6,1,1,5,2,1,1,2,1,5,2,1,3,1,4,2,1,1,2,1,6,2,2,5,1,5,1,1,8,2,1,1,2,1,1,6,2,1,1,2,1,13,19,2,1,4,2,5,1,1,1,2,1,1,1,1,5,1,1,1,1,1,3,1,1,1,1,13,1,11,3,7,1,1,2,4,6,7,8,3,1,2,2,4,6,1,3,1,1,10,4,3,1,4,1,1,1,4,7,8,2,1,1,1,2,1,5,1,1,2,1,1,7,3,5,4,3,1,1,1,2,1,31,3,1,1],"molecule":"dayhoff"}],"version":0.4}] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d641713..494be6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,11 @@ use std::io::{BufRead, BufReader, BufWriter}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; +use anyhow::{anyhow, Context, Result}; use clap::arg_enum; use log::info; use rayon::prelude::*; -use sourmash::signature::Signature; +use sourmash::signature::{Signature, SigsTrait}; use sourmash::sketch::minhash::{ max_hash_for_scaled, HashFunctions, KmerMinHash, KmerMinHashBTree, }; @@ -66,7 +67,7 @@ fn subtract>( scaled: usize, hash_function: HashFunctions, output: Option

, -) -> Result<(), Box> { +) -> Result<()> { info!("Loading queries"); let max_hash = max_hash_for_scaled(scaled as u64); @@ -121,42 +122,55 @@ fn subtract>( let processed_sigs = AtomicUsize::new(0); - search_sigs.par_iter().for_each(|filename| { + search_sigs.par_iter().try_for_each(|filename| { let i = processed_sigs.fetch_add(1, Ordering::SeqCst); if i % 1000 == 0 { info!("Processed {} sigs", i); } - let mut search_mh: Option = None; - let mut search_sig = Signature::from_path(&filename) - .unwrap_or_else(|_| panic!("Error processing {:?}", filename)) - .swap_remove(0); - if let Some(sketch) = search_sig.select_sketch(&template) { - if let Sketch::MinHash(mh) = sketch { - search_mh = Some(mh.clone().into()); - } - } - let mut search_mh = search_mh.unwrap_or_else(|| { - panic!( - "Unable to load a sketch from {:?} matching the provided template: {:?}", - filename, &template - ) - }); + let mut search_sig = Signature::from_path(&filename)?.swap_remove(0); + let mut search_mh = select_and_downsample(&search_sig, &template) + .with_context(|| format!("Unable to load a sketch from {:?}", &filename,))?; // remove the hashes - search_mh.remove_many(&hashes_to_remove).unwrap(); + search_mh.remove_many(&hashes_to_remove)?; // save to output dir let mut path = outdir.clone(); - path.push(filename.file_name().unwrap()); + path.push( + filename + .file_name() + .ok_or_else(|| anyhow!("Error converting filename"))?, + ); - let mut out = BufWriter::new(File::create(path).unwrap()); + let mut out = BufWriter::new(File::create(path)?); search_sig.reset_sketches(); search_sig.push(Sketch::LargeMinHash(search_mh)); - serde_json::to_writer(&mut out, &[search_sig]).unwrap(); - }); + serde_json::to_writer(&mut out, &[search_sig])?; - Ok(()) + Ok(()) + }) +} + +fn select_and_downsample(search_sig: &Signature, template: &Sketch) -> Result { + let mut search_mh: Option = None; + if let Sketch::MinHash(template) = template { + for sketch in search_sig.sketches() { + if let Sketch::MinHash(mh) = sketch { + if mh.check_compatible(&template).is_ok() { + search_mh = Some(mh.into()); + } else if mh.ksize() == template.ksize() + && mh.hash_function() == template.hash_function() + && mh.seed() == template.seed() + && mh.scaled() < template.scaled() + { + search_mh = Some(mh.downsample_max_hash(template.max_hash())?.into()); + } + } + } + } + + search_mh.ok_or_else(|| anyhow!("No sketch matching the provided template: {:?}", &template)) } fn main() -> Result<(), Box> { diff --git a/tests/subtract_cmd.rs b/tests/subtract_cmd.rs index 370e7ca..6a45a5f 100644 --- a/tests/subtract_cmd.rs +++ b/tests/subtract_cmd.rs @@ -96,3 +96,32 @@ fn subtract_protein_from_dayhoff() -> Result<(), Box> { Ok(()) } + +#[test] +fn dayhoff_downsample() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("subtract")?; + + let tmp_dir = TempDir::new()?; + + let mut file = NamedTempFile::new()?; + writeln!(file, "data/bat2-LU__AAACCTGAGCCACGCT.sig")?; + + cmd.arg("data/bat2-LU__AAACCTGAGCCACGCT-s100.sig") + .arg(file.path()) + .args(&["-k", "42"]) + .args(&["-s", "100"]) + .args(&["-e", "dayhoff"]) + .args(&["-o", tmp_dir.path().to_str().unwrap()]) + .assert() + .success(); + + let path = tmp_dir + .path() + .join("42") + .join("bat2-LU__AAACCTGAGCCACGCT.sig"); + assert!(path.exists()); + let mh = &Signature::from_path(path)?.swap_remove(0).sketches()[0]; + assert_eq!(mh.size(), 0); + + Ok(()) +}