Repository: saketkc/pysradb

Issue:
[BUG] month & day swapped for publication_date?
Thanks for the great tool!

I wonder if the month & date are swapped for the `publication_date` argument in `SraSearch`, since I find fewer entries with a date range from '01-01-2021:01-02-2021' vs '01-01-2021:02-01-2021'.

![image](https://user-images.githubusercontent.com/19657573/140439289-287e8b21-c10f-4342-a216-816a4c6af3bf.png)

Note the function nevertheless throws an error for e.g. 29-01-2021

In [2]: pysradb.__version__
Out[2]: '1.0.1'

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#146](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (cf42b39) into [master](https://codecov.io/gh/saketkc/pysradb/commit/494c5acf728a0c65883a5255a1c90f3af4299876?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (494c5ac) will **increase** coverage by `0.95%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/saketkc/pysradb/pull/146/graphs/tree.svg?width=650&height=150&src=pr&token=w1fPTXpzK2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

```diff
@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
+ Coverage   57.12%   58.08%   +0.95%     
==========================================
  Files           8        8              
  Lines        1775     1782       +7     
==========================================
+ Hits         1014     1035      +21     
+ Misses        761      747      -14     
```


| [Impacted Files](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [pysradb/search.py](https://codecov.io/gh/saketkc/pysradb/pull/146/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cHlzcmFkYi9zZWFyY2gucHk=) | `80.03% <100.00%> (+0.18%)` | :arrow_up: |
| [pysradb/download.py](https://codecov.io/gh/saketkc/pysradb/pull/146/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cHlzcmFkYi9kb3dubG9hZC5weQ==) | `28.39% <0.00%> (-0.36%)` | :arrow_down: |
| [pysradb/sraweb.py](https://codecov.io/gh/saketkc/pysradb/pull/146/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cHlzcmFkYi9zcmF3ZWIucHk=) | `81.74% <0.00%> (+2.97%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [494c5ac...cf42b39](https://codecov.io/gh/saketkc/pysradb/pull/146?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

saketkc: Thanks a lot for fixing this so quickly @bscrow!

Patch:
diff --git a/pysradb/search.py b/pysradb/search.py
index 4a918c3..b99c971 100644
--- a/pysradb/search.py
+++ b/pysradb/search.py
@@ -823,7 +823,10 @@ class SraSearch(QuerySearch):
         if self.fields["mbases"]:
             term += str(self.fields["mbases"]) + "[Mbases] AND "
         if self.fields["publication_date"]:
-            term += self.fields["publication_date"].replace("-", "/") + "[PDAT] AND "
+            dates = []
+            for date in self.fields["publication_date"].split(":"):
+                dates.append("/".join(date.split("-")[::-1]))
+            term += ":".join(dates) + "[PDAT] AND "
         if self.fields["platform"]:
             term += self.fields["platform"] + "[Platform] AND "
         if self.fields["selection"]:
@@ -1623,9 +1626,10 @@ class GeoSearch(SraSearch):
         if self.geo_fields["organism"]:
             term += self.geo_fields["organism"] + "[Organism] AND "
         if self.geo_fields["publication_date"]:
-            term += (
-                self.geo_fields["publication_date"].replace("-", "/") + "[PDAT] AND "
-            )
+            dates = []
+            for date in self.fields["publication_date"].split(":"):
+                dates.append("/".join(date.split("-")[::-1]))
+            term += ":".join(dates) + "[PDAT] AND "
         if self.geo_fields["dataset_type"]:
             term += self.geo_fields["dataset_type"] + "[DataSet Type] AND "
         if self.geo_fields["entry_type"]:


Test patch:
diff --git a/tests/data/test_search/sra_search_test1.txt b/tests/data/test_search/sra_search_test1.txt
index 3fe5739..cb6f3c5 100644
--- a/tests/data/test_search/sra_search_test1.txt
+++ b/tests/data/test_search/sra_search_test1.txt
@@ -1,49 +1,2 @@
-SRX113357
-SRX160148
-SRX160292
-SRX145829
-SRX188582
-SRX160512
-SRX113348
-SRX113350
-SRX172392
-SRX172360
 SRX137370
-SRX145830
-SRX113341
-SRX188584
-SRX188583
-SRX113359
-SRX172315
-SRX113360
-SRX113351
-SRX113343
-SRX172393
-SRX113344
-SRX160514
-SRX113345
-SRX113346
-SRX113361
-SRX160291
-SRX113342
-SRX160515
-SRX160510
-SRX160147
-SRX160157
-SRX113352
-SRX113349
-SRX113340
-SRX172394
-SRX113356
-SRX160149
-SRX188585
-SRX137371
-SRX113347
-SRX160516
-SRX113358
-SRX113354
-SRX113353
-SRX160511
-SRX113355
-SRX145831
-SRX172361
\ No newline at end of file
+SRX137371
\ No newline at end of file
diff --git a/tests/data/test_search/sra_uids.txt b/tests/data/test_search/sra_uids.txt
index 5a75d5d..8e45e9e 100644
--- a/tests/data/test_search/sra_uids.txt
+++ b/tests/data/test_search/sra_uids.txt
@@ -1,49 +1,2 @@
-246598
-246597
-246596
-246595
-181685
-181684
-181683
 155791
 155790
-130901
-130900
-130899
-130898
-130897
-130896
-130895
-130894
-130893
-130892
-130891
-130890
-130889
-130888
-130887
-130886
-130885
-130884
-130883
-130882
-130881
-130880
-214061
-214060
-214059
-214028
-214027
-213982
-202173
-202172
-202171
-202169
-202168
-202167
-201949
-201948
-201814
-201806
-201805
-201804
diff --git a/tests/test_search.py b/tests/test_search.py
index f33bd25..1955ab0 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -944,7 +944,7 @@ def test_valid_search_query_1_sra(valid_search_inputs_1):
         "Escherichia coli[Organism]",
         "PAIRED[Layout]",
         "5[Mbases]",
-        "01/01/2019:31/12/2019[PDAT]",
+        "2019/01/01:2019/12/31[PDAT]",
         "ION_TORRENT[Platform]",
         "RANDOM[Selection]",
         "GENOMIC[Source]",
@@ -962,9 +962,9 @@ def test_valid_search_query_2_sra(valid_search_inputs_2):
     expected_query = [
         "Triple[Layout]",
         "Escherichia coli AND SRS6898222[Accession] AND Escherichia coli[Organism] AND paired[Layout] AND "
-        "6[Mbases] AND 01/01/1999:31/12/2019[PDAT] AND ILLUMINA[Platform] AND DNase[Selection] AND "
+        "6[Mbases] AND 1999/01/01:2019/12/31[PDAT] AND ILLUMINA[Platform] AND DNase[Selection] AND "
         "METATRANSCRIPTOMIC[Source] AND MBD-Seq[Strategy]",
-        "single[Layout] AND 5[Mbases] AND 31/12/2019[PDAT] AND OXFORD_NANOPORE[Platform] AND "
+        "single[Layout] AND 5[Mbases] AND 2019/12/31[PDAT] AND OXFORD_NANOPORE[Platform] AND "
         "MBD2 protein methyl-CpG binding domain[Selection] AND GENOMIC SINGLE CELL[Source] AND AMPLICON[Strategy]",
         "Paired[Layout] AND COMPLETE_GENOMICS[Platform] AND Inverse rRNA[Selection] AND TRANSCRIPTOMIC[Source] AND "
         "Hi-C[Strategy]",
@@ -1188,7 +1188,7 @@ def test_valid_search_query_geo(valid_search_inputs_geo):
         "query AND sra gds[Filter]",
         "sra gds[Filter] AND SRS6898940[Accession]",
         "sra gds[Filter] AND Escherichia coli[Organism]",
-        "sra gds[Filter] AND 01/01/2019:31/12/2019[PDAT]",
+        "sra gds[Filter] AND 2019/01/01:2019/12/31[PDAT]",
         "",
         "",
     ]
@@ -1198,7 +1198,7 @@ def test_valid_search_query_geo(valid_search_inputs_geo):
         "GEO query AND gds sra[Filter]",
         "GEO query AND gds sra[Filter]",
         "gds sra[Filter] AND Escherichia coli[Organism]",
-        "gds sra[Filter] AND 01/01/2019:31/12/2019[PDAT]",
+        "gds sra[Filter] AND 2019/01/01:2019/12/31[PDAT]",
         "gds sra[Filter] AND GEO dataset type[DataSet Type]",
         "gds sra[Filter] AND GEO entry type[Entry Type]",
     ]