本文整理汇总了C#中MongoRepository.GetCollection方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.GetCollection方法的具体用法?C# MongoRepository.GetCollection怎么用?C# MongoRepository.GetCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoRepository
的用法示例。
在下文中一共展示了MongoRepository.GetCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CellCounts
private static async Task CellCounts()
{
var mongoConnection = new MongoRepository("genomics");
var tbfsCollection = mongoConnection.GetCollection<EncodeTbfsPeak>("encode.tbfs-peaks");
var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument { { "antibody", "CTCF" } })
.Group(new BsonDocument { { "_id", "$cell" }, { "count", new BsonDocument("$sum", 1) } });
var results = await aggregate.ToListAsync();
var ordered = results.OrderBy(x => x[0]);
// var aggregate = tbfsCollection.Aggregate()
// .Match(new BsonDocument { { "antibody", "CTCF" } })
// .Group(new BsonDocument { { "_id", "$chromosome" }, { "count", new BsonDocument("$sum", 1) } });
// var results = await aggregate.ToListAsync();
// var ordered = results.OrderBy(x => x[0]);
using (var writer = new StreamWriter(File.Open("C:\\_dev\\data\\genomics\\results.csv", FileMode.Create)))
{
foreach (var doc in ordered)
{
var line = doc[0] + "," + doc[1];
writer.WriteLine(line);
}
}
}
示例2: LineageSpecificity
private static async Task LineageSpecificity()
{
var mongoConnection = new MongoRepository("genomics");
var tbfsCollection = mongoConnection.GetCollection<EncodeTbfsPeak>("encode.tbfs-peaks");
Console.WriteLine("Cleaning database...");
//await tbfsCollection.Indexes.DropAllAsync();
var keys = Builders<EncodeTbfsPeak>.IndexKeys.Ascending("chromosome").Ascending("cell");
await tbfsCollection.Indexes.CreateOneAsync(keys);
keys = Builders<EncodeTbfsPeak>.IndexKeys.Ascending("chromosome");
await tbfsCollection.Indexes.CreateOneAsync(keys);
keys = Builders<EncodeTbfsPeak>.IndexKeys.Ascending("cell");
await tbfsCollection.Indexes.CreateOneAsync(keys);
keys =
Builders<EncodeTbfsPeak>.IndexKeys.Ascending("chromosome")
.Ascending("cell")
.Ascending("startPos")
.Ascending("endPos");
await tbfsCollection.Indexes.CreateOneAsync(keys);
keys = Builders<EncodeTbfsPeak>.IndexKeys.Ascending("startPos");
await tbfsCollection.Indexes.CreateOneAsync(keys);
keys = Builders<EncodeTbfsPeak>.IndexKeys.Ascending("endPos");
await tbfsCollection.Indexes.CreateOneAsync(keys);
var uBuilder = Builders<EncodeTbfsPeak>.Filter;
var uFilter = uBuilder.Eq("antibody", "CTCF");
var update = Builders<EncodeTbfsPeak>.Update.Set("overlapcount", -1);
await tbfsCollection.UpdateManyAsync(uFilter, update);
Console.WriteLine("Getting chromosomes...");
//Get Chromosomes
var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument {{"antibody", "CTCF"}})
.Group(new BsonDocument {{"_id", "$chromosome"}});
var chromosomes = await aggregate.ToListAsync();
var orderedChromosomes = chromosomes.Select(x => x[0].AsString).OrderBy(x => x);
Console.WriteLine("Getting cells...");
//Get cells
aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument {{"antibody", "CTCF"}})
.Group(new BsonDocument {{"_id", "$cell"}});
var cells = await aggregate.ToListAsync();
var orderedCells = cells.Select(x => x[0].AsString).OrderBy(x => x);
//Build cell set you care about
var allowedCells = orderedCells.ToList();
/*using (var reader = new StreamReader(File.OpenRead("C:\\_dev\\data\\genomics\\allowed_cell_types.txt")))
{
string line;
while ((line = reader.ReadLine()) != null)
{
allowedCells.Add(line);
}
}*/
var cellCount = allowedCells.Count;
foreach (var chromosome in orderedChromosomes)
{
Console.WriteLine("Getting data for " + chromosome + "...");
var chromeBuilder = Builders<EncodeTbfsPeak>.Filter;
var chromeFilter = chromeBuilder.Eq("chromosome", chromosome);
var ctbfs = await tbfsCollection.Find(chromeFilter).ToListAsync();
var filteredCtbfs = ctbfs.Where(x => allowedCells.Exists(y => y == x.Cell)).ToList();
Console.WriteLine("Received " + filteredCtbfs.Count);
_completedCount = 0;
Task.WaitAll(orderedCells.Where(x=> allowedCells.Exists(y => y == x)).OrderBy(x => x).Select(cell => Task.Run(async () => await ProcessLineageSpecificity(tbfsCollection, chromosome, cell, filteredCtbfs, allowedCells, cellCount))).ToArray());
}
}
示例3: ConvertTbfsToFasta
private static async Task ConvertTbfsToFasta()
{
var genomePath = "C:\\_dev\\data\\genomics\\ucsc\\genome\\hg19\\";
var outputPath = "C:\\_dev\\data\\genomics\\2012-reproduce\\tbfs_fasta\\";
var mongoConnection = new MongoRepository("genomics");
var tbfsCollection = mongoConnection.GetCollection<EncodeTbfsPeak>("encode.tbfs-peaks");
//Build cell set you care about
var allowedCells = new List<string>();
using (var reader = new StreamReader(File.OpenRead("C:\\_dev\\data\\genomics\\allowed_cell_types.txt")))
{
string line;
while ((line = reader.ReadLine()) != null)
{
allowedCells.Add(line);
}
}
Console.WriteLine("Getting chromosomes...");
//Get Chromosomes
var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument {{"antibody", "CTCF"}})
.Group(new BsonDocument {{"_id", "$chromosome"}});
var chromosomes = await aggregate.ToListAsync();
var orderedChromosomes = chromosomes.Select(x => x[0].AsString).OrderBy(x => x);
var allowedCell = "AG04449";
var totalSequences = 0;
using (var writer = new StreamWriter(File.Open(outputPath + "peaks." + allowedCell + ".fasta", FileMode.Create)))
{
foreach (var chromosome in orderedChromosomes)
{
Console.WriteLine("Getting sites for " + chromosome + "-" + allowedCell + "...");
var builder = Builders<EncodeTbfsPeak>.Filter;
var chromeFilter = builder.Eq("chromosome", chromosome) & builder.Eq("class", "ubiquitous") &
builder.Eq("cell", allowedCell);
var ctbfs = await tbfsCollection.Find(chromeFilter).ToListAsync();
Console.WriteLine("Got " + ctbfs.Count + " sites");
Console.WriteLine("Loading chromosome genomic data...");
var fileLines = new List<string>();
int totalCount = 0;
using (var reader = new StreamReader(File.Open(genomePath + chromosome + ".fa", FileMode.Open)))
{
string line;
while ((line = reader.ReadLine()) != null)
{
totalCount += line.Length;
fileLines.Add(line);
}
}
//Get rid of first line
fileLines.RemoveAt(0);
//Compound data
var chromeArray = new char[totalCount];
var currentPos = 0;
foreach (var fileLine in fileLines)
{
for (var i = 0; i < fileLine.Length; i++)
{
chromeArray[currentPos + i] = fileLine[i];
}
currentPos += fileLine.Length;
}
Console.WriteLine("Creating FASTA data...");
foreach (var peak in ctbfs.OrderBy(x => x.StartPos))
{
totalSequences++;
writer.WriteLine(">CTCF-" + totalSequences);
var line = "";
var peakLength = peak.EndPos - peak.StartPos;
for (var i = 0; i < peakLength; i++)
{
line += chromeArray[peak.StartPos + i];
}
writer.WriteLine(line);
}
}
}
}
示例4: LineageSpecificityCount
private static async Task LineageSpecificityCount()
{
var mongoConnection = new MongoRepository("genomics");
var tbfsCollection = mongoConnection.GetCollection<EncodeTbfsPeak>("encode.tbfs-peaks");
/*var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument {{"cell", "K562"}})
.Group(
new BsonDocument
{
{
"_id", new BsonDocument
{
{"chromosome", "$chromosome"},
{"class", "$class"}
}
},
{"count", new BsonDocument("$sum", 1)}
});
var results = await aggregate.ToListAsync();*/
var aggregate = tbfsCollection.Aggregate()
// .Match(new BsonDocument { { "cell", "HMF" } })
.Group(
new BsonDocument
{
{
"_id", new BsonDocument
{
{"cell", "$cell"},
{"class", "$class"}
}
},
{"count", new BsonDocument("$sum", 1)}
});
var results = await aggregate.ToListAsync();
/* var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument { { "cell", "K562" } })
.Group(new BsonDocument { { "_id", "$overlapcount" }, { "count", new BsonDocument("$sum", 1) } });
var results = await aggregate.ToListAsync();*/
/* var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument { { "cell", "K562" } })
.Group(new BsonDocument { { "_id", "$missingCell" }, { "count", new BsonDocument("$sum", 1) } });
var results = await aggregate.ToListAsync();*/
var ordered = results.OrderBy(x => x[0]);
}