private static SAMFileHeader mergeHeaders(List<RecordSource> sources) {
		SAMFileHeader header = new SAMFileHeader();
		for (RecordSource source : sources) {
			SAMFileHeader h = source.reader.getFileHeader();

			for (SAMSequenceRecord seq : h.getSequenceDictionary().getSequences()) {
				if (header.getSequenceDictionary().getSequence(seq.getSequenceName()) == null)
					header.addSequence(seq);
			}

			for (SAMProgramRecord pro : h.getProgramRecords()) {
				if (header.getProgramRecord(pro.getProgramGroupId()) == null)
					header.addProgramRecord(pro);
			}

			for (String comment : h.getComments())
				header.addComment(comment);

			for (SAMReadGroupRecord rg : h.getReadGroups()) {
				if (header.getReadGroup(rg.getReadGroupId()) == null)
					header.addReadGroup(rg);
			}
		}

		return header;
	}