| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eeadc2f commit 5868d90
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,28 +12,34 @@ | |||
| 12 | 12 | import java.io.UncheckedIOException; | |
| 13 | 13 | import java.nio.file.Files; | |
| 14 | 14 | import java.nio.file.Paths; | |
| 15 | + import java.util.ArrayList; | ||
| 16 | + import java.util.Collections; | ||
| 15 | 17 | import java.util.Date; | |
| 16 | 18 | import java.util.List; | |
| 17 | 19 | import java.util.concurrent.atomic.AtomicInteger; | |
| 18 | - import java.util.stream.Stream; | ||
| 20 | + import java.util.regex.Pattern; | ||
| 19 | 21 | import java.util.zip.GZIPInputStream; | |
| 20 | 22 | ||
| 21 | 23 | import static org.junit.Assert.*; | |
| 22 | 24 | ||
| 23 | 25 | public class CifFileConsumerImplTest { | |
| 24 | - /** | ||
| 25 | - * java.lang.NumberFormatException: multiple points have been thrown. | ||
| 26 | - */ | ||
| 27 | 26 | @Test | |
| 28 | 27 | @Ignore("ignored for now as Bcif file source may change - currently using local files") | |
| 29 | - public void testNumberFormat() { | ||
| 30 | - Stream.of("1z4s", "4hec", "1dzw", "2y28").forEach(pdbId -> { | ||
| 31 | - System.out.println(pdbId); | ||
| 32 | - Structure cif = loadLocalCif(pdbId); | ||
| 33 | - assertNumberFormat(cif); | ||
| 34 | - Structure bcif = loadLocalBcif(pdbId); | ||
| 35 | - assertNumberFormat(bcif); | ||
| 36 | - }); | ||
| 28 | + public void testFailingEntries() { | ||
| 29 | + Pattern.compile(", ").splitAsStream("4he8, 1z4u, 4fp1, 1blc, 4cit, 2y2y, 4exq, 2n0f, 2d9o, 2v16, 1kqv, " + | ||
| 30 | + "1bwo, 2k2g, 1qhd, 5mhj, 2dn3, 5pq8, 5cay, 6ms1, 2vhu, 2gi0, 3swe, 3daz, 5yel, 2pxp, 4uis, 3cs1, 3in5," + | ||
| 31 | + " 1sl3, 4hjc, 3hj2, 5kpi, 1gyq, 1yq8, 4yqz, 1ox3, 2pls, 1vne, 4q02, 1dtt, 1jau, 5h3b, 5sxk, 4el7, 5q7w," + | ||
| 32 | + " 4zuz, 1n6i, 1dhg, 3dhe, 2gpo, 5if7, 5ld8, 1jhz, 4fr3, 1r6u, 3hdl, 5fse, 1iho, 1t10, 2oc6, 3czx, 3b3o," + | ||
| 33 | + " 5i6w, 2ecv, 4l2x, 441d, 2i0x, 1xq4, 3tbb, 4mmz, 1qew, 6i16, 1t8d, 5w7r, 6gm1, 1s7u, 2qp3, 1cf3, 4myb," + | ||
| 34 | + " 1omh, 1zog, 2b68, 1nqb, 1t7k") | ||
| 35 | + .parallel() | ||
| 36 | + .forEach(pdbId -> { | ||
| 37 | + System.out.println(pdbId); | ||
| 38 | + Structure cif = loadLocalCif(pdbId); | ||
| 39 | + assertNumberFormat(cif); | ||
| 40 | + Structure bcif = loadLocalBcif(pdbId); | ||
| 41 | + assertNumberFormat(bcif); | ||
| 42 | + }); | ||
| 37 | 43 | } | |
| 38 | 44 | ||
| 39 | 45 | private Structure loadLocalCif(String pdbId) { | |
@@ -63,13 +69,21 @@ private void assertNumberFormat(Structure structure) { | |||
| 63 | 69 | assertNotNull(modDate); | |
| 64 | 70 | } | |
| 65 | 71 | ||
| 72 | + /** | ||
| 73 | + * Performance diary; | ||
| 74 | + * | ||
| 75 | + * 05/01/19 - ciftools v0.3.0, parallel, bcif, non-gzipped, 12 worker threads | ||
| 76 | + * 918 s for 151079 structures, 6073 µs per structure, failed for 0 entries | ||
| 77 | + * | ||
| 78 | + * @throws IOException propagated | ||
| 79 | + */ | ||
| 66 | 80 | @Test | |
| 67 | 81 | @Ignore("ignore long-running test, do run to track performance") | |
| 68 | 82 | public void parseEntireArchive() throws IOException { | |
| 69 | 83 | AtomicInteger counter = new AtomicInteger(0); | |
| 70 | - AtomicInteger failed = new AtomicInteger(0); | ||
| 71 | 84 | long start = System.nanoTime(); | |
| 72 | 85 | int chunkSize = 250; | |
| 86 | + List<String> failed = Collections.synchronizedList(new ArrayList<>()); | ||
| 73 | 87 | ||
| 74 | 88 | Files.walk(Paths.get( | |
| 75 | 89 | // change to your own paths | |
@@ -93,13 +107,14 @@ public void parseEntireArchive() throws IOException { | |||
| 93 | 107 | } catch (Exception e) { | |
| 94 | 108 | System.err.println("failed for " + path.toFile().getAbsolutePath()); | |
| 95 | 109 | e.printStackTrace(); | |
| 96 | - failed.incrementAndGet(); | ||
| 110 | + failed.add(path.toFile().getName().split("\\.")[0]); | ||
| 97 | 111 | } | |
| 98 | 112 | }); | |
| 99 | 113 | ||
| 100 | 114 | long end = System.nanoTime(); | |
| 101 | 115 | System.out.println((end - start) / 1_000_000_000 + " s"); | |
| 102 | - System.out.println("failed for " + failed.intValue() + " structures"); | ||
| 116 | + System.out.println("failed for " + failed.size() + " structures"); | ||
| 117 | + System.out.println("failed ids: " + failed); | ||
| 103 | 118 | } | |
| 104 | 119 | ||
| 105 | 120 | private static boolean headerOnly; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,11 @@ | |||
| 18 | 18 | import org.slf4j.LoggerFactory; | |
| 19 | 19 | ||
| 20 | 20 | import javax.vecmath.Matrix4d; | |
| 21 | - import java.text.ParseException; | ||
| 22 | - import java.text.SimpleDateFormat; | ||
| 21 | + import java.time.LocalDate; | ||
| 22 | + import java.time.LocalDateTime; | ||
| 23 | + import java.time.ZoneId; | ||
| 24 | + import java.time.format.DateTimeFormatter; | ||
| 25 | + import java.time.format.DateTimeFormatterBuilder; | ||
| 23 | 26 | import java.util.*; | |
| 24 | 27 | import java.util.stream.Collectors; | |
| 25 | 28 | import java.util.stream.IntStream; | |
@@ -37,7 +40,10 @@ | |||
| 37 | 40 | */ | |
| 38 | 41 | class CifFileConsumerImpl implements CifFileConsumer<Structure> { | |
| 39 | 42 | private static final Logger logger = LoggerFactory.getLogger(CifFileConsumerImpl.class); | |
| 40 | - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US); | ||
| 43 | + private static final DateTimeFormatter DATE_FORMAT = new DateTimeFormatterBuilder() | ||
| 44 | + .parseCaseInsensitive() | ||
| 45 | + .appendPattern("yyyy-MM-dd") | ||
| 46 | + .toFormatter(Locale.US); | ||
| 41 | 47 | ||
| 42 | 48 | private Structure structure; | |
| 43 | 49 | private Chain currentChain; | |
@@ -524,36 +530,24 @@ public void consumeDatabasePDBremark(DatabasePDBRemark databasePDBremark) { | |||
| 524 | 530 | } | |
| 525 | 531 | } | |
| 526 | 532 | ||
| 533 | + private Date convert(LocalDate localDate) { | ||
| 534 | + return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); | ||
| 535 | + } | ||
| 536 | + | ||
| 527 | 537 | @Override | |
| 528 | 538 | public void consumeDatabasePDBrev(DatabasePDBRev databasePDBrev) { | |
| 529 | 539 | logger.debug("got a database revision:" + databasePDBrev); | |
| 530 | 540 | ||
| 531 | 541 | for (int rowIndex = 0; rowIndex < databasePDBrev.getRowCount(); rowIndex++) { | |
| 532 | 542 | if (databasePDBrev.getNum().get(rowIndex) == 1) { | |
| 533 | 543 | String dateOriginal = databasePDBrev.getDateOriginal().get(rowIndex); | |
| 534 | - try { | ||
| 535 | - Date dep = DATE_FORMAT.parse(dateOriginal); | ||
| 536 | - pdbHeader.setDepDate(dep); | ||
| 537 | - } catch (ParseException e){ | ||
| 538 | - logger.warn("Could not parse date string '{}', deposition date will be unavailable", | ||
| 539 | - dateOriginal); | ||
| 540 | - } | ||
| 544 | + pdbHeader.setDepDate(convert(LocalDate.parse(dateOriginal, DATE_FORMAT))); | ||
| 541 | 545 | ||
| 542 | 546 | String date = databasePDBrev.getDate().get(rowIndex); | |
| 543 | - try { | ||
| 544 | - Date rel = DATE_FORMAT.parse(date); | ||
| 545 | - pdbHeader.setRelDate(rel); | ||
| 546 | - } catch (ParseException e){ | ||
| 547 | - logger.warn("Could not parse date string '{}', modification date will be unavailable", date); | ||
| 548 | - } | ||
| 547 | + pdbHeader.setRelDate(convert(LocalDate.parse(date, DATE_FORMAT))); | ||
| 549 | 548 | } else { | |
| 550 | 549 | String dbrev = databasePDBrev.getDate().get(rowIndex); | |
| 551 | - try { | ||
| 552 | - Date mod = DATE_FORMAT.parse(dbrev); | ||
| 553 | - pdbHeader.setModDate(mod); | ||
| 554 | - } catch (ParseException e){ | ||
| 555 | - logger.warn("Could not parse date string '{}', modification date will be unavailable", dbrev); | ||
| 556 | - } | ||
| 550 | + pdbHeader.setModDate(convert(LocalDate.parse(dbrev, DATE_FORMAT))); | ||
| 557 | 551 | } | |
| 558 | 552 | } | |
| 559 | 553 | } | |
@@ -677,23 +671,13 @@ public void consumePdbxAuditRevisionHistory(PdbxAuditRevisionHistory pdbxAuditRe | |||
| 677 | 671 | // first entry in revision history is the release date | |
| 678 | 672 | if (pdbxAuditRevisionHistory.getOrdinal().get(rowIndex) == 1) { | |
| 679 | 673 | String release = pdbxAuditRevisionHistory.getRevisionDate().get(rowIndex); | |
| 680 | - try { | ||
| 681 | - Date releaseDate = DATE_FORMAT.parse(release); | ||
| 682 | - pdbHeader.setRelDate(releaseDate); | ||
| 683 | - } catch (ParseException e) { | ||
| 684 | - logger.warn("Could not parse date string '{}', release date will be unavailable", release); | ||
| 685 | - } | ||
| 674 | + pdbHeader.setRelDate(convert(LocalDate.parse(release, DATE_FORMAT))); | ||
| 686 | 675 | } else { | |
| 687 | 676 | // all other dates are revision dates; | |
| 688 | 677 | // since this method may be called multiple times, | |
| 689 | 678 | // the last revision date will "stick" | |
| 690 | 679 | String revision = pdbxAuditRevisionHistory.getRevisionDate().get(rowIndex); | |
| 691 | - try { | ||
| 692 | - Date revisionDate = DATE_FORMAT.parse(revision); | ||
| 693 | - pdbHeader.setModDate(revisionDate); | ||
| 694 | - } catch (ParseException e) { | ||
| 695 | - logger.warn("Could not parse date string '{}', revision date will be unavailable", revision); | ||
| 696 | - } | ||
| 680 | + pdbHeader.setModDate(convert(LocalDate.parse(revision, DATE_FORMAT))); | ||
| 697 | 681 | } | |
| 698 | 682 | } | |
| 699 | 683 | } | |
@@ -710,13 +694,7 @@ public void consumePdbxDatabaseStatus(PdbxDatabaseStatus pdbxDatabaseStatus) { | |||
| 710 | 694 | StrColumn recvdInitialDepositionDate = pdbxDatabaseStatus.getRecvdInitialDepositionDate(); | |
| 711 | 695 | if (recvdInitialDepositionDate.isDefined()) { | |
| 712 | 696 | String deposition = recvdInitialDepositionDate.get(rowIndex); | |
| 713 | - | ||
| 714 | - try { | ||
| 715 | - Date depositionDate = DATE_FORMAT.parse(deposition); | ||
| 716 | - pdbHeader.setDepDate(depositionDate); | ||
| 717 | - } catch (ParseException e) { | ||
| 718 | - logger.warn("Could not parse date string '{}', deposition date will be unavailable", deposition); | ||
| 719 | - } | ||
| 697 | + pdbHeader.setDepDate(convert(LocalDate.parse(deposition, DATE_FORMAT))); | ||
| 720 | 698 | } | |
| 721 | 699 | } | |
| 722 | 700 | } | |
@@ -784,6 +762,7 @@ public void consumeRefine(Refine refine) { | |||
| 784 | 762 | // there are 2 resolution values, one for each method | |
| 785 | 763 | // we take the last one found so that behaviour is like in PDB file parsing | |
| 786 | 764 | double lsDResHigh = refine.getLsDResHigh().get(rowIndex); | |
| 765 | + // TODO this could use a check to keep reasonable values - 1.5 may be overwritten by 0.0 | ||
| 787 | 766 | if (pdbHeader.getResolution() != PDBHeader.DEFAULT_RESOLUTION) { | |
| 788 | 767 | logger.warn("More than 1 resolution value present, will use last one {} and discard previous {}", | |
| 789 | 768 | lsDResHigh, String.format("%4.2f",pdbHeader.getResolution())); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments