void makePair(Alignment& a, Alignment& b, Alignment& x, Alignment& y) { initMate(a, x); initMate(b, y); Feature spacer; getSpacer(a, b, spacer); int insert = a.Length + spacer.getLength() + b.Length; // Add in mate pair info x.MateRefID = b.RefID; x.matePosition(b.position()); x.InsertSize = insert; y.MateRefID = a.RefID; y.matePosition(a.position()); y.InsertSize = -1 * insert; // Update Mapping information appropriately x.SetIsReverseStrand(a.IsReverseStrand()); x.SetIsMateReverseStrand(b.IsReverseStrand()); y.SetIsReverseStrand(b.IsReverseStrand()); y.SetIsMateReverseStrand(a.IsReverseStrand()); }
bool isValidPair(Alignment& a, Alignment& b) { Feature spacer; getSpacer(a, b, spacer); int gap = spacer.getLength(); // Calculate the correct size of the insert // REMEMBER: negative gaps mean our values overlap // pair must be oriented correctly // (5'--------->3' 3'<---------5') return gap >= MIN_GAP && gap <= MAX_GAP && !a.IsReverseStrand() && b.IsReverseStrand(); }
int main (int argc, char * argv[]) { vector<string> inputFilenames; string combinedOutFilename, alignmentsOutFilename; try { TCLAP::CmdLine cmd("Program description", ' ', VERSION); TCLAP::ValueArg<string> combinedOutputArg("o", "out", "Combined output filename (BAM format)", true, "", "combined.bam", cmd); TCLAP::ValueArg<int> minInsertArg("n", "min-insert", "Minimum insert size", false, DEFAULT_MIN_GAP, "min insert size", cmd); TCLAP::ValueArg<int> maxInsertArg("x", "max-insert", "Maximum insert size", false, DEFAULT_MAX_GAP, "max insert size", cmd); TCLAP::MultiArg<string> inputArgs("b", "bam", "Input BAM file", true, "input.bam", cmd); cmd.parse(argc, argv); combinedOutFilename = combinedOutputArg.getValue(); MIN_GAP = minInsertArg.getValue(); MAX_GAP = maxInsertArg.getValue(); inputFilenames = inputArgs.getValue(); } catch (TCLAP::ArgException &e) { cerr << "Error: " << e.error() << " " << e.argId() << endl; } // TODO require that alignments are sorted by name BamMultiReader reader; reader.Open(inputFilenames); if (!ValidOut.Open(combinedOutFilename, reader.GetHeader(), reader.GetReferenceData())) { cerr << ValidOut.GetErrorString() << endl; return 1; } string current, prev; char mateID; Group group; set<string> references; Alignment a; while (reader.GetNextAlignment(a)) { parseID(a.Name, current, mateID); if (current.compare(prev) && prev.size() > 0) { processGroup(group, references); group.clear(); references.clear(); } references.insert(a.RefName); GroupKey key; key.refID = a.RefName; key.mateID = mateID; key.rev = a.IsReverseStrand(); group.insert( std::make_pair( key, a ) ); prev = current; } processGroup(group, references); }