Buggy code:
public class ChainEvolContext implements Serializable { private static final long serialVersionUID = 1L ; private static final Logger LOGGER = LoggerFactory . getLogger ( ChainEvolContext . class ) ; private static final double ROUNDING_MARGIN = 1.0E-4 ; private static final double MAX_QUERY_TO_UNIPROT_DISAGREEMENT = 0.1 ; private static final Pattern ALLX_SEQ_PATTERN = Pattern . compile ( "^X+$" ) ; private static final String BLASTOUT_SUFFIX = "blast.out.xml" ; private static final String BLAST_BASENAME = "pdb2unimapping" ; private static final String FASTA_SUFFIX = ".fa" ; private static final boolean BLAST_NO_FILTERING = true ; private static final boolean DEBUG = false ; private class MappingCoverage implements Comparable < ChainEvolContext . MappingCoverage > { public String uniprotId ; public int totalCoverage ; public MappingCoverage ( String uniprotId , int coverage ) { } public void add ( int coverage ) { } @ Override public int compareTo ( ChainEvolContext . MappingCoverage o ) { } public String toString ( ) { } } private String sequenceId ; private String sequence ; private UnirefEntry query ; private Interval queryInterv ; private boolean hasQueryMatch ; private SequencePair < ProteinSequence , AminoAcidCompound > alnPdb2Uniprot ; private double idCutoff ; private double queryCov ; private HomologList homologs ; private boolean searchWithFullUniprot ; private List < String > queryWarnings ; private ChainEvolContextList parent ; private HashMap < ResidueNumber , Integer > resNumbers2SeqresSerials ; private HashMap < Integer , ResidueNumber > seqresSerials2resNumbers ; private boolean isProtein ; public ChainEvolContext ( ChainEvolContextList parent , String sequence , String sequenceName ) { } public ChainEvolContext ( ChainEvolContextList parent , Compound compound ) { } public String getSequenceId ( ) { } public boolean isProtein ( ) { } public void retrieveQueryData ( EppicParams params ) throws BlastException , IOException , InterruptedException { } private String checkSiftsMappings ( List < SiftsFeature > mappings , boolean allowChimeras ) { } public void blastForHomologs ( EppicParams params ) throws BlastException , UniprotVerMisMatchException , IOException , InterruptedException { } public void filterToSameDomainOfLife ( ) { } public void removeIdenticalToQuery ( double minQueryCov ) { } public void retrieveHomologsData ( ) throws UniprotVerMisMatchException , IOException , SQLException { } public void applyHardIdentityCutoff ( double homHardIdCutoff , double queryCovCutoff ) { } public void applyIdentityCutoff ( EppicParams params ) throws BlastException , IOException , InterruptedException { } public void align ( EppicParams params ) throws UniprotVerMisMatchException , IOException , InterruptedException { } public MultipleSequenceAlignment getAlignment ( ) { } public String getQueryPdbToUniprotAlnString ( ) { } public SequencePair < ProteinSequence , AminoAcidCompound > getPdb2uniprotAln ( ) { } public List < Double > getConservationScores ( ) { } public void computeEntropies ( int reducedAlphabet ) { } public double calcScoreForResidueSet ( List < Group > residues ) { } public int getReducedAlphabet ( ) { } protected void setConservationScoresAsBfactors ( Chain chain ) { } public int getNumHomologs ( ) { } public String getRepresentativeChainCode ( ) { } public String getPdbSequence ( ) { } public boolean isPdbSeqPositionMatchingUniprot ( int resser ) { } public int getQueryUniprotPosForPDBPos ( int resser ) { int alnIdx = alnPdb2Uniprot . getQuery ( ) . getAlignmentIndexAt ( resser ) ; if ( alnPdb2Uniprot . hasGap ( alnIdx ) ) { return - 1 ; } int uniprotPos = alnPdb2Uniprot . getIndexInTargetAt ( alnIdx ) ; <START_BUG> int pos = uniprotPos - ( queryInterv . beg ) ; <END_BUG> if ( ( pos <= 0 ) || ( pos > ( queryInterv . getLength ( ) ) ) ) return - 1 ; return pos ; } public int getPDBPosForQueryUniprotPos ( int queryPos ) { } private String findUniprotMapping ( File blastPlusBlastp , String blastDbDir , String blastDb , int blastNumThreads , double pdb2uniprotIdThreshold , double pdb2uniprotQcovThreshold , boolean useUniparc ) throws BlastException , IOException , InterruptedException { } private String getDeflineAccession ( BlastHit hit ) { } private boolean isHitUniprot ( BlastHit hit ) { } public String getUniprotVer ( ) { } public UnirefEntry getQuery ( ) { } public Interval getQueryInterval ( ) { } public boolean hasQueryMatch ( ) { } public boolean isSearchWithFullUniprot ( ) { } public double getIdCutoff ( ) { } public int getUsedClusteringPercentId ( ) { } public List < String > getQueryWarnings ( ) { } public HomologList getHomologs ( ) { } public int getSeqresSerial ( Group g ) { } public ResidueNumber getResNumFromSerial ( int resser ) { } public int getSerialFromResNum ( ResidueNumber resNum ) { } private void initResNumberMaps ( Compound compound ) { } private static int getFirstMatchingPos ( SequencePair < ProteinSequence , AminoAcidCompound > pair , boolean first ) { } private static int getLastMatchingPos ( SequencePair < ProteinSequence , AminoAcidCompound > pair , boolean first ) { } }

Fix:
int pos = uniprotPos - ( ( queryInterv . beg ) - 1 ) ;