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 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 ; long newSequenceLength = entry . getSequence ( ) . getLength ( ) ; for ( Location location : feature . getLocations ( ) . getLocations ( ) ) { 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 ; } } } } } shiftReferenceLocation ( entry , newSequenceLength ) ; Long newBeginLocation , newEndLocation = null ; Location newLocation = null ; if ( ! invalidFeature ) { for ( Qualifier qualifier : feature . getQualifiers ( ) ) { if ( qualifier . getName ( ) . equals ( Qualifier . TRANSL_EXCEPT_QUALIFIER_NAME ) ) { TranslExceptQualifier translExcepttqualifier = new TranslExceptQualifier ( qualifier . getValue ( ) ) ; } 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 ; }
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)