Changeset 40172
- Timestamp:
- Oct 16, 2017, 11:32:55 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20170822/src/opihi/dvo/find_dups.c
r40171 r40172 1 1 # include "data.h" 2 // NOTE: if there are only a few uniq values, the old algorithm is not bad.3 // for 10000 uniq values, 30M points take ~20sec in the new algorithm,4 // 3M points takess 45 sec in the old method.5 2 6 /* given imageID and detID, make a 64bit joint ID and sort it*/7 int find_dups(int argc, char **argv) {3 /* given two 32bit IDs, a 64bit joint ID and sort it, along with an index (sequence) vector */ 4 int uniqpair (int argc, char **argv) { 8 5 9 int N new, i, N;10 Vector * ivec, *ovec;6 int N; 7 Vector *ID1vec = NULL, *ID2vec = NULL, *SEQvec = NULL, *OUTvec = NULL; 11 8 12 9 int VERBOSE = FALSE; … … 16 13 } 17 14 18 Vector *cvec = NULL; 15 Vector *SEQdup = NULL; 16 if ((N = get_argument (argc, argv, "-save-dups"))) { 17 remove_argument (N, &argc, argv); 18 if ((SEQdup = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) { 19 gprint (GP_ERR, "invalid vector %s\n", "SEQdups"); 20 return FALSE; 21 } 22 remove_argument (N, &argc, argv); 23 } 24 25 Vector *CNTvec = NULL; 19 26 if ((N = get_argument (argc, argv, "-c"))) { 20 27 remove_argument (N, &argc, argv); 21 if (( cvec = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) {28 if ((CNTvec = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) { 22 29 gprint (GP_ERR, "invalid vector %s\n", argv[N]); 23 30 return FALSE; … … 26 33 } 27 34 28 if (argc != 3) {29 gprint (GP_ERR, "USAGE: find_dups (ID1) (ID2) (sequence) (out) -c count\n");35 if (argc != 5) { 36 gprint (GP_ERR, "USAGE: uniqpair (ID1) (ID2) (IDout) -c count\n"); 30 37 return (FALSE); 31 38 } 32 39 33 40 if ((ID1vec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 34 if ((ID2vec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);35 if (( SEQvec = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE);41 if ((ID2vec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE); 42 if ((OUTvec = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE); 36 43 37 if ((ID1vec->type == OPIHI_FLT) || (ID2vec->type == OPIHI_FLT) || (ID1vec->type == OPIHI_FLT)) { 38 gprint (GP_ERR, "ERROR: ID and sequence vectors much be int\n"); 44 if ((ID1vec->type == OPIHI_FLT) || (ID2vec->type == OPIHI_FLT)) { 45 gprint (GP_ERR, "ERROR: ID vectors much be int\n"); 46 return (FALSE); 47 } 48 if (ID1vec->Nelements != ID2vec->Nelements) { 49 gprint (GP_ERR, "ERROR: ID vectors not all the same length\n"); 39 50 return (FALSE); 40 51 } 41 52 42 /* allocate the maximum possible needed */ 43 ResetVector (ovec, ivec->type, ivec->Nelements); 44 if (cvec) { 45 ResetVector (cvec, OPIHI_INT, ivec->Nelements); 53 // storage for the output and count vectors 54 int Nout = 0; 55 int NOUT = 10000; 56 ResetVector (OUTvec, OPIHI_INT, NOUT); 57 if (CNTvec) { 58 ResetVector (CNTvec, OPIHI_INT, NOUT); 46 59 } 47 60 48 Nnew = 0; 49 50 // generate the joined vector 51 61 // storage for the duplicate sequences 62 int NseqDup = 0; 63 int NSEQDUP = 10000; 64 if (SEQdup) { 65 ResetVector (SEQdup, OPIHI_INT, NSEQDUP); 66 } 52 67 53 // copy the input data to a temporary array to avoid damaging it with sort68 // incrementing pointers to the input IDs 54 69 opihi_int *ID1 = ID1vec->elements.Int; 55 70 opihi_int *ID2 = ID2vec->elements.Int; 56 71 72 // generate the joined and sequence vectors 57 73 opihi_int *IDfull = NULL; 74 opihi_int *SEQdata = NULL; 58 75 ALLOCATE (IDfull, opihi_int, ID1vec->Nelements); 59 for (i = 0; i < ID1vec->Nelements; i++) { 76 ALLOCATE (SEQdata, opihi_int, SEQvec[0].Nelements); 77 for (int i = 0; i < ID1vec->Nelements; i++) { 60 78 IDfull[i] = ID1[i] + (ID2[i] << 32); 79 SEQdata[i] = i; 61 80 } 62 81 63 llsorttwo (IDfull, SEQ vec->elements.Int, ivec->Nelements);82 llsorttwo (IDfull, SEQdata, ID1vec->Nelements); 64 83 65 Nnew = 0; 66 opihi_int *vtgt = ovec[0].elements.Int; 67 84 opihi_int *vtgt = OUTvec->elements.Int; 68 85 opihi_int *vsrc = IDfull; 69 opihi_int *vidx = SEQvec->elements.Int;70 86 71 87 int onePercent = ID1vec->Nelements / 100; 72 88 73 /* ADD sequence to output74 do not allocate all memory to start75 */76 77 89 struct sigaction *old_sigaction = SetInterrupt(); 78 for (i = 0; (i < ID1vec->Nelements) && !interrupt; Nnew++) { 79 vtgt[Nnew] = *vsrc; 90 for (int i = 0; (i < ID1vec->Nelements) && !interrupt; Nout++) { 91 if (Nout >= NOUT) { 92 NOUT += 10000; 93 REALLOCATE (vtgt, opihi_int, NOUT); 94 if (CNTvec) { 95 REALLOCATE (CNTvec->elements.Int, opihi_int, NOUT); 96 } 97 } 98 vtgt[Nout] = *vsrc; 80 99 int Ndup = 0; 81 100 opihi_int lastValue = *vsrc; … … 86 105 if (VERBOSE && (i % onePercent == 0)) gprint (GP_ERR, "."); 87 106 } 88 if (cvec) { 89 cvec->elements.Int[Nnew] = Ndup; 107 if (CNTvec) { 108 CNTvec->elements.Int[Nout] = Ndup; 109 } 110 if (SEQdup && (Ndup > 1)) { 111 // we want to save SEQdata values for the duplicates 112 // SEQdata[i-Ndup] .. SEQdata[i-N 113 for (j = i - Ndup; j < i; j++) { 114 SEQdup->elements.Int[NseqDup] = SEQdata[j]; 115 NseqDup ++; 116 if (NseqDup >= NSEQDUP) { 117 NSEQDUP += 10000; 118 REALLOCATE (SEQdup->elements.Int, opihi_int, NSEQDUP); 119 } 120 } 90 121 } 91 122 } 92 123 ClearInterrupt (old_sigaction); 93 124 if (VERBOSE) gprint (GP_ERR, "\n"); 94 free (indata);95 125 96 // free up extra memory 97 ResetVector (ovec, ivec->type, Nnew); 98 if (cvec) ResetVector (cvec, OPIHI_INT, Nnew); 126 free (SEQdata); 127 free (IDfull); 128 129 if (SEQdup) { 130 SEQdup->Nelements = NseqDup; 131 REALLOCATE (SEQdup->elements.Int, opihi_int, Nseqdup); 132 } 133 134 // fix references and free up extra memory: 135 OUTvec->elements.Int = vtgt; 136 ResetVector (OUTvec, OPIHI_INT, Nout); 137 if (cvec) ResetVector (cvec, OPIHI_INT, Nout); 99 138 100 139 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
