-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path138.java
More file actions
1282 lines (1118 loc) · 41.5 KB
/
Copy path138.java
File metadata and controls
1282 lines (1118 loc) · 41.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright 2012 EMBL-EBI, Hinxton outstation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package uk.ac.ebi.embl.api.validation.helper;
import org.apache.commons.lang.StringUtils;
import uk.ac.ebi.embl.api.AccessionMatcher;
import uk.ac.ebi.embl.api.contant.AnalysisType;
import uk.ac.ebi.embl.api.entry.Entry;
import uk.ac.ebi.embl.api.entry.Text;
import uk.ac.ebi.embl.api.entry.feature.Feature;
import uk.ac.ebi.embl.api.entry.feature.SourceFeature;
import uk.ac.ebi.embl.api.entry.location.Location;
import uk.ac.ebi.embl.api.entry.location.LocationFactory;
import uk.ac.ebi.embl.api.entry.qualifier.*;
import uk.ac.ebi.embl.api.entry.reference.Reference;
import uk.ac.ebi.embl.api.storage.CachedFileDataManager;
import uk.ac.ebi.embl.api.storage.DataManager;
import uk.ac.ebi.embl.api.storage.DataSet;
import uk.ac.ebi.embl.api.validation.*;
import uk.ac.ebi.embl.api.validation.check.CheckFileManager;
import uk.ac.ebi.embl.api.validation.plan.EmblEntryValidationPlanProperty;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static uk.ac.ebi.embl.api.AccessionMatcher.getSplittedAccession;
public class Utils {
private static Object FeatureFactory;
private final static String UTILS_2= "Utility_shift_Location_2";
private final static String UTILS_3 = "Utility_shift_Location_3";
private final static String UTILS_4 = "Utility_shift_Location_4";
private final static String UTILS_5 = "Utility_shift_Location_5";
private final static String UTILS_6= "Utility_shift_Location_6";
private static final String MESSAGE_KEY_MIN_NUMBER_OF_SEQUENCES_ERROR = "SequenceMinCountCheck";
private static final String MESSAGE_KEY_MAX_NUMBER_OF_SEQUENCES_ERROR = "SequenceMaxCountCheck";
private static final Pattern SHRINK = Pattern.compile(" {2,}");
private static final int MIN_CONTIG_CNT = 2;
private static final int MAX_CONTIG_CNT = 1000000;
private static final int MIN_SCAFFOLD_CNT = 1;
private static final int MAX_SCAFFOLD_CNT = 1000000;
private static final int MIN_CHROMOSOME_CNT = 1;
private static final int MAX_CHROMOSOME_CNT = 1260;
private static final DataManager dataManager = new CachedFileDataManager();
private static final CheckFileManager tsvFileManager = new CheckFileManager();
private static final Pattern entityNumberPattern = Pattern.compile("^&#([0-9]{2,3});$");
private static final Map<String, Character> entityNameToChar = new HashMap<String, Character>() {{
put("&", '&');
put("<", '<');
put(">", '>');
}};
private static final Pattern splitDigitsPattern = Pattern.compile("^(\\D+)(\\d+)$");
//prevent instantiation
private Utils() {
}
public static String paramArrayToString(Object[] array) {
StringBuilder result = new StringBuilder();
result.append("\"");
if (array != null) {
result.append(StringUtils.join(array, ", "));
}
result.append("\"");
return result.toString();
}
public static String paramArrayToCuratorTipString(Object[] array) {
StringBuilder result = new StringBuilder();
/**
* use " rather than ' as tooltip gizmo in webin does not like '
*/
result.append("\"");
if (array != null) {
result.append(StringUtils.join(array, ", "));
}
result.append("\"");
return result.toString();
}
public static String paramArrayToCuratorReportString(Object[] array) {
StringBuilder result = new StringBuilder();
result.append("\"");
if (array != null) {
result.append(StringUtils.join(array, ",\n"));
}
result.append("\"");
return result.toString();
}
/**
* Converts list of strings to an array.
*
* @param list a list of strings to be converted
* @return an array
*/
public static Object[] stringListToArray(List<String> list) {
Object[] params = null;
if (list != null) {
params = list.toArray(new String[list.size()]);
}
return params;
}
/**
* Check whether value NOT matches the pattern build with prefix, middle
* part and post-fixer.
*
* @param value a value to be checked
* @param prefix a prefix pattern
* @param middle a middle pattern
* @param postfix a post-fixer pattern
* @return true if value not matches pattern otherwise false
*/
public static boolean notMatches(String value, String prefix, String middle,
String postfix) {
return !matches(value, prefix, middle, postfix);
}
/**
* Check whether value matches the pattern build with prefix, middle part
* and post-fixer.
*
* @param value a value to be checked
* @param prefix a prefix pattern
* @param middle a middle pattern
* @param postfix a post-fixer pattern
* @return true if value matches pattern otherwise false
*/
public static boolean matches(String value, String prefix, String middle,
String postfix) {
String pattern = prefix + middle + postfix;
boolean result = value.matches(pattern);
return result;
}
/**
* It removes prefixes from values and compare remaining parts.
*
* @param value1 first value to be checked
* @param prefix1 prefix of the first value
* @param value2 second value to be checked
* @param prefix2 prefix of the second value
* @return true when both values without their prefixes are equal
*/
public static boolean matchesWithoutPrefixes(String value1, String prefix1,
String value2, String prefix2) {
if (!value1.startsWith(prefix1)) {
return false;
}
value1 = value1.substring(prefix1.length());
if (!value2.startsWith(prefix2)) {
return false;
}
value2 = value2.substring(prefix2.length());
return value1.equals(value2);
}
public static List<Text> stringsToTexts(List<String> strings, Origin origin){
List<Text> texts = new ArrayList<Text>();
for(String string : strings){
texts.add(new Text(string, origin));
}
return texts;
}
public static FlattenedMessageResult flattenMessages(List<ValidationMessage<Origin>> validationMessages,
int messageFlattenThreshold) {
Map<String, Integer> messageCounts = new HashMap<String, Integer>();
List<ValidationMessage> flattenedMessages = new ArrayList<ValidationMessage>();
List<ValidationMessage> unFlattenedMessages = new ArrayList<ValidationMessage>();
for (ValidationMessage<Origin> message : validationMessages) {
String messageKey = message.getMessageKey();
if (messageCounts.containsKey(messageKey)) {
Integer count = messageCounts.get(messageKey);
count += 1;
messageCounts.put(messageKey, count);
} else {
messageCounts.put(messageKey, 1);
}
}
for (ValidationMessage<Origin> message : validationMessages) {
String messageKey = message.getMessageKey();
if (messageCounts.containsKey(messageKey)) {
Integer count = messageCounts.get(messageKey);
if (count > messageFlattenThreshold) {
String messageExample = ValidationMessageManager.getString(messageKey);//get the unformatted message string
message.setMessage(messageExample + " (" + count + " occurrences)");//swap the message to contain the example message (unformatted)
flattenedMessages.add(message);
messageCounts.remove(messageKey);
} else {
unFlattenedMessages.add(message);
}
}
}
return new FlattenedMessageResult(flattenedMessages, unFlattenedMessages);
}
public static List<FlattenedValidationPlanResult> flattenValidationPlans(List<ValidationPlanResult> planResults) {
Map<String,FlattenedValidationPlanResult> resultsMap = new HashMap<String, FlattenedValidationPlanResult>();
for(ValidationPlanResult planResult : planResults){
if(resultsMap.containsKey(planResult.getTargetOrigin())){
FlattenedValidationPlanResult flattenedResult = resultsMap.get(planResult.getTargetOrigin());
flattenedResult.append(planResult);
}else{
resultsMap.put(planResult.getTargetOrigin(), new FlattenedValidationPlanResult(planResult));
}
}
return new ArrayList<FlattenedValidationPlanResult>(resultsMap.values());
}
public static String parseTSVString(String input){
if(input.equals("(null)")){
return null;
}
return input.trim();
}
/**
* Shifting the feature Locations according to the new sequence locations
*
* @param entry
* @param deletedBeginNs
* (number of deleted 'n's at the beginning of sequence)
*
* @return ArrayList (Validation Messages)
*/
public static ArrayList<ValidationMessage> shiftLocation(Entry entry,
int deletedBeginNs,boolean removeall) {
ArrayList<Feature> gapFeatures = new ArrayList<Feature>();
ArrayList<Feature> invalidFeatures = new ArrayList<Feature>();
ArrayList<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
if (entry == null) {
return null;
}
List<Feature> features = entry.getFeatures();
for (int i = 0; i < features.size(); i++) {
Feature feature = features.get(i);
boolean invalidFeature = false;
// New Sequence String Length
long newSequenceLength = entry.getSequence().getLength();
for (Location location : feature.getLocations().getLocations()) {
/*
* check for all feature locations exists in the entry are
* within range of sequence Begin and End positions and shifting
* the locations of the feature according to the new sequence
* positions
*/
if (location.getBeginPosition() <= deletedBeginNs
&& location.getEndPosition() <= deletedBeginNs) {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
if (feature.getName().equals(Feature.GAP_FEATURE_NAME)) {
validationMessages.add(ValidationMessage.message(
Severity.FIX, UTILS_2, location
.getBeginPosition().toString(),
location.getEndPosition().toString()));
gapFeatures.add(feature);
invalidFeature = true;
} else {
if(feature!=null&&!feature.getName().equals(Feature.SOURCE_FEATURE_NAME))
{
invalidFeatures.add(feature);
invalidFeature = true;
}
}
} else if (location.getBeginPosition() <= deletedBeginNs
&& location.getEndPosition() > deletedBeginNs) {
location.setBeginPosition((long) 1);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
if (location.getEndPosition() > newSequenceLength)
{
location.setEndPosition(newSequenceLength);
}
} else if (location.getBeginPosition() > deletedBeginNs
&& location.getEndPosition() > deletedBeginNs) {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
if (location.getBeginPosition() > newSequenceLength
&& location.getEndPosition() > newSequenceLength) {
if (feature.getName().equals(Feature.GAP_FEATURE_NAME)) {
gapFeatures.add(feature);
ValidationMessage<Origin> message = ValidationMessage.message(
Severity.FIX, UTILS_2, location.getBeginPosition().toString(),
location.getEndPosition().toString());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
invalidFeature = true;
}
else {
if(feature!=null&&!feature.getName().equals(Feature.SOURCE_FEATURE_NAME))
{
invalidFeatures.add(feature);
invalidFeature = true;
}
}
}
if (location.getBeginPosition() <= newSequenceLength
&& location.getEndPosition() > newSequenceLength)
{
location.setEndPosition(newSequenceLength);
}
}
if (location.getBeginPosition().equals(location.getEndPosition())) {
if(removeall)
{
location.setEndPosition(null);
}
else{
if (feature.getName().equals(Feature.GAP_FEATURE_NAME)) {
gapFeatures.add(feature);
ValidationMessage<Origin> message = ValidationMessage.message(
Severity.FIX, UTILS_2, location.getBeginPosition().toString(),
location.getEndPosition().toString());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
invalidFeature = true;
} else {
if(feature!=null&&!feature.getName().equals(Feature.SOURCE_FEATURE_NAME))
{
invalidFeatures.add(feature);
invalidFeature = true;
}
}
}
}
}
// Reference Location shifting
shiftReferenceLocation(entry , newSequenceLength);
//set the new sequencelength
//entry.getSequence().setLength(newSequenceLength);
// Qualifier Location Shifting
Long newBeginLocation, newEndLocation = null;
Location newLocation = null;
if (!invalidFeature) {
for (Qualifier qualifier : feature.getQualifiers()) {
// TRANSL_EXCEPT_QUALIFIER
if (qualifier.getName().equals(
Qualifier.TRANSL_EXCEPT_QUALIFIER_NAME)) {
TranslExceptQualifier translExcepttqualifier = new TranslExceptQualifier(
qualifier.getValue());
/*if (shiftLocationQualifier(translExcepttqualifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
translExcepttqualifier, deletedBeginNs,
feature));
}*/
} /*else if (qualifier.getName().equals(
Qualifier.ANTICODON_QUALIFIER_NAME)) {
AnticodonQualifier antiCodonqualifier = new AnticodonQualifier(
qualifier.getValue());
if (shiftLocationQualifier(antiCodonqualifier,
deletedBeginNs, feature) != null) {
validationMessages
.add(shiftLocationQualifier(
antiCodonqualifier, deletedBeginNs,
feature));
}
} */else if (qualifier.getName().equals(
Qualifier.RPT_UNIT_RANGE_QUALIFIER_NAME)) {
Rpt_Unit_RangeQualifier rptUnitRangequalifier = new Rpt_Unit_RangeQualifier(
qualifier.getValue());
if (shiftLocationQualifier(rptUnitRangequalifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
rptUnitRangequalifier, deletedBeginNs,
feature));
}
}
else if (qualifier.getName().equals(
Qualifier.TAG_PEPTIDE_QUALIFIER_NAME)) {
Tag_PeptideQualifier tagPeptidequalifier = new Tag_PeptideQualifier(
qualifier.getValue());
if (shiftLocationQualifier(tagPeptidequalifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
tagPeptidequalifier, deletedBeginNs,
feature));
}
}
}
}
}
if (gapFeatures.size() > 0) {
for (Feature feature : gapFeatures) {
entry.removeFeature(feature);
}
}
if (invalidFeatures.size() > 0) {
for (Feature feature : invalidFeatures) {
ValidationMessage<Origin> message = ValidationMessage.message(
Severity.FIX, UTILS_5, feature.getName(),
feature.getName());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
entry.removeFeature(feature);
}
}
return validationMessages;
}
public static ValidationMessage shiftLocationQualifier(
LocationQualifier qualifier, long deletedBeginNs, Feature feature) {
Long newBeginLocation = null, newEndLocation = null;
Location newLocation = null;
List<Location> locationsList = null;
locationsList = feature.getLocations().getLocations();
long featureNewBeginLocation = 0;
long featureNewEndLocation = 0;
for (Location location : locationsList) {
featureNewBeginLocation = location.getBeginPosition();
featureNewEndLocation = location.getEndPosition();
}
try {
LocationFactory factory = new LocationFactory();
if (qualifier.getLocation().getBeginPosition() >= deletedBeginNs) {
newBeginLocation = qualifier.getLocation().getBeginPosition()
- deletedBeginNs;
if (!(qualifier.getLocation().getEndPosition() == null)) {
newEndLocation = qualifier.getLocation().getEndPosition()
- deletedBeginNs;
// if the new Qualifier Location is in between new
// feature locations set the new locations to the
// qualifier
if (newBeginLocation >= featureNewBeginLocation
&& newEndLocation <= featureNewEndLocation) {
newLocation = factory.createLocalRange(
newBeginLocation, newEndLocation);
qualifier.setLocation(newLocation);
}
else {
return ValidationMessage.message(Severity.ERROR,
UTILS_3, qualifier.getName(), newBeginLocation,
newEndLocation);
}
}
else {
if (newBeginLocation > featureNewBeginLocation
&& newBeginLocation < featureNewEndLocation) {
newBeginLocation = qualifier.getLocation()
.getBeginPosition() - deletedBeginNs;
newLocation = factory.createLocalBase(newBeginLocation);
qualifier.setLocation(newLocation);
} else {
return ValidationMessage.message(Severity.ERROR,
UTILS_3, qualifier.getName(), newBeginLocation,
newEndLocation);
}
}
} else {
newBeginLocation = qualifier.getLocation().getBeginPosition()
- deletedBeginNs;
newEndLocation = qualifier.getLocation().getEndPosition()
- deletedBeginNs;
return ValidationMessage.message(Severity.ERROR, UTILS_3,
qualifier.getName(), newBeginLocation, newEndLocation);
}
} catch (ValidationException e) {
e.printStackTrace();
}
return null;
}
// Reference Location shifting
public static ValidationMessage shiftReferenceLocation(Entry entry,
long newSequenceLength) {
Collection<Reference> references = entry.getReferences();
for (Reference reference : references) {
for (Location rlocation : reference.getLocations().getLocations()) {
{
rlocation.setEndPosition(newSequenceLength);
if (rlocation.getBeginPosition().equals(
rlocation.getEndPosition())) {
return ValidationMessage.message(Severity.WARNING,
UTILS_6, rlocation.getBeginPosition(),
rlocation.getEndPosition());
}
}
}
}
return null;
}
/**
* Shifting the feature Locations according to the new sequence locations
* and remove the features which have been placed fully inside the 'n' start
* and end.
*
* @param entry
* @param deletedBeginNs
* (number of deleted 'n's at the beginning of sequence)
*
* @return ArrayList (Validation Messages)
*/
public static ArrayList<ValidationMessage> shiftAndRemoveFeature(
Entry entry, int deletedBeginNs) {
List<Location> locationsList = null;
ArrayList<Feature> gapFeatures = new ArrayList();
ArrayList<ValidationMessage> validationMessages = new ArrayList();
long featureNewBeginLocation = 0;
long featureNewEndLocation = 0;
if (entry == null) {
return null;
}
List<Feature> features = entry.getFeatures();
for (int i = 0; i < features.size(); i++) {
Feature feature = features.get(i);
locationsList = feature.getLocations().getLocations();
boolean invalidFeature = false;
// New Sequence String Length
long newSequenceLength = entry.getSequence().getLength();
for (int j = 0; j < feature.getLocations().getLocations().size(); j++) {
// for (Location location :
// feature.getLocations().getLocations()) {
boolean position = false;
Location location = feature.getLocations().getLocations()
.get(j);
/*
* check for all feature locations exists in the entry are
* within range of sequence Begin and End positions and shifting
* the locations of the feature according to the new sequence
* positions
*/
// check1
if (location.getBeginPosition() == location.getEndPosition()) {
position = true;
}
if (location.getBeginPosition() <= deletedBeginNs
&& location.getEndPosition() <= deletedBeginNs) {
if (position) {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
} else {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
}
if (feature.getName().equals(Feature.GAP_FEATURE_NAME)) {
validationMessages.add(ValidationMessage.message(
Severity.FIX, UTILS_2, location
.getBeginPosition().toString(),
location.getEndPosition().toString()));
gapFeatures.add(feature);
invalidFeature = true;
} else {
// entry.removeFeature(feature);
feature.getLocations().removeLocation(location);
j = j - 1;
ValidationMessage<Origin> message = ValidationMessage
.message(Severity.FIX, UTILS_4, feature
.getName(), location.getBeginPosition()
.toString(), location.getEndPosition()
.toString());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
invalidFeature = true;
// continue;
}
} else if (location.getBeginPosition() <= deletedBeginNs
&& location.getEndPosition() > deletedBeginNs) {
location.setBeginPosition((long) 1);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
if (location.getEndPosition() > newSequenceLength)
{
location.setEndPosition(newSequenceLength);
}
} else if (location.getBeginPosition() > deletedBeginNs
&& location.getEndPosition() > deletedBeginNs) {
if (position) {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
} else {
location.setBeginPosition(location.getBeginPosition()
- deletedBeginNs);
location.setEndPosition(location.getEndPosition()
- deletedBeginNs);
}
if (location.getBeginPosition() > newSequenceLength
&& location.getEndPosition() > newSequenceLength) {
if (feature.getName().equals(Feature.GAP_FEATURE_NAME)) {
gapFeatures.add(feature);
ValidationMessage<Origin> message = ValidationMessage
.message(Severity.FIX, UTILS_2, location
.getBeginPosition().toString(),
location.getEndPosition()
.toString());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
invalidFeature = true;
}
else {
feature.getLocations().removeLocation(location);
j = j - 1;
ValidationMessage<Origin> message = ValidationMessage
.message(Severity.FIX, UTILS_4, feature
.getName(), location
.getBeginPosition().toString(),
location.getEndPosition()
.toString());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
invalidFeature = true;
// continue;
}
}
if (location.getBeginPosition() <= newSequenceLength
&& location.getEndPosition() > newSequenceLength)
{
location.setEndPosition(newSequenceLength);
}
}
}
if (feature.getLocations().getLocations().isEmpty()) {
ValidationMessage<Origin> message = ValidationMessage.message(
Severity.FIX, UTILS_5, feature.getName(),
feature.getName());
message.getOrigins().add(feature.getOrigin());
validationMessages.add(message);
removeFeatureQualifiers(feature);
entry.removeFeature(feature);
i = i - 1;
}
locationsList = feature.getLocations().getLocations();
for (Location location : locationsList) {
featureNewBeginLocation = location.getBeginPosition();
featureNewEndLocation = location.getEndPosition();
}
// Qualifier Location Shifting
Long newBeginLocation, newEndLocation = null;
Location newLocation = null;
if (!invalidFeature) {
for (Qualifier qualifier : feature.getQualifiers()) {
// TRANSL_EXCEPT_QUALIFIER
/*if (qualifier.getName().equals(
qualifier.TRANSL_EXCEPT_QUALIFIER_NAME)) {
TranslExceptQualifier translExcepttqualifier = new TranslExceptQualifier(
qualifier.getValue());
if (shiftLocationQualifier(translExcepttqualifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
translExcepttqualifier, deletedBeginNs,
feature));
}
}else if (qualifier.getName().equals(
qualifier.ANTICODON_QUALIFIER_NAME)) {
AnticodonQualifier antiCodonqualifier = new AnticodonQualifier(
qualifier.getValue());
if (shiftLocationQualifier(antiCodonqualifier,
deletedBeginNs, feature) != null) {
validationMessages
.add(shiftLocationQualifier(
antiCodonqualifier, deletedBeginNs,
feature));
}
}*/ if (qualifier.getName().equals(
qualifier.RPT_UNIT_RANGE_QUALIFIER_NAME)) {
Rpt_Unit_RangeQualifier rptUnitRangequalifier = new Rpt_Unit_RangeQualifier(
qualifier.getValue());
if (shiftLocationQualifier(rptUnitRangequalifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
rptUnitRangequalifier, deletedBeginNs,
feature));
}
}
else if (qualifier.getName().equals(
qualifier.TAG_PEPTIDE_QUALIFIER_NAME)) {
Tag_PeptideQualifier tagPeptidequalifier = new Tag_PeptideQualifier(
qualifier.getValue());
if (shiftLocationQualifier(tagPeptidequalifier,
deletedBeginNs, feature) != null) {
validationMessages.add(shiftLocationQualifier(
tagPeptidequalifier, deletedBeginNs,
feature));
}
}
}
}
}
if (gapFeatures.size() > 0) {
for (Feature feature : gapFeatures) {
entry.removeFeature(feature);
}
}
return validationMessages;
}
public static void removeFeatureQualifiers(Feature feature) {
List<Qualifier> qualifier = new ArrayList<Qualifier>();
List<String> qualNames = new ArrayList<String>();
qualifier = feature.getQualifiers();
for (Qualifier qual : qualifier) {
qualNames.add(qual.getName());
}
for (String name : qualNames) {
feature.removeSingleQualifier(name);
}
}
/** Trims the string and replaces runs of whitespace with a single space.
*/
public static String shrink(String string) {
if (string == null) {
return null;
}
string = string.trim();
return SHRINK.matcher(string).replaceAll(" ");
}
/**
* Split the string into values using the regular expression, removes
* whitespace from the beginning and end of the resultant strings and
* replaces runs of whitespace with a single space.
*/
public static Vector<String> split(String string, String regex)
{
Vector<String> strings = new Vector<String>();
for (String value : string.split(new String(regex)))
{
value = value.trim();
if (!value.equals(""))
{
strings.add(shrink(value));
}
}
return strings;
}
/*
* returns the comment line checklist map having key,value pairs for each checklist
*/
public static HashMap<String, HashMap<String, String>> getCommentCheckList(Entry entry)
{
String comment = entry.getComment().getText();
String[] tempComment = new String[3];
int start = comment.indexOf("##");
String CheckListString = comment.substring(start + 2, comment.length());
String[] commentChecklists = CheckListString.split("##");
HashMap<String, HashMap<String, String>> ckeckListMap = new HashMap<String, HashMap<String, String>>();
for (int i = 0; i < commentChecklists.length; i = i + 4)
{
HashMap<String, String> keyVal = new HashMap<String, String>();
tempComment = Arrays.copyOfRange(commentChecklists, i, i + 3);
String key = tempComment[0].replaceAll("-Data-START", "");
String keyValues = tempComment[1];
String[] keyvalue = keyValues.split("\n");
for (int j = 1; j < keyvalue.length; j++)
{
keyVal.put(keyvalue[j].split("::")[0], keyvalue[j].split("::")[1]);
}
ckeckListMap.put(key, keyVal);
}
return ckeckListMap;
}
public static String getValidFeatureName(String featureName)
{
DataSet dataSet = dataManager.getDataSet(tsvFileManager.filePath(FileName.FEATURE_KEYS, false));
if (!dataSet.contains(0, featureName))
{
if (dataSet.findRowIgnoreCase(0, featureName) != null)
{
return dataSet.findRowIgnoreCase(0, featureName).getString(0);
}
}
return featureName;
}
public static ValidationScope getValidaionScope(String scope)
{
if (scope == null)
{
return ValidationScope.EMBL;
}
return ValidationScope.get(scope);
}
public static String getComponentTypeId(Entry contigEntry)
{
String componentTypeId=null;
if(Entry.WGS_DATACLASS.equals(contigEntry.getDataClass()))
{
componentTypeId="W";
}
else if(Entry.HTG_DATACLASS.equals(contigEntry.getDataClass()))
{
List<String> componentTypeIds= new ArrayList<String>();
List<Text> keywords=contigEntry.getKeywords();
for(Text keywordtext:keywords)
{
String keyword= keywordtext.getText();
if(keyword.contains("PHASE1")||keyword.contains("PHASE0")||keyword.contains("PHASE2"))
{
componentTypeIds.add("P");
}
if(keyword.contains("PHASE3"))
{
componentTypeIds.add("F");
}
if(keyword.contains("DRAFT")||keyword.contains("FULLTOP"))
{
componentTypeIds.add("D");
}
if(keyword.contains("ACTIVEFIN"))
{
componentTypeIds.add("A");
}
else
{
componentTypeIds.add("O");
}
}
if(componentTypeIds.size()==0)
{
componentTypeId="O";
}
if(componentTypeIds.size()==1)
{
componentTypeId=componentTypeIds.get(0);
}
else
{ // F > A > D > P
if (componentTypeIds.contains("F"))
{
componentTypeId="F";
}
else if (componentTypeIds.contains("A"))
{
componentTypeId="A";
}
else if (componentTypeIds.contains("D"))
{
componentTypeId="D";
}
else if (componentTypeIds.contains("P"))
{
componentTypeId="P";
}
else
{
componentTypeId="O";
}
}
}
else
{
componentTypeId="O";
}
return componentTypeId;
}
public static boolean isMatches(String regEx, String value) {
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(value);
return matcher.matches();
}
public static Matcher matcher(String regEx, String value) {
Pattern pattern = Pattern.compile(regEx);
return pattern.matcher(value);
}
public static boolean isAllUpperCase(String s) {
for(char c: s.toCharArray()) {
if(Character.isAlphabetic(c) && !Character.isUpperCase(c)){
return false;
}
}
return true;
}
public static StringBuilder escapeASCIIHtmlEntities(final CharSequence input) {
if(input == null)
return null;
StringBuilder replaced = new StringBuilder();
StringBuilder toBeReplaced = new StringBuilder();
boolean isEntity = false;
for(int i =0; i<input.length();i++){
char c = input.charAt(i);
if (isEntity) {
if (c == '&') {