/** * Instantiates multiple underlying SAM writes, one per input SAM reader registered with GATK * engine (those will be retrieved from <code>toolkit</code>). The output file names will be * generated automatically by stripping ".sam" or ".bam" off the input file name and adding ext * instead (e.g. ".cleaned.bam"). onto a unique output file name. * * @param toolkit * @param ext */ public void setupByReader( GenomeAnalysisEngine toolkit, String ext, SAMFileHeader.SortOrder order, boolean presorted, boolean indexOnTheFly, boolean generateMD5, SAMProgramRecord pRecord) { for (SAMReaderID rid : toolkit.getReadsDataSource().getReaderIDs()) { String fName = toolkit.getReadsDataSource().getSAMFile(rid).getName(); String outName; int pos; if (fName.toUpperCase().endsWith(".BAM")) pos = fName.toUpperCase().lastIndexOf(".BAM"); else { if (fName.toUpperCase().endsWith(".SAM")) pos = fName.toUpperCase().lastIndexOf(".SAM"); else throw new UserException.BadInput( "Input file name " + fName + " does not end with .sam or .bam"); } String prefix = fName.substring(0, pos); outName = prefix + ext; if (writerMap.containsKey(rid)) throw new StingException( "nWayOut mode: Reader id for input sam file " + fName + " is already registered"); addWriter(rid, outName, order, presorted, indexOnTheFly, generateMD5, pRecord); } }
/** * Instantiates multiple underlying SAM writes, one per input SAM reader registered with GATK * engine (those will be retrieved from <code>toolkit</code>). The <code>in2out</code> map must * contain an entry for each input filename and map it onto a unique output file name. * * @param toolkit * @param in2out */ public void setupByReader( GenomeAnalysisEngine toolkit, Map<String, String> in2out, SAMFileHeader.SortOrder order, boolean presorted, boolean indexOnTheFly, boolean generateMD5, SAMProgramRecord pRecord) { if (in2out == null) throw new StingException("input-output bam filename map for n-way-out writing is NULL"); for (SAMReaderID rid : toolkit.getReadsDataSource().getReaderIDs()) { String fName = toolkit.getReadsDataSource().getSAMFile(rid).getName(); String outName; if (!in2out.containsKey(fName)) throw new UserException.BadInput( "Input-output bam filename map does not contain an entry for the input file " + fName); outName = in2out.get(fName); if (writerMap.containsKey(rid)) throw new StingException( "nWayOut mode: Reader id for input sam file " + fName + " is already registered; " + "map file likely contains multiple entries for this input file"); addWriter(rid, outName, order, presorted, indexOnTheFly, generateMD5, pRecord); } }
public void addAlignment(SAMRecord samRecord) { final SAMReaderID id = toolkit.getReaderIDForRead(samRecord); String rg = samRecord.getStringAttribute("RG"); if (rg != null) { String rg_orig = toolkit.getReadsDataSource().getOriginalReadGroupId(rg); samRecord.setAttribute("RG", rg_orig); } addAlignment(samRecord, id); }